Added URL checking
This commit is contained in:
parent
4182bf9231
commit
ca1e5219e0
36
tbot.py
36
tbot.py
@ -1,5 +1,6 @@
|
||||
import twitch
|
||||
import datetime
|
||||
import re
|
||||
|
||||
UserID = "oauth:9yymca9k3o4okc40lgc67q9u9x3dqe"
|
||||
PREFIX = '!'
|
||||
@ -8,11 +9,20 @@ BOTID = '[BOT]'
|
||||
#User limits
|
||||
TIMEOUT = 10
|
||||
MSG_LIMIT = 10
|
||||
|
||||
userstats = {}
|
||||
|
||||
permitURL = []
|
||||
|
||||
def isURL(message):
|
||||
rule = re.compile("http(|s):\/\/.*\..*")
|
||||
if rule.findall(message):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
|
||||
def handle_message(message: twitch.chat.Message) -> None:
|
||||
print(message.text)
|
||||
#print(message.chat
|
||||
if message.text.startswith(PREFIX + 'views'):
|
||||
message.chat.send(f'{BOTID} @{message.user.display_name}, you have {message.user.view_count} views.')
|
||||
|
||||
@ -24,7 +34,14 @@ def handle_message(message: twitch.chat.Message) -> None:
|
||||
|
||||
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')}")
|
||||
message.chat.send(f"{BOTID} Changing game to {message.text.strip(PREFIX + 'setgame').strip()}")
|
||||
|
||||
if message.text.startswith(PREFIX + "permit"):
|
||||
message.chat.send(f"permitting {message.text.strip(PREFIX + 'permit')}")
|
||||
permitURL.append(message.text.strip(PREFIX + 'permit').strip())
|
||||
|
||||
if message.text.startswith(PREFIX + "uptime"):
|
||||
pass # FIND WAY TO DO THIS WHEN ITS NOT 7AM
|
||||
|
||||
# User limits
|
||||
if message.user.display_name not in userstats:
|
||||
@ -43,6 +60,16 @@ def handle_message(message: twitch.chat.Message) -> None:
|
||||
message.chat.send(f"/timeout {message.user.display_name} 15")
|
||||
print(f"{userstats[message.user.display_name][2]}:{currTime}")
|
||||
|
||||
if message.user.display_name not in permitURL and isURL(message.text):
|
||||
print("Timout user for 1 second to remove URL message, needs to be fixed")
|
||||
message.chat.send(f"/timeout {message.user.display_name} 1")
|
||||
message.chat.send(f"{BOTID} @{message.user.display_name} Please do not post messages with URL's unless permitted")
|
||||
else:
|
||||
if isURL(message.text):
|
||||
permitURL.remove(message.user.display_name)
|
||||
else:
|
||||
pass
|
||||
|
||||
print(userstats)
|
||||
|
||||
def main():
|
||||
@ -56,4 +83,5 @@ def main():
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
print(isURL("https://google.com"))
|
||||
Loading…
x
Reference in New Issue
Block a user