From 8d3fe05698d180b5bb20db04a3f331ec3f3e4a60 Mon Sep 17 00:00:00 2001 From: blackfur <64478051+theblackfurguy@users.noreply.github.com> Date: Tue, 19 Jan 2021 19:57:54 +0100 Subject: [PATCH] Added Main Message to Response handler --- run.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/run.py b/run.py index 6f4ed0a..2c6681d 100644 --- a/run.py +++ b/run.py @@ -22,6 +22,13 @@ def printversion(): print("Somer Version") +def remove_mention(m, s, i): + if m == "s": + return s[0:i] + s[i+21:] + elif m == "l": + return s[:i] + s[i+22:] + + async def download(): await bot.change_presence(activity=discord.Game(name=" downloading Message History")) os.system("rm chatlogs/*.tmp.yml") @@ -83,4 +90,26 @@ async def on_ready(): else: chatbot = ChatBot(config["botname"]) + +@bot.event +async def on_message(message): + if message.author != bot.user: + if message.channel.id in config["usechannels"]: + if message.content.startswith(config["exclutionprefix"]): + return + else: + response = chatbot.get_response(message.content) + response = response.__str__() + if config["filterpings"]: + position = response.find("<@!") + while position != -1: + response = remove_mention("l", response, position) + position = response.find("<@!") + position = response.find("<@") + while position != -1: + response = remove_mention("s", response, position) + position = response.find("<@") + await message.channel.send(response) + print(f"Input was given: '{message.content}', this output was found: '{response}'") + bot.run(config["token"])