Compare commits
No commits in common. "da06145f2584e9d4e35fee8415e36e81b6c89e85" and "68ac5d76ee44a3a8b2d98d60004a6ace5861ef72" have entirely different histories.
da06145f25
...
68ac5d76ee
@ -18,7 +18,7 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta):
|
|||||||
#twitch_message.chat.send("test acknowledged")
|
#twitch_message.chat.send("test acknowledged")
|
||||||
|
|
||||||
diceRoll: str = ""
|
diceRoll: str = ""
|
||||||
bot.send_message("Rolling Dice...")
|
twitch_message.chat.send("Rolling Dice...")
|
||||||
print("Rolling Dice...")
|
print("Rolling Dice...")
|
||||||
|
|
||||||
temp_preParsedMessage = twitch_message.text.split("+")
|
temp_preParsedMessage = twitch_message.text.split("+")
|
||||||
@ -63,4 +63,4 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta):
|
|||||||
|
|
||||||
diceRoll = "@" + twitch_message.sender + " rolled: " + diceRoll
|
diceRoll = "@" + twitch_message.sender + " rolled: " + diceRoll
|
||||||
print(diceRoll)
|
print(diceRoll)
|
||||||
bot.send_message(diceRoll)
|
twitch_message.chat.send(diceRoll)
|
||||||
@ -14,4 +14,4 @@ class CommandTest(AbstractCommand, metaclass=ABCMeta):
|
|||||||
|
|
||||||
def do_command(self, bot, twitch_message):
|
def do_command(self, bot, twitch_message):
|
||||||
print("!test Detected")
|
print("!test Detected")
|
||||||
bot.send_message("testing acknowledged")
|
twitch_message.chat.send("test acknowledged")
|
||||||
|
|||||||
@ -13,10 +13,8 @@ class CommandTTS(AbstractCommand, metaclass=ABCMeta):
|
|||||||
def do_command(self, bot, twitch_message):
|
def do_command(self, bot, twitch_message):
|
||||||
args = self.get_args(twitch_message.text)
|
args = self.get_args(twitch_message.text)
|
||||||
if args[1] == "start":
|
if args[1] == "start":
|
||||||
if twitch_message.sender.lower() == twitch_message.channel:
|
bot.send_message("tts activated on #%s" % twitch_message.channel)
|
||||||
bot.send_message("tts activated on #%s" % twitch_message.channel)
|
bot.tts_enabled = True
|
||||||
bot.tts_enabled = True
|
|
||||||
elif args[1] == "stop":
|
elif args[1] == "stop":
|
||||||
if twitch_message.sender.lower() == twitch_message.channel:
|
bot.send_message("tts deactivated")
|
||||||
bot.send_message("tts activated on #%s" % twitch_message.channel)
|
bot.tts_enabled = False
|
||||||
bot.tts_enabled = False
|
|
||||||
|
|||||||
121
cooldowns.py
121
cooldowns.py
@ -1,121 +0,0 @@
|
|||||||
import random
|
|
||||||
import re
|
|
||||||
|
|
||||||
import datetime
|
|
||||||
from datetime import timedelta
|
|
||||||
|
|
||||||
import time
|
|
||||||
from time import sleep
|
|
||||||
|
|
||||||
class Cooldown_Action:
|
|
||||||
def __init__(self):
|
|
||||||
self.tag:str = ""
|
|
||||||
self.time = datetime.datetime.now()
|
|
||||||
|
|
||||||
class Cooldown:
|
|
||||||
def __init__(self):
|
|
||||||
self.cooldownName:str = ""
|
|
||||||
self.cooldownActionLimit:int = 0
|
|
||||||
self.cooldownDuration:int = 0 #Seconds
|
|
||||||
|
|
||||||
self.actionList:list = []
|
|
||||||
|
|
||||||
def setupCooldown(self, name, limit, duration):
|
|
||||||
self.cooldownName = name
|
|
||||||
self.cooldownActionLimit = limit
|
|
||||||
self.cooldownDuration = duration
|
|
||||||
|
|
||||||
class Cooldown_Module:
|
|
||||||
def __init__(self):
|
|
||||||
super().__init__()
|
|
||||||
self.cooldownList:list = []
|
|
||||||
|
|
||||||
def setupCooldown(self, name, limit, duration):
|
|
||||||
newCD:Cooldown = Cooldown()
|
|
||||||
newCD.setupCooldown(name, limit, duration)
|
|
||||||
self.cooldownList.append(newCD)
|
|
||||||
|
|
||||||
|
|
||||||
def getCooldown(self, name:str):
|
|
||||||
returnCD:bool = False
|
|
||||||
for cd in self.cooldownList:
|
|
||||||
if cd.cooldownName == name:
|
|
||||||
returnCD = True
|
|
||||||
return cd
|
|
||||||
if returnCD == False:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def isCooldownActive(self, name:str):
|
|
||||||
isCooldownActivated:bool = False
|
|
||||||
|
|
||||||
selectedCooldown:Cooldown = self.getCooldown(name)
|
|
||||||
|
|
||||||
if selectedCooldown == None:
|
|
||||||
return None
|
|
||||||
|
|
||||||
timenow = datetime.datetime.now()
|
|
||||||
|
|
||||||
if len(selectedCooldown.actionList) >= selectedCooldown.cooldownActionLimit:
|
|
||||||
actionCount = len(selectedCooldown.actionList)
|
|
||||||
|
|
||||||
maxTmpIndex = actionCount - selectedCooldown.cooldownActionLimit
|
|
||||||
maxRecentAction:Cooldown_Action = selectedCooldown.actionList[maxTmpIndex]
|
|
||||||
|
|
||||||
timeDiff = timenow - maxRecentAction.time
|
|
||||||
maxTimeAllowed = timedelta(seconds = selectedCooldown.cooldownDuration)
|
|
||||||
|
|
||||||
if timeDiff < maxTimeAllowed:
|
|
||||||
isCooldownActivated = True
|
|
||||||
|
|
||||||
return isCooldownActivated
|
|
||||||
|
|
||||||
def actionTrigger(self, name:str = "", tag:str = ""):
|
|
||||||
newAction = Cooldown_Action()
|
|
||||||
newAction.tag = tag
|
|
||||||
targetCD = self.getCooldown(name)
|
|
||||||
if targetCD != None:
|
|
||||||
targetCD.actionList.append(newAction)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
testCD = Cooldowns_Module()
|
|
||||||
cdName = "test"
|
|
||||||
testCD.setupCooldown(cdName, 20, 2)
|
|
||||||
|
|
||||||
print("CD Test 0: ")
|
|
||||||
for x in range(20):
|
|
||||||
testCD.actionTrigger("cdName")
|
|
||||||
sleep(0)
|
|
||||||
print(testCD.isCooldownActive("cdName"))
|
|
||||||
print("//Test Done//")
|
|
||||||
sleep(2)
|
|
||||||
|
|
||||||
print("CD Test 1: ")
|
|
||||||
for x in range(20):
|
|
||||||
testCD.actionTrigger(cdName)
|
|
||||||
sleep(0)
|
|
||||||
print(testCD.isCooldownActive("test"))
|
|
||||||
print("//Test Done//")
|
|
||||||
sleep(2)
|
|
||||||
|
|
||||||
print("CD Test 2: ")
|
|
||||||
for x in range(10):
|
|
||||||
testCD.actionTrigger(cdName)
|
|
||||||
sleep(0)
|
|
||||||
print(testCD.isCooldownActive(cdName))
|
|
||||||
print("//Test Done//")
|
|
||||||
sleep(2)
|
|
||||||
|
|
||||||
print("CD Test 3: ")
|
|
||||||
for x in range(20):
|
|
||||||
testCD.actionTrigger(cdName)
|
|
||||||
sleep(0.05)
|
|
||||||
print(testCD.isCooldownActive(cdName))
|
|
||||||
print("//Test Done//")
|
|
||||||
sleep(2)
|
|
||||||
|
|
||||||
print("CD Test 4: ")
|
|
||||||
for x in range(20):
|
|
||||||
testCD.actionTrigger(cdName)
|
|
||||||
sleep(0.6)
|
|
||||||
print(testCD.isCooldownActive(cdName))
|
|
||||||
print("//Test Done//")
|
|
||||||
@ -1,4 +1,3 @@
|
|||||||
from typing import Sequence
|
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
|
|
||||||
@ -13,7 +12,6 @@ import commands.loader as command_loader
|
|||||||
import credentials
|
import credentials
|
||||||
from commands.command_base import AbstractCommand
|
from commands.command_base import AbstractCommand
|
||||||
|
|
||||||
from cooldowns import Cooldown_Module
|
|
||||||
|
|
||||||
class Twitch_Module():
|
class Twitch_Module():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -32,11 +30,6 @@ class Twitch_Module():
|
|||||||
self._urlMatcher = re.compile(
|
self._urlMatcher = re.compile(
|
||||||
"(https?:(/{1,3}|[a-z0-9%])|[a-z0-9.-]+[.](com|net|org|edu|gov|mil|aero|asia|biz|cat|coop|info|int|jobs|mobi|museum|name|post|pro|tel|travel|xxx|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|Ja|sk|sl|sm|sn|so|sr|ss|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw))")
|
"(https?:(/{1,3}|[a-z0-9%])|[a-z0-9.-]+[.](com|net|org|edu|gov|mil|aero|asia|biz|cat|coop|info|int|jobs|mobi|museum|name|post|pro|tel|travel|xxx|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|Ja|sk|sl|sm|sn|so|sr|ss|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw))")
|
||||||
|
|
||||||
# Default Twitch Chat limit is 20 per 30 seconds
|
|
||||||
# If Mod or Op, Twitch Chat limit is 100 per 30 seconds
|
|
||||||
self.twitchChat_cooldown:Cooldown_Module = Cooldown_Module()
|
|
||||||
self.twitchChat_cooldown.setupCooldown("twitchChat", 20, 32)
|
|
||||||
|
|
||||||
def join_channel(self, credential: credentials.Twitch_Credential, channel_name:str):
|
def join_channel(self, credential: credentials.Twitch_Credential, channel_name:str):
|
||||||
channel_name = "#" + channel_name
|
channel_name = "#" + channel_name
|
||||||
print("Connecting to Channel: " + channel_name)
|
print("Connecting to Channel: " + channel_name)
|
||||||
@ -60,9 +53,7 @@ class Twitch_Module():
|
|||||||
self.chat.irc.socket.close()
|
self.chat.irc.socket.close()
|
||||||
|
|
||||||
def send_message(self, message):
|
def send_message(self, message):
|
||||||
if self.twitchChat_cooldown.isCooldownActive("twitchChat") == False:
|
self.chat.send(message)
|
||||||
self.chat.send(message)
|
|
||||||
self.twitchChat_cooldown.actionTrigger("twitchChat")
|
|
||||||
|
|
||||||
def send_whisper(self, user, message):
|
def send_whisper(self, user, message):
|
||||||
pass
|
pass
|
||||||
@ -73,10 +64,8 @@ class Twitch_Module():
|
|||||||
if message.channel == "thecuriousnerd":
|
if message.channel == "thecuriousnerd":
|
||||||
|
|
||||||
if not self.isSenderBot(message):
|
if not self.isSenderBot(message):
|
||||||
if self.twitchChat_cooldown.isCooldownActive("twitchChat") == False:
|
if message.sender.lower() == "thecuriousnerd":
|
||||||
self.eval_commands(message)
|
self.eval_commands(message)
|
||||||
#elif message.channel == message.sender:
|
|
||||||
#self.eval_commands(message)
|
|
||||||
self.tts_message(message)
|
self.tts_message(message)
|
||||||
|
|
||||||
def eval_commands(self, message: twitch.chat.Message):
|
def eval_commands(self, message: twitch.chat.Message):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user