From 3eb3548d261b186eefd7e9a8c9e01b0ee24480e7 Mon Sep 17 00:00:00 2001 From: Paillat Date: Sun, 27 Nov 2022 16:09:49 +0100 Subject: [PATCH 1/4] . --- database/{data.db => old database.db} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename database/{data.db => old database.db} (100%) diff --git a/database/data.db b/database/old database.db similarity index 100% rename from database/data.db rename to database/old database.db From 299428589811360d5506f731eb7d0e21ef041d21 Mon Sep 17 00:00:00 2001 From: Liam Kern Date: Wed, 7 Dec 2022 14:30:01 +0100 Subject: [PATCH 2/4] change history for replies --- code/code.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/code/code.py b/code/code.py index d824ea5..41ed965 100644 --- a/code/code.py +++ b/code/code.py @@ -6,7 +6,6 @@ import logging # pip install logging import sqlite3 # pip install sqlite3 import asyncio # pip install asyncio import os # pip install os -import random # pip install random import re # pip install re import datetime # pip install datetime #set the debug mode to the maximum @@ -278,7 +277,7 @@ async def pretend(ctx, pretend_to_be: str): c.execute("UPDATE data SET pretend_to_be = ? WHERE guild_id = ?", (pretend_to_be, ctx.guild.id)) conn.commit() @bot.event -async def on_message(message): +async def on_message(message: discord.Message): #check if the message is from a bot if message.author.bot: return @@ -292,9 +291,12 @@ async def on_message(message): return #check if the message has been sent in the channel set in the database c.execute("SELECT channel_id FROM data WHERE guild_id = ?", (message.guild.id,)) + try : replied_message: discord.Message = await message.to_reference() + except : replied_message = None if str(message.channel.id) != str(c.fetchone()[0]): - if message.content.find("<@1046051875755134996>") != -1: - debug("wrong channel, but mention") + #check if the message is a mention or if the message replies to the bot + if message.content.find("<@1046051875755134996>") != -1 or replied_message != None: + debug("wrong channel, but mention or reply") else : debug("The message has been sent in the wrong channel") return @@ -315,8 +317,14 @@ async def on_message(message): #get the advanced settings from the database c.execute("SELECT max_tokens, temperature, frequency_penalty, presence_penalty, prompt_size FROM data WHERE guild_id = ?", (message.guild.id,)) max_tokens, temperature, frequency_penalty, presence_penalty, prompt_size = c.fetchone() - messages = await message.channel.history(limit=prompt_size).flatten() - messages.reverse() + if replied_message == None: + messages = await message.channel.history(limit=prompt_size).flatten() + messages.reverse() + else : + messages = await message.channel.history(limit=prompt_size, before=replied_message.created_at).flatten() + messages.reverse() + messages.append(replied_message) + messages.append(message) prompt = "" #get the channel id from the database c.execute("SELECT channel_id FROM data WHERE guild_id = ?", (message.guild.id,)) From 5296f28ad22a1ac78a7bfdec1c23e07458cd361b Mon Sep 17 00:00:00 2001 From: Liam Kern Date: Wed, 7 Dec 2022 20:51:18 +0100 Subject: [PATCH 3/4] fix replies --- code/code.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/code/code.py b/code/code.py index 41ed965..35a23ce 100644 --- a/code/code.py +++ b/code/code.py @@ -293,6 +293,9 @@ async def on_message(message: discord.Message): c.execute("SELECT channel_id FROM data WHERE guild_id = ?", (message.guild.id,)) try : replied_message: discord.Message = await message.to_reference() except : replied_message = None + else : + if replied_message.author.id != bot.user.id: + replied_message = None if str(message.channel.id) != str(c.fetchone()[0]): #check if the message is a mention or if the message replies to the bot if message.content.find("<@1046051875755134996>") != -1 or replied_message != None: From 7b2029a40cea658770d5b05d0dd2ec4fc86636df Mon Sep 17 00:00:00 2001 From: Paillat Date: Thu, 8 Dec 2022 12:37:21 +0100 Subject: [PATCH 4/4] Update code.py --- code/code.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/code/code.py b/code/code.py index 35a23ce..3eb48aa 100644 --- a/code/code.py +++ b/code/code.py @@ -291,15 +291,16 @@ async def on_message(message: discord.Message): return #check if the message has been sent in the channel set in the database c.execute("SELECT channel_id FROM data WHERE guild_id = ?", (message.guild.id,)) - try : replied_message: discord.Message = await message.to_reference() - except : replied_message = None - else : - if replied_message.author.id != bot.user.id: - replied_message = None + try : original_message = await message.channel.fetch_message(message.reference.message_id) + except : original_message = None + if original_message != None and original_message.author.id != bot.user.id: + original_message = None if str(message.channel.id) != str(c.fetchone()[0]): #check if the message is a mention or if the message replies to the bot - if message.content.find("<@1046051875755134996>") != -1 or replied_message != None: - debug("wrong channel, but mention or reply") + if original_message != None: + debug("wrong channel, but reply") + elif message.content.find("<@"+str(bot.user.id)+">") != -1: + debug("wrong channel, but mention") else : debug("The message has been sent in the wrong channel") return @@ -320,13 +321,13 @@ async def on_message(message: discord.Message): #get the advanced settings from the database c.execute("SELECT max_tokens, temperature, frequency_penalty, presence_penalty, prompt_size FROM data WHERE guild_id = ?", (message.guild.id,)) max_tokens, temperature, frequency_penalty, presence_penalty, prompt_size = c.fetchone() - if replied_message == None: + if original_message == None: messages = await message.channel.history(limit=prompt_size).flatten() messages.reverse() else : - messages = await message.channel.history(limit=prompt_size, before=replied_message.created_at).flatten() + messages = await message.channel.history(limit=prompt_size, before=original_message).flatten() messages.reverse() - messages.append(replied_message) + messages.append(original_message) messages.append(message) prompt = "" #get the channel id from the database @@ -528,4 +529,5 @@ bot.loop.create_task(check_day_task()) # Replace the following with your bot's token with open("key.txt") as f: key = f.read() -bot.run(key) + +bot.run(key) \ No newline at end of file