diff --git a/config.py b/config.py index 32ec879..f8a4ccb 100644 --- a/config.py +++ b/config.py @@ -2,19 +2,33 @@ from enum import Enum credentialsNickname = "praxis_bot" -twitch_module: bool = True -discord_module: bool = False +twitch_module: bool = False +discord_module: bool = True test_module: bool = False autojoin_TwitchChannels = ["thecuriousnerd"] +whitelisted_TwitchPowerUsers = ["thecuriousnerd", "theredpoint", "lakotor"] + block_TwitchChannelsMessaging = [""] -block_TwitchChannelsTTS = [""] -blockAll_TwitchChatChannelMessaging = False -blockAll_TwitchChatChannelTTS = False +blockAll_TwitchChatChannelsMessaging = False -selected_discordTTSChannels = ["431129571308339210"] +autoEnabled_TwitchChannelsTTS = False +block_TwitchChannelsTTS = [""] # block supersedes the tts_enabled bool +blockAll_TwitchChatChannelsTTS = False # blockAll supersedes the force bool and force list and tts_enabled bool +force_TwitchChannelsTTS = [""] # force supersedes the block list +forceAll_TwitchChatChannelsTTS = False # forceAll supersedes the blockAll bool and block list and force list +block_DiscordChannelsMessaging = [""] +blockAll_DiscordChannelsMessaging = False +blockAll_DiscordPrivateMessaging = False # Private Messaging not yet implemented + +selected_DiscordTTSChannels = ["431129571308339210"] +autoEnabled_DiscordChannelsTTS = False +block_DiscordChannelsTTS = [""] # block supersedes the tts_enabled bool +blockAll_DiscordChannelsTTS = False # blockAll supersedes the force bool and force list and tts_enabled bool +force_DiscordChannelsTTS = [""] # force supersedes the block list +forceAll_DiscordChatChannelsTTS = False # forceAll supersedes the blockAll bool and block list and force list class Speaker(Enum): GOOGLE_TEXT_TO_SPEECH = 1 diff --git a/discord_script.py b/discord_script.py index 907aa3c..dafb5fd 100644 --- a/discord_script.py +++ b/discord_script.py @@ -79,9 +79,14 @@ class Discord_Module(discord.Client): async def eval_triggeredEvents(self, message: discord.Message): # This will check for the selected channels and will TTS stuff from there. + await self.tts_message(message) + foundChannel = False + for channel in self.selected_ttsChannels: if channel == message.channel.id: - await self.tts_message(message) + # await self.tts_message(message) + pass + async def eval_automaticEvents(self, message: discord.Message): @@ -114,20 +119,36 @@ class Discord_Module(discord.Client): #print(e) pass # we don't care - async def send_message(self, message, response): - if self.cooldownModule.isCooldownActive("discordRateLimit") == False: + async def send_message(self, message: discord.Message, response): + isBlocked = await self.isChannel_inConfigList(str(message.channel.id), config.block_DiscordChannelsMessaging) + if self.cooldownModule.isCooldownActive("discordRateLimit") == False and not isBlocked and not config.blockAll_DiscordChannelsMessaging: await message.channel.send(response) self.cooldownModule.actionTrigger("discordRateLimit") + async def tts_message(self, message: discord.Message): - if not await self.contains_slur(message): - if self.tts_enabled: + isBlocked = await self.isChannel_inConfigList(str(message.channel.id), config.block_DiscordChannelsTTS) + isForced = (await self.isChannel_inConfigList(str(message.channel.id), config.force_DiscordChannelsTTS) and not config.blockAll_DiscordChannelsTTS) + #print("isBlocked: " + str(isBlocked)) + #print("isForced: " + str(isForced)) + if (not await self.contains_slur(message)): + if self.tts_enabled and not isBlocked and not config.blockAll_DiscordChannelsTTS or isForced or config.forceAll_DiscordChatChannelsTTS: if not message.content.startswith('!'): text_to_say: str = "%s says, %s" % (message.author.display_name, message.content) channel_text = "%s user msg" % message.channel tts.tts(text_to_say) + + if not await self.contains_slur(message): + if self.tts_enabled: + if not message.content.startswith('!'): + pass + #text_to_say: str = "%s says, %s" % (message.author.display_name, message.content) + #channel_text = "%s user msg" % message.channel + + #tts.tts(text_to_say) + # Checks for basic slurs. async def contains_slur(self, message: discord.Message): containsSlur: bool = False @@ -162,6 +183,20 @@ class Discord_Module(discord.Client): print("<{ bot detected! }> ") return isBot + async def isChannel_inConfigList(self, selectedChannel, selectedList): + #print(channel) + #print(selectedList) + is_Self = False + for discordChannel in selectedList: + print("isSelf: " + str(discordChannel) + " vs " + str(selectedChannel)) + if discordChannel == selectedChannel: + is_Self = True + #if is_Self: + # print("Is Self") + #if not is_Self: + # print("Is Not Self") + return is_Self + diff --git a/main.py b/main.py index b73c292..5479772 100644 --- a/main.py +++ b/main.py @@ -31,7 +31,11 @@ def twitch_module_init(dbCert, twitchCert): twitchModule_.db_manager.setup_engine(dbCert) twitchModule_.twitchCredential = twitchCert + twitchModule_.tts_enabled = config.autoEnabled_TwitchChannelsTTS + twitchModule_.whitelisted_users = config.whitelisted_TwitchPowerUsers + for twitchChannel in config.autojoin_TwitchChannels: + print("joining channel function") twitchModule_.join_channel(None, twitchChannel) def discord_module_init(dbCert, discordCert): @@ -39,7 +43,9 @@ def discord_module_init(dbCert, discordCert): discordModule_.dbCredential = dbCert discordModule_.discordCredential = discordCert - for ttsChannel in config.selected_discordTTSChannels: + discordModule_.tts_enabled = config.autoEnabled_DiscordChannelsTTS + + for ttsChannel in config.selected_DiscordTTSChannels: discordModule_.selected_ttsChannels.append(int(ttsChannel)) discordModule_.main() diff --git a/twitch_script.py b/twitch_script.py index 127f400..a17094b 100644 --- a/twitch_script.py +++ b/twitch_script.py @@ -28,7 +28,7 @@ class Twitch_Module(): self.tts_enabled: bool = False self.tts_whitelist_enabled: bool = False self.links_allowed: bool = True - self.whitelisted_users: list = ["thecuriousnerd", "theredpoint", "lakotor"] + self.whitelisted_users: list = ["thecuriousnerd"] # don't freak out, this is *merely* a regex for matching urls that will hit just about everything 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))") @@ -40,7 +40,7 @@ class Twitch_Module(): def join_channel(self, credential: credentials.Twitch_Credential, channel_name:str): channel_name = "#" + channel_name - print("Connecting to Channel: " + channel_name) + print("Connecting to Channel: " + channel_name + "...") if credential is None: credential = self.twitchCredential @@ -62,8 +62,11 @@ class Twitch_Module(): self.chat.irc.socket.close() def send_message(self, message): - if self.cooldownModule.isCooldownActive("twitchChat") == False: + isBlocked = self.isChannel_inConfigList(self.chat.channel, config.block_TwitchChannelsMessaging) + #print("isBlocked: " + str(isBlocked) + " for: " + self.chat.channel) + if self.cooldownModule.isCooldownActive("twitchChat") == False and not isBlocked and not config.blockAll_TwitchChatChannelsMessaging: self.chat.send(message) + #print("Sent ChatMSG") self.cooldownModule.actionTrigger("twitchChat") def send_whisper(self, user, message): @@ -72,13 +75,11 @@ class Twitch_Module(): # This reacts to messages def twitch_chat(self, message: twitch.chat.Message) -> None: print("[#" + message.channel + "](" + message.sender + ")> " + message.text) - if message.channel == "thecuriousnerd": - - if not self.isSenderBot(message): - if self.cooldownModule.isCooldownActive("twitchChat") == False: - print("Pre Eval") - self.eval_commands(message) - self.tts_message(message) + if not self.isSenderBot(message): + if self.cooldownModule.isCooldownActive("twitchChat") == False: + print("Pre Eval") + self.eval_commands(message) + self.tts_message(message) def eval_commands(self, message: twitch.chat.Message): print("evaling command") @@ -111,8 +112,10 @@ class Twitch_Module(): def tts_message(self, message: twitch.chat.Message): - if not self.contains_slur(message): - if self.tts_enabled: + isBlocked = self.isChannel_inConfigList(self.chat.channel, config.block_TwitchChannelsTTS) + isForced = (self.isChannel_inConfigList(self.chat.channel, config.force_TwitchChannelsTTS) and not config.blockAll_TwitchChatChannelsTTS) + if (not self.contains_slur(message)): + if self.tts_enabled and not isBlocked and not config.blockAll_TwitchChatChannelsTTS or isForced or config.forceAll_TwitchChatChannelsTTS: if not message.text.startswith('!'): text_to_say: str = "%s says, %s" % (message.sender, message.text) channel_text = "%s user msg" % message.channel @@ -150,6 +153,19 @@ class Twitch_Module(): print("<{ slur detected! }> " + " [#" + message.channel + "](" + message.sender + ") used a slur in chat") return containsSlur + def isChannel_inConfigList(self, selectedChannel, selectedList): + #print(channel) + #print(selectedList) + is_Self = False + for twitchChannel in selectedList: + if twitchChannel == selectedChannel: + is_Self = True + #if is_Self: + # print("Is Self") + #if not is_Self: + # print("Is Not Self") + return is_Self + # This is a old function used prior to the creation of the Twitch_Module class above.