100 lines
3.1 KiB
Python
100 lines
3.1 KiB
Python
import twitch
|
|
import re
|
|
import json
|
|
import UserData
|
|
|
|
with open(".twitchcreds") as file:
|
|
botSettings = json.loads(file.read())#
|
|
|
|
UserID = botSettings[0]['OAUTH']
|
|
PREFIX = '!'
|
|
BOTID = '[BOT]'
|
|
CHANNEL = botSettings[1]["CHANNEL"]
|
|
|
|
#Users
|
|
Users = {}
|
|
|
|
def isURL(message):
|
|
rule = re.compile(r"http(|s)[;:]\/\/.*\..*")
|
|
return rule.findall(message)
|
|
|
|
def addUser(username):
|
|
Users[username] = UserData.UserData(username, username in botSettings[1]["MODS"])
|
|
|
|
def checkUserExists(username):
|
|
if username in Users:
|
|
pass
|
|
else:
|
|
addUser(username)
|
|
return True
|
|
|
|
def handle_message(message: twitch.chat.Message) -> None:
|
|
uname = message.user.display_name
|
|
if uname not in Users:
|
|
Users[uname] = UserData.UserData(uname, uname in botSettings[1]["MODS"])
|
|
|
|
if message.text.startswith(PREFIX + 'views'):
|
|
message.chat.send(f'{BOTID} @{uname}, you have {message.user.view_count} views.')
|
|
|
|
if message.text.startswith(PREFIX + "hello"):
|
|
message.chat.send(f"{BOTID} Hello @{uname}, how are you?")
|
|
|
|
if message.text.startswith(PREFIX + "author"):
|
|
message.chat.send(f"{BOTID} I am written by an idiot who knows enough to cause trouble ;)")
|
|
|
|
if message.text.startswith(PREFIX + "uptime"):
|
|
pass # FIND WAY TO DO THIS WHEN ITS NOT 7AM
|
|
|
|
if message.user.display_name in botSettings[1]["MODS"]:
|
|
if message.text.startswith(PREFIX + "setgame"):
|
|
# Do logic for setting the game
|
|
message.chat.send(f"{BOTID} Changing game to {message.text.strip(PREFIX + 'setgame').strip()}")
|
|
|
|
if message.text.startswith(PREFIX + "permit"):
|
|
print(message.text)
|
|
msg = message.text.replace(PREFIX + "permit","").strip()
|
|
print(msg)
|
|
if '@' in message.text:
|
|
msg = msg.replace('@','')
|
|
if checkUserExists(msg):
|
|
message.chat.send(f"permitting {msg}")
|
|
Users[msg].addURLPermit()
|
|
|
|
|
|
#User Limits
|
|
if Users[uname].checkUserMessageTimout():
|
|
Users[uname].setUserMessageCount()
|
|
if Users[uname].messageCount >= Users[uname].messageLimit: # if the message limit has been reached
|
|
message.chat.send(f"{BOTID} Timing out {uname} for 15 seconds, please no spam :(")
|
|
message.chat.send(f"/timeout {uname} 15")
|
|
|
|
#URL Permits
|
|
if Users[uname].URLPermit and isURL(message.text):
|
|
Users[uname].removeURLPermit()
|
|
elif not Users[uname].URLPermit and isURL(message.text):
|
|
if f"https://www.twitch.tv/{CHANNEL}/clip" in message.text:
|
|
pass
|
|
|
|
else:
|
|
message.chat.send(f"/timeout {uname} 1")
|
|
message.chat.send(f"{BOTID} @{uname} Please do not post messages with URL's unless permitted")
|
|
|
|
|
|
|
|
|
|
# print(userstats)
|
|
|
|
def main():
|
|
chat = twitch.Chat(channel='#aztecdude1',
|
|
nickname='AzBot',
|
|
oauth=UserID,
|
|
helix=twitch.Helix(client_id=botSettings[0]['CLIENTID'], use_cache=True))
|
|
|
|
chat.subscribe(handle_message)
|
|
chat.send(f"{BOTID} I am online now")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|
|
#print(isURL("https://google.com"))
|