Discord TTS Channels

This commit is contained in:
Alex Orid 2021-04-29 17:07:41 -04:00
parent 8bd428637e
commit a5429e5ce5
2 changed files with 58 additions and 5 deletions

View File

@ -39,7 +39,7 @@ blockAll_DiscordChannelsMessaging = False # Blocks the ability to send messages
blockAll_DiscordPrivateMessaging = False # Private Messaging not yet implemented
autoEnabled_DiscordChannelsTTS = False
autoEnabled_DiscordChannelsTTS = True
selected_DiscordTTSChannels = ["431129571308339210"]
block_DiscordChannelsTTS = [""] # block supersedes the tts_enabled bool
blockAll_DiscordChannelsTTS = False # blockAll supersedes the force bool and force list and tts_enabled bool
@ -48,8 +48,8 @@ forceAll_DiscordChatChannelsTTS = False # forceAll supersedes the blockAll bool
blockAll_TTS_URL_Discord = True
autoEnabled_Discord_rgbLightControl = False
#OLD CONFIGS WILL DELETE
#autoEnabled_Discord_rgbLightControl = False
#discord_defaultCommandEnabledState = True
#discord_defaultCommandEnabledState_liveStreamOnly = True # If true this will make commands only available during live streams.

View File

@ -70,7 +70,7 @@ class Discord_Module(discord.Client):
#await self.eval_triggeredEvents(message)
await self.eval_commands(message)
#await self.tts_message(message)
await self.eval_tts(message)
async def eval_triggeredEvents(self, message: discord.Message):
@ -83,6 +83,15 @@ class Discord_Module(discord.Client):
# await self.tts_message(message)
pass
async def eval_tts(self, message: discord.Message):
command, rest = utility.parse_line(message.content)
try:
is_actionable = await self.is_command(command)
if not is_actionable:
await self.exec_tts(message)
except:
print("something went wrong with tts")
async def eval_commands(self, message: discord.Message):
command, rest = utility.parse_line(message.content)
try:
@ -115,7 +124,6 @@ class Discord_Module(discord.Client):
# todo handle failed requests
pass
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:
@ -144,6 +152,51 @@ class Discord_Module(discord.Client):
return is_Self
async def exec_tts(self, message: discord.Message):
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))
print(message.channel.id, message.channel.id, message.channel.id)
isMessageChannelInList = False
for TTS_C_id in config.selected_DiscordTTSChannels:
print(TTS_C_id)
if int(TTS_C_id) == int(message.channel.id):
isMessageChannelInList = True
if config.autoEnabled_DiscordChannelsTTS and (isMessageChannelInList) 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
await self.exec_tts_sender("", text_to_say)
async def exec_tts_sender(self, username, message):
params = urlencode({'tts_sender': username, 'tts_text': message})
#standalone_tts_core
url = "http://standalone_tts_core:60809/api/v1/tts/send_text?%s" % params
resp = requests.get(url)
if resp.status_code == 200:
print("Got the following message: %s" % resp.text)
data = loads(resp.text)
msg = data['message']
if msg is not None:
return msg
# todo send to logger and other relevent services
else:
# todo handle failed requests
pass
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)