Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- config.py
- HOST = "irc.twitch.tv"
- PORT = 6667
- NICK = "kveth_o_bot"
- PASS = "oauth:ctrb2g9f90ffyhk8qlz8zas3r5efbd"
- CHAN = "kvethlorien"
- # -*- coding: utf-8 -*-
- oplist = {}
- utils.py
- import config
- import urllib2
- import json
- import time
- import thread
- from time import sleep
- # -*- coding: utf-8 -*-
- def mess(sock, message):
- sock.send("PRIVMSG #{} :{}\r\n".format(config.CHAN, message))
- def ban(sock, user):
- mess(sock, ".ban {}".format(user))
- def timeout(sock, user, seconds = 500):
- mess(sock, ".timeout {}".format(user, seconds))
- #req = request
- #res = response
- def fillOpList():
- while True:
- try:
- url = "http://tmi.twitch.tv/group/user/kvethlorien/chatters"
- req = urllib2.Request(url, headers={"accept": "*/*"})
- res = urllib2.urlopen(req).read()
- if res.find("502 bad gateaway") == -1:
- config.oplist.clear()
- data = json.loads(res)
- for p in data["chatters"]["moderators"]:
- config.oplist[p] = "mod"
- for p in data["chatters"]["global_mods"]:
- config.oplist[p] = "global_mod"
- for p in data["chatters"]["admins"]:
- config.oplist[p] = "admin"
- for p in data["chatters"]["staff"]:
- config.oplist[p] = "staff"
- except:
- "Something went wrong...do nothing"
- sleep(5)
- def isOp(user):
- return user in config.oplist
- bot.py
- import config
- import utils
- import socket
- import re
- import time
- import thread
- from time import sleep
- # -*- coding: utf-8 -*-
- def main():
- s = socket.socket()
- s.connect((config.HOST, config.PORT))
- s.send("PASS {}\r\n".format(config.PASS).encode("utf-8"))
- s.send("NICK {}\r\n".format(config.NICK).encode("utf-8"))
- s.send("JOIN #{}\r\n".format(config.CHAN).encode("utf-8"))
- chat_message = re.compile(r"^:.*?\s:")
- utils.mess(s, "I'm a stupid Bad Robot")
- thread.start_new_thread(utils.fillOpList, ())
- while True:
- response = s.recv(1024).decode("utf-8")
- if response == "PING :tmi.twitch.tv\r\n":
- s.send("POND :tmi.twitch.tv\r\n".encode("utf-8"))
- else:
- username = re.search(r"\w+", response).group(0)
- message = chat_message.sub("", response)
- print(response)
- print(message)
- if message.strip() == "!time":
- utils.mess(s, "It's currently" + time.strftime("%I:%M %p %Z on %A %B %d %Y"))
- if message.strip() == "!ping" and utils.isOp(username):
- utils.mess(s, "pong!")
- if message.strip() == "!links":
- utils.mess(s, "vk: vk.com/kvethlorien twitter: twitter.com/kvethlorien youtube: youtube.comc/NathaliePuninskiy/")
- if message.strip() == "!commands":
- utils.mess(s, "!time, !ping, !links, !discord, !btag, !playwithme" )
- if message.strip() == "!discord":
- utils.mess(s, "https://discord.gg/ybMNWz4" )
- if message.strip() == "!btag":
- utils.mess(s, "kvethlorien#2136")
- if message.strip() == "!playwithme":
- utils.mess(s, "if you want to join me in quickmatches or unranked draft write /join kvethlorien in gamechat")
- sleep(1)
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement