Fixed Cooldowns Bug

This commit is contained in:
Alex Orid 2020-10-15 01:58:00 -04:00
parent 5f5496c918
commit e7d9ecb273
2 changed files with 13 additions and 13 deletions

View File

@ -34,21 +34,17 @@ class Cooldowns_Module:
isCoolDownActivated:bool = False isCoolDownActivated:bool = False
timenow = datetime.datetime.now() timenow = datetime.datetime.now()
timepast = timenow.fromtimestamp
if len(self.actionList) > self.coolDownActionLimit: if len(self.actionList) >= self.coolDownActionLimit:
actionCount = len(self.actionList) actionCount = len(self.actionList)
maxTmpIndex = actionCount - self.coolDownActionLimit - 1 maxTmpIndex = actionCount - self.coolDownActionLimit - 1
maxRecentAction:Cooldown_Action = self.actionList[maxTmpIndex] maxRecentAction:Cooldown_Action = self.actionList[maxTmpIndex]
minTmpIndex = actionCount - 1 timeDiff = timenow - maxRecentAction.time
mostRecentAction:Cooldown_Action = self.actionList[minTmpIndex]
timeDiff = mostRecentAction.time - maxRecentAction.time
maxTimeAllowed = timedelta(seconds = self.coolDownDuration) maxTimeAllowed = timedelta(seconds = self.coolDownDuration)
if timeDiff >= maxTimeAllowed: if timeDiff < maxTimeAllowed:
isCoolDownActivated = True isCoolDownActivated = True
return isCoolDownActivated return isCoolDownActivated
@ -60,7 +56,7 @@ class Cooldowns_Module:
if __name__ == "__main__": if __name__ == "__main__":
testCD = Cooldowns_Module() testCD = Cooldowns_Module()
testCD.setupCooldown("test", 20, 1) testCD.setupCooldown("test", 20, 5)
print("CD Test 1: ") print("CD Test 1: ")
for x in range(10): for x in range(10):
@ -71,11 +67,11 @@ if __name__ == "__main__":
print("CD Test 2: ") print("CD Test 2: ")
for x in range(21): for x in range(21):
testCD.actionTrigger() testCD.actionTrigger()
sleep(0.08) sleep(0.05)
print(testCD.isCooldownActive()) print(testCD.isCooldownActive())
print("CD Test 3: ") print("CD Test 3: ")
for x in range(40): for x in range(20):
testCD.actionTrigger() testCD.actionTrigger()
sleep(0.02) sleep(0.6)
print(testCD.isCooldownActive()) print(testCD.isCooldownActive())

View File

@ -32,8 +32,10 @@ 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:Cooldowns_Module = Cooldowns_Module() self.twitchChat_cooldown:Cooldowns_Module = Cooldowns_Module()
self.twitchChat_cooldown.setupCooldown("twitchChat", 20, 30) 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
@ -71,8 +73,10 @@ class Twitch_Module():
if message.channel == "thecuriousnerd": if message.channel == "thecuriousnerd":
if not self.isSenderBot(message): if not self.isSenderBot(message):
if message.sender.lower() == "thecuriousnerd": if self.twitchChat_cooldown.isCooldownActive() == False:
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):