Advertisement
Guest User

Untitled

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