Advertisement
Guest User

Untitled

a guest
Jan 27th, 2017
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. HOST = "irc.twitch.tv"
  3. PORT = 6667
  4. NICK = "kveth_o_bot"
  5. PASS = "oauth:ctrb2g9f90ffyhk8qlz8zas3r5efbd"
  6. CHAN = "kvethlorien"
  7. oplist = {}
  8.  
  9.  
  10. # -*- coding: utf-8 -*-
  11. import config
  12. import utils
  13. import socket
  14. import re
  15. import time
  16. import thread
  17. from time import sleep
  18.  
  19.  
  20. def main():
  21. s = socket.socket()
  22. s.connect((config.HOST, config.PORT))
  23. s.send("PASS {}\r\n".format(config.PASS).encode("utf-8"))
  24. s.send("NICK {}\r\n".format(config.NICK).encode("utf-8"))
  25. s.send("JOIN #{}\r\n".format(config.CHAN).encode("utf-8"))
  26.  
  27. chat_message = re.compile(r"^:.*?\s:")
  28. utils.mess(s, "I'm a stupid Bad Robot")
  29.  
  30. thread.start_new_thread(utils.fillOpList, ())
  31. while True:
  32. response = s.recv(1024).decode("utf-8")
  33. if response == "PING :tmi.twitch.tv\r\n":
  34. s.send("POND :tmi.twitch.tv\r\n".encode("utf-8"))
  35. else:
  36. username = re.search(r"\w+", response).group(0)
  37. message = chat_message.sub("", response)
  38. print(response)
  39. print(message)
  40.  
  41. if message.strip() == "!time":
  42. utils.mess(s, "It's currently" + time.strftime("%I:%M %p %Z on %A %B %d %Y"))
  43. if message.strip() == "!ping" and utils.isOp(username):
  44. utils.mess(s, "pong!")
  45. if message.strip() == "!links":
  46. utils.mess(s, "vk: vk.com/kvethlorien twitter: twitter.com/kvethlorien youtube: youtube.comc/NathaliePuninskiy/")
  47. if message.strip() == "!commands":
  48. utils.mess(s, "!time, !ping, !links, !discord, !btag, !playwithme" )
  49. if message.strip() == "!discord":
  50. utils.mess(s, "https://discord.gg/ybMNWz4" )
  51. if message.strip() == "!btag":
  52. utils.mess(s, "kvethlorien#2136 fyrr#2230")
  53. if message.strip() == "!playwithme":
  54. utils.mess(s, "if you want to join me in quickmatches or unranked draft write /join kvethlorien in gamechat")
  55.  
  56.  
  57.  
  58.  
  59.  
  60. sleep(1)
  61.  
  62.  
  63. if __name__ == "__main__":
  64. main()
  65.  
  66.  
  67.  
  68.  
  69. # -*- coding: utf-8 -*-
  70. import config
  71. import urllib2
  72. import json
  73. import time
  74. import thread
  75. from time import sleep
  76.  
  77.  
  78.  
  79.  
  80. def mess(sock, message):
  81. sock.send("PRIVMSG #{} :{}\r\n".format(config.CHAN, message))
  82.  
  83.  
  84.  
  85. def ban(sock, user):
  86. mess(sock, ".ban {}".format(user))
  87.  
  88.  
  89. def timeout(sock, user, seconds = 500):
  90. mess(sock, ".timeout {}".format(user, seconds))
  91.  
  92. #req = request
  93. #res = response
  94.  
  95.  
  96. def fillOpList():
  97. while True:
  98. try:
  99. url = "http://tmi.twitch.tv/group/user/kvethlorien/chatters"
  100. req = urllib2.Request(url, headers={"accept": "*/*"})
  101. res = urllib2.urlopen(req).read()
  102. if res.find("502 bad gateaway") == -1:
  103. config.oplist.clear()
  104. data = json.loads(res)
  105. for p in data["chatters"]["moderators"]:
  106. config.oplist[p] = "mod"
  107. for p in data["chatters"]["global_mods"]:
  108. config.oplist[p] = "global_mod"
  109. for p in data["chatters"]["admins"]:
  110. config.oplist[p] = "admin"
  111. for p in data["chatters"]["staff"]:
  112. config.oplist[p] = "staff"
  113. except:
  114. "Something went wrong...do nothing"
  115. sleep(5)
  116.  
  117.  
  118. def isOp(user):
  119. return user in config.oplist
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement