SHARE
TWEET

Untitled

DatGuy1 Mar 23rd, 2018 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python3
  2.  
  3. import socket
  4. import re
  5. import io as cStringIO
  6. import urllib
  7. import tempfile
  8. import os
  9. import obspython as obs
  10.  
  11. try:
  12.     s = socket.socket()
  13.     s.connect((HOST, PORT))
  14.     s.send("PASS {}\r\n".format(PASS).encode("utf-8"))
  15.     s.send("NICK {}\r\n".format(NICK).encode("utf-8"))
  16.     s.send("JOIN {}\r\n".format(CHAN).encode("utf-8"))
  17.     connected = True
  18. except Exception as e:
  19.     obs.script_log(obs.LOG_WARNING, "Error listening to IRC stream: " + str(e))
  20.     connected = False
  21.  
  22. enabled = False
  23.  
  24. CHAT_MSG=re.compile(r"^:\w+!\w+@\w+\.tmi\.twitch\.tv PRIVMSG #\w+ :")
  25.  
  26. #done defining shieet
  27.  
  28. def script_description():
  29.     return "lidl description"
  30.  
  31. def script_properties():
  32.     props = obs.obs_properties_create()
  33.     obs.script_log(obs.LOG_DEBUG, "here")
  34.     obs.obs_properties_add_text(props, "emote1", "First emote", obs.OBS_TEXT_DEFAULT)
  35.     obs.obs_properties_add_text(props, "emote2", "Second emote", obs.OBS_TEXT_DEFAULT)
  36.  
  37.     p1 = obs.obs_properties_add_list(props, "count1", "Emote 1 counter", obs.OBS_COMBO_TYPE_EDITABLE, obs.OBS_COMBO_FORMAT_STRING)
  38.     p2 = obs.obs_properties_add_list(props, "count2", "Emote 2 counter", obs.OBS_COMBO_TYPE_EDITABLE, obs.OBS_COMBO_FORMAT_STRING)
  39.     l1 = obs.obs_properties_add_list(props, "image1", "Emote 1 photo", obs.OBS_COMBO_TYPE_EDITABLE, obs.OBS_COMBO_FORMAT_STRING)
  40.     l2 = obs.obs_properties_add_list(props, "image2", "Emote 2 photo", obs.OBS_COMBO_TYPE_EDITABLE, obs.OBS_COMBO_FORMAT_STRING)
  41.     sources = obs.obs_enum_sources()
  42.     if sources is not None:
  43.         for source in sources:
  44.             source_id = obs.obs_source_get_id(source)
  45.             if source_id == "text_gdiplus" or source_id == "text_ft2_source":
  46.                 name = obs.obs_source_get_name(source)
  47.                 obs.obs_property_list_add_string(p1, name, name)
  48.                 obs.obs_property_list_add_string(p2, name, name)
  49.             elif source_id == "image_source":
  50.                 name = obs.obs_source_get_name(source)
  51.                 obs.obs_property_list_add_string(l1, name, name)
  52.                 obs.obs_property_list_add_string(l2, name, name)
  53.  
  54.         obs.source_list_release(sources)
  55.     obs.obs_properties_add_button(props, "button", "(De)Activate", activate_meter)
  56.     return props
  57.  
  58. def activate_meter(props, prop):
  59.     global enabled
  60.     global emote1
  61.     global emote2
  62.     global count1
  63.     global count2
  64.     global image1
  65.     global image2
  66.     enabled = not enabled
  67.  
  68.     sceneSource = obs.obs_frontend_get_current_scene()
  69.     scene = obs.obs_scene_from_source(sceneSource)
  70.     img1 = obs.obs_scene_find_source(scene, image1)
  71.     img2 = obs.obs_scene_find_source(scene, image2)
  72.     counter1 = obs.obs_scene_find_source(scene, count1)
  73.     counter2 = obs.obs_scene_find_source(scene, count2)
  74.  
  75.     if emote1 not in emotes or emote2 not in emotes:
  76.         obs.script_log(obs.LOG_ERROR, "One of the emotes is not available")
  77.     downloadimages(emote1, emote2)
  78.  
  79.     obs.obs_sceneitem_set_visible(img1, enabled)
  80.     obs.obs_sceneitem_set_visible(img2, enabled)
  81.     obs.obs_sceneitem_set_visible(counter1, enabled)
  82.     obs.obs_sceneitem_set_visible(counter2, enabled)
  83.  
  84.     senders = []
  85.     emote1s = 0
  86.     emote2s = 0
  87.     total1 = open('total1.txt', 'w')
  88.     total2 = open('total2.txt', 'w')
  89.  
  90.    # while enabled
  91.     if (enabled and connected):
  92.         response = s.recv(1024).decode("utf-8")
  93.         if response:
  94.             if response == "PING :tmi.twitch.tv\r\n":
  95.                 s.send("PONG :tmi.twitch.tv\r\n".encode("utf-8"))
  96.             else:
  97.                 username = re.search(r"\w+", response).group(0) # return the entire match
  98.                 senders.append(username)
  99.                 message = CHAT_MSG.sub("", response)
  100.                 obs.script_log(obs.LOG_DEBUG, message)
  101.                 if emote1 in message:
  102.                     emote1s += 1
  103.                 elif emote2 in message:
  104.                     emote2s += 1
  105.                 total1.write(str(emote1s))
  106.                 total2.write(str(emote2s))
  107.  
  108.  
  109.  
  110.  
  111. def script_update(settings):
  112.     global emote1
  113.     global emote2
  114.     global count1
  115.     global count2
  116.     global image1
  117.     global image2
  118.  
  119.     emote1 = obs.obs_data_get_string(settings, "emote1")
  120.     emote2 = obs.obs_data_get_string(settings, "emote2")
  121.     count1 = obs.obs_data_get_string(settings, "count1")
  122.     count2 = obs.obs_data_get_string(settings, "count2")
  123.     image1 = obs.obs_data_get_string(settings, "image1")
  124.     image2 = obs.obs_data_get_string(settings, "image2")
  125.  
  126.  
  127.  
  128. def downloadimages(emote1, emote2):
  129.     response1 = urllib.request.urlopen(emotes[emote1])
  130.     response2 = urllib.request.urlopen(emotes[emote2])
  131.     item1 = cStringIO.BytesIO(response1.read())
  132.     item2 = cStringIO.BytesIO(response2.read())
  133.     emote1img = open('emote1.png','wb')
  134.     emote1img.write(item1.getvalue())
  135.     emote2img = open('emote2.png','wb')
  136.     emote2img.write(item2.getvalue())
  137.     emote1img.close()
  138.     emote2img.close()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top