From b0169ec68d2a47e3dad4d96d66350e06f3b80dc5 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Tue, 20 Oct 2020 04:44:52 -0400 Subject: [PATCH] Setup Cooldowns & Msg Clean Up --- commands/implemented/command_roll_discord.py | 6 ++++-- discord_script.py | 10 ++++++++++ twitch_script.py | 10 +++++----- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/commands/implemented/command_roll_discord.py b/commands/implemented/command_roll_discord.py index cc1f747..8c86d07 100644 --- a/commands/implemented/command_roll_discord.py +++ b/commands/implemented/command_roll_discord.py @@ -24,7 +24,8 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta): #twitch_message.chat.send("test acknowledged") diceRoll: str = "" - await discord_message.channel.send("Rolling Dice...") + await bot.send_message(discord_message, "Rolling Dice...") + #await discord_message.channel.send("Rolling Dice...") print("Rolling Dice...") temp_preParsedMessage = discord_message.content.split("+") @@ -70,4 +71,5 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta): diceRoll = discord_message.author.mention + " rolled: " + diceRoll print(diceRoll) - await discord_message.channel.send(diceRoll) \ No newline at end of file + await bot.send_message(discord_message, diceRoll) + #await discord_message.channel.send(diceRoll) diff --git a/discord_script.py b/discord_script.py index 9bc8325..f6041d0 100644 --- a/discord_script.py +++ b/discord_script.py @@ -17,12 +17,17 @@ import discord import discord.message import discord.channel +from cooldowns import Cooldown_Module + class Discord_Module(discord.Client): def __init__(self): super().__init__() self.dbCredential: credentials.DB_Credential self.discordCredential: credentials.Discord_Credential + self.cooldownModule:Cooldown_Module = Cooldown_Module() + self.cooldownModule.setupCooldown("discordRateLimit", 10, 1) + self.commands = command_loader.load_commands() self.tts_enabled: bool = False @@ -69,6 +74,11 @@ class Discord_Module(discord.Client): except Exception as e: print(e) pass # we don't care + + async def send_message(self, message, response): + if self.cooldownModule.isCooldownActive("discordRateLimit") == False: + await message.channel.send(response) + self.cooldownModule.actionTrigger("discordRateLimit") diff --git a/twitch_script.py b/twitch_script.py index bf4ef2c..b05ed8e 100644 --- a/twitch_script.py +++ b/twitch_script.py @@ -34,8 +34,8 @@ class Twitch_Module(): # 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) + self.cooldownModule:Cooldown_Module = Cooldown_Module() + self.cooldownModule.setupCooldown("twitchChat", 20, 32) def join_channel(self, credential: credentials.Twitch_Credential, channel_name:str): channel_name = "#" + channel_name @@ -60,9 +60,9 @@ class Twitch_Module(): self.chat.irc.socket.close() def send_message(self, message): - if self.twitchChat_cooldown.isCooldownActive("twitchChat") == False: + if self.cooldownModule.isCooldownActive("twitchChat") == False: self.chat.send(message) - self.twitchChat_cooldown.actionTrigger("twitchChat") + self.cooldownModule.actionTrigger("twitchChat") def send_whisper(self, user, message): pass @@ -73,7 +73,7 @@ class Twitch_Module(): if message.channel == "thecuriousnerd": if not self.isSenderBot(message): - if self.twitchChat_cooldown.isCooldownActive("twitchChat") == False: + if self.cooldownModule.isCooldownActive("twitchChat") == False: self.eval_commands(message) #elif message.channel == message.sender: #self.eval_commands(message)