diff --git a/.env.template b/.env.template index cfa6a37..c11f89d 100644 --- a/.env.template +++ b/.env.template @@ -5,6 +5,7 @@ DiscordToken= DiscordBroadcastChannel= DiscordAlertUserID= DiscordDebugChannel= +DiscordChatChannel= # #---[Archipelago Config]--- ArchipelagoServer=wss://archipelago.gg @@ -65,4 +66,4 @@ JoinMessage='' DebugMode=false DiscordJoinOnly=false SelfHostNoWeb=false -CycleDiscord=0 \ No newline at end of file +CycleDiscord=0 diff --git a/bridgeipelago.py b/bridgeipelago.py index d6ba723..9158e7e 100644 --- a/bridgeipelago.py +++ b/bridgeipelago.py @@ -49,6 +49,7 @@ DiscordBroadcastChannel = int(os.getenv('DiscordBroadcastChannel')) DiscordAlertUserID = os.getenv('DiscordAlertUserID') DiscordDebugChannel = int(os.getenv('DiscordDebugChannel')) +DiscordChatChannel = int(os.getenv('DiscordChatChannel') or DiscordBroadcastChannel) ArchHost = os.getenv('ArchipelagoServer') ArchPort = os.getenv('ArchipelagoPort') @@ -389,6 +390,8 @@ async def on_ready(): global DebugChannel DebugChannel = DiscordClient.get_channel(DiscordDebugChannel) await DebugChannel.send('Bot connected. Debug control - Online.') + global ChatChannel + ChatChannel = DiscordClient.get_channel(DiscordChatChannel) # We wont sync the command tree for now, need to roll out central control first. #await tree.sync(guild=discord.Object(id=DiscordGuildID)) @@ -404,24 +407,24 @@ async def on_ready(): print("++ Async bot started -", DiscordClient.user) @DiscordClient.event -async def on_message(message): +async def on_message(message: discord.Message) -> None: if message.author == DiscordClient.user: return - - if message.channel.id != MainChannel.id: + + if message.channel.id not in [MainChannel.id, ChatChannel.id, DebugChannel.id]: return - + # Registers user for a alot in Archipelago if message.content.startswith('$register'): ArchSlot = message.content ArchSlot = ArchSlot.replace("$register ","") Status = await Command_Register(str(message.author),ArchSlot) - await SendMainChannelMessage(Status) + await message.reply(Status) # Clears registration file for user if message.content.startswith('$clearreg'): Status = await Command_ClearReg(str(message.author)) - await SendMainChannelMessage(Status) + await message.reply(Status) if message.content.startswith('$listreg'): await Command_ListRegistrations(message.author) @@ -438,44 +441,45 @@ async def on_message(message): if message.content.startswith('$groupcheck'): game = (message.content).split('$groupcheck ') await Command_GroupCheck(message.author, game[1]) - + if message.content.startswith('$hints'): - await Command_Hints(message.author) - + await Command_Hints(message) + if message.content.startswith('$deathcount'): - await Command_DeathCount() - + await Command_DeathCount(message) + if message.content.startswith('$checkcount'): - await Command_CheckCount() - + await Command_CheckCount(message) + if message.content.startswith('$checkgraph'): - await Command_CheckGraph() - + await Command_CheckGraph(message) + if message.content.startswith('$iloveyou'): await Command_ILoveYou(message) if message.content.startswith('$hello'): await Command_Hello(message) + if message.content.startswith('$archinfo'): await Command_ArchInfo(message) if message.content.startswith('$setenv'): pair = ((message.content).split('$setenv '))[1].split(' ') rtrnmessage = SetEnvVariable(pair[0], pair[1]) - await SendMainChannelMessage(rtrnmessage) + await message.reply(rtrnmessage) if message.content.startswith('$reloadtracker'): ReloadBot() - await SendMainChannelMessage("Reloading tracker... Please wait about 5-10 seconds.") - + await message.reply("Reloading tracker... Please wait about 5-10 seconds.") + if message.content.startswith('$reloaddiscord'): discordseppuku_queue.put("Reloading Discord bot...") - await SendMainChannelMessage("Reloading Discord bot... Please wait.") + await message.reply("Reloading Discord bot... Please wait.") if message.content.startswith('$reloaddata'): ReloadJSONPackages() - await SendMainChannelMessage("Reloading datavars... Please wait 2-3 seconds.") + await message.reply("Reloading datavars... Please wait 2-3 seconds.") if not message.content.startswith('$') and EnableDiscordBridge == "true": relayed_message = "(Discord) " + str(message.author) + " - " + str(message.content) @@ -493,7 +497,7 @@ async def CheckCommandQueue(): ProcessItemQueue.stop() ProcessDeathQueue.stop() ProcessChatQueue.stop() - + print("++ Closing Discord Client") exit() @@ -635,42 +639,42 @@ async def ProcessChatQueue(): chatmessage = chat_queue.get() if not (chatmessage['data'][0]['text']).startswith(ArchipelagoBotSlot): if not chatmessage['message'].lower().startswith("!"): - await SendMainChannelMessage(chatmessage['data'][0]['text']) + await SendChatChannelMessage(chatmessage['data'][0]['text']) else: if EnableAPClientHelp == "true" and chatmessage['message'].lower().startswith("!help"): - await SendMainChannelMessage(chatmessage['data'][0]['text']) + await SendChatChannelMessage(chatmessage['data'][0]['text']) elif EnableAPClientLicense == "true" and chatmessage['message'].lower().startswith("!license"): - await SendMainChannelMessage(chatmessage['data'][0]['text']) + await SendChatChannelMessage(chatmessage['data'][0]['text']) elif EnableAPClientCountdown == "true" and chatmessage['message'].lower().startswith("!countdown"): - await SendMainChannelMessage(chatmessage['data'][0]['text']) + await SendChatChannelMessage(chatmessage['data'][0]['text']) elif EnableAPClientOptions == "true" and chatmessage['message'].lower().startswith("!options"): - await SendMainChannelMessage(chatmessage['data'][0]['text']) + await SendChatChannelMessage(chatmessage['data'][0]['text']) elif EnableAPClientAdmin == "true" and chatmessage['message'].lower().startswith("!admin"): - await SendMainChannelMessage(chatmessage['data'][0]['text']) + await SendChatChannelMessage(chatmessage['data'][0]['text']) elif EnableAPClientPlayers == "true" and chatmessage['message'].lower().startswith("!players"): - await SendMainChannelMessage(chatmessage['data'][0]['text']) + await SendChatChannelMessage(chatmessage['data'][0]['text']) elif EnableAPClientStatus == "true" and chatmessage['message'].lower().startswith("!status"): - await SendMainChannelMessage(chatmessage['data'][0]['text']) + await SendChatChannelMessage(chatmessage['data'][0]['text']) elif EnableAPClientRelease == "true" and chatmessage['message'].lower().startswith("!release"): - await SendMainChannelMessage(chatmessage['data'][0]['text']) + await SendChatChannelMessage(chatmessage['data'][0]['text']) elif EnableAPClientCollect == "true" and chatmessage['message'].lower().startswith("!collect"): - await SendMainChannelMessage(chatmessage['data'][0]['text']) + await SendChatChannelMessage(chatmessage['data'][0]['text']) elif EnableAPClientRemaining == "true" and chatmessage['message'].lower().startswith("!remaining"): - await SendMainChannelMessage(chatmessage['data'][0]['text']) + await SendChatChannelMessage(chatmessage['data'][0]['text']) elif EnableAPClientMissing == "true" and chatmessage['message'].lower().startswith("!missing"): - await SendMainChannelMessage(chatmessage['data'][0]['text']) + await SendChatChannelMessage(chatmessage['data'][0]['text']) elif EnableAPClientChecked == "true" and chatmessage['message'].lower().startswith("!checked"): - await SendMainChannelMessage(chatmessage['data'][0]['text']) + await SendChatChannelMessage(chatmessage['data'][0]['text']) elif EnableAPClientAlias == "true" and chatmessage['message'].lower().startswith("!alias"): - await SendMainChannelMessage(chatmessage['data'][0]['text']) + await SendChatChannelMessage(chatmessage['data'][0]['text']) elif EnableAPClientGetItem == "true" and chatmessage['message'].lower().startswith("!getitem"): - await SendMainChannelMessage(chatmessage['data'][0]['text']) + await SendChatChannelMessage(chatmessage['data'][0]['text']) elif EnableAPClientHint == "true" and chatmessage['message'].lower().startswith("!hint"): - await SendMainChannelMessage(chatmessage['data'][0]['text']) + await SendChatChannelMessage(chatmessage['data'][0]['text']) elif EnableAPClientHintLocation == "true" and chatmessage['message'].lower().startswith("!hint_location"): - await SendMainChannelMessage(chatmessage['data'][0]['text']) + await SendChatChannelMessage(chatmessage['data'][0]['text']) elif EnableAPClientVideo == "true" and chatmessage['message'].lower().startswith("!video"): - await SendMainChannelMessage(chatmessage['data'][0]['text']) + await SendChatChannelMessage(chatmessage['data'][0]['text']) else: await CancelProcess() @@ -735,6 +739,9 @@ async def first_command(interaction): async def SendMainChannelMessage(message): await MainChannel.send(message) +async def SendChatChannelMessage(message): + await ChatChannel.send(message) + async def SendDebugChannelMessage(message): await DebugChannel.send(message) @@ -907,12 +914,13 @@ async def Command_GroupCheck(DMauthor, game): print(e) await DebugChannel.send("ERROR IN GROUPCHECK <@"+DiscordAlertUserID+">") -async def Command_Hints(player): +async def Command_Hints(message: discord.Message) -> None: if SelfHostNoWeb == "true": - await MainChannel.send("This command is not available in self-hosted mode.") + await message.reply("This command is not available in self-hosted mode.") return - + try: + player = message.author await player.create_dm() page = requests.get(ArchTrackerURL) @@ -952,7 +960,7 @@ async def Command_Hints(player): found = (row.find_all('td')[6].text).strip() if(found == "✔"): continue - + finder = (row.find_all('td')[0].text).strip() receiver = (row.find_all('td')[1].text).strip() item = (row.find_all('td')[2].text).strip() @@ -1020,7 +1028,7 @@ async def Command_Hints(player): print(e) await DebugChannel.send("ERROR IN HINTLIST <@"+DiscordAlertUserID+">") -async def Command_DeathCount(): +async def Command_DeathCount(message: discord.Message) -> None: try: d = open(DeathFileLocation,"r") DeathLines = d.readlines() @@ -1028,9 +1036,9 @@ async def Command_DeathCount(): deathdict = {} if len(DeathLines) == 0: - await MainChannel.send("No deaths to report.") + await message.reply("No deaths to report.") return - + for deathline in DeathLines: DeathUser = deathline.split("||")[6] DeathUser = DeathUser.split("\n")[0] @@ -1050,7 +1058,7 @@ async def Command_DeathCount(): deathcounts.append(int(deathdict[key])) message = message + "\n" + str(key) + ": " + str(deathdict[key]) message = message + '```' - await MainChannel.send(message) + await message.reply(message) ### PLOTTING CODE ### with plt.xkcd(): @@ -1093,14 +1101,14 @@ async def Command_DeathCount(): # Save image and send - any existing plot will be overwritten plt.savefig(DeathPlotLocation, bbox_inches="tight") - await MainChannel.send(file=discord.File(DeathPlotLocation)) + await message.reply(file=discord.File(DeathPlotLocation)) except Exception as e: WriteToErrorLog("Command_DeathCount", "Error in death count command: " + str(e)) await DebugChannel.send("ERROR DEATHCOUNT <@"+DiscordAlertUserID+">") -async def Command_CheckCount(): +async def Command_CheckCount(message: discord.Message) -> None: if SelfHostNoWeb == "true": - await MainChannel.send("This command is not available in self-hosted mode.") + await message.reply("This command is not available in self-hosted mode.") return try: @@ -1127,7 +1135,7 @@ async def Command_CheckCount(): game = (row.find_all('td')[2].text).strip() status = (row.find_all('td')[3].text).strip() checks = (row.find_all('td')[4].text).strip() - + SlotArray.append(len(slot)) GameArray.append(len(game)) StatusArray.append(len(status)) @@ -1167,15 +1175,15 @@ async def Command_CheckCount(): #Finishes the check message checkmessage = checkmessage + "```" - await MainChannel.send(checkmessage) + await message.reply(checkmessage) except Exception as e: WriteToErrorLog("Command_CheckCount", "Error in check count command: " + str(e)) print(e) await DebugChannel.send("ERROR IN CHECKCOUNT <@"+DiscordAlertUserID+">") -async def Command_CheckGraph(): +async def Command_CheckGraph(message: discord.Message) -> None: if SelfHostNoWeb == "true": - await MainChannel.send("This command is not available in self-hosted mode.") + await message.reply("This command is not available in self-hosted mode.") return try: @@ -1246,19 +1254,19 @@ async def Command_CheckGraph(): # Save image and send - any existing plot will be overwritten plt.savefig(CheckPlotLocation, bbox_inches="tight") - await MainChannel.send(file=discord.File(CheckPlotLocation)) + await message.reply(file=discord.File(CheckPlotLocation)) except Exception as e: WriteToErrorLog("Command_CheckGraph", "Error in check graph command: " + str(e)) print(e) await DebugChannel.send("ERROR IN CHECKGRAPH <@"+DiscordAlertUserID+">") -async def Command_ILoveYou(message): - await message.channel.send("Thank you. You make a difference in this world. :)") +async def Command_ILoveYou(message: discord.Message) -> None: + await message.reply("Thank you. You make a difference in this world. :)") -async def Command_Hello(message): - await message.channel.send('Hello!') +async def Command_Hello(message: discord.Message) -> None: + await message.reply('Hello!') -async def Command_ArchInfo(message): +async def Command_ArchInfo(message: discord.Message) -> None: DebugMode = os.getenv('DebugMode') if(DebugMode == "true"): print("===ENV_VARIABLES===") @@ -1300,7 +1308,7 @@ async def Command_ArchInfo(message): print(ArchRoomData) print("") else: - await message.channel.send("Debug Mode is disabled.") + await message.reply("Debug Mode is disabled.") ## HELPER FUNCTIONS def ConfirmSpecialFiles(): @@ -1563,8 +1571,8 @@ def ConfirmDataLocations(): global ArchDataDirectory global ArchInfo global OutputFileLocation - global ErrorFileLocation - global DeathFileLocation + global ErrorFileLocation + global DeathFileLocation global DeathTimecodeLocation global DeathPlotLocation global CheckPlotLocation