Improve similarity detection
All checks were successful
Build and Publish college-bot-v2 / build_and_publish (push) Successful in 2m1s

This commit is contained in:
Nexus 2024-06-07 20:44:06 +01:00
parent 8f5a9d741a
commit 08f167e294
Signed by: nex
GPG key ID: 0FA334385D0B689F
3 changed files with 21 additions and 3 deletions

View file

@ -1,3 +1,4 @@
jishaku~=2.5
wheel>=0.42
setuptools>=69
yt-dlp @ https://github.com/yt-dlp/yt-dlp/archive/master.tar.gz

View file

@ -1116,6 +1116,7 @@ class Ollama(commands.Cog):
await msg.edit(embed=embed)
last_edit = time.time()
similar = {}
for truth in truths:
_ratio = fuzz.ratio(truth.content, embed.description)
if truth.content == embed.description:
@ -1124,10 +1125,26 @@ class Ollama(commands.Cog):
value="This truth was already truthed. Shit AI."
)
elif _ratio >= 70:
similar[truth.id] = _ratio
if similar:
if len(similar) > 1:
lns = []
for truth_id, _ratio in similar.items():
lns.append(f"* `{truth_id}`: {_ratio:.2f}%")
embed.add_field(
name="Likely repeated truth",
value=f"Is a {_ratio:.2f}% match to truth {truth.id!r}."
name="Possibly repeated truth",
value="This truth was similar to the following existing ones:\n" + "\n".join(lns),
inline=False
)
else:
truth_id = tuple(similar)[0]
_ratio = similar[truth_id]
embed.add_field(
name="Possibly repeated truth",
value=f"This truth was {_ratio:.2f}% similar to `{truth_id}`."
)
embed.set_footer(
text="Finished generating truth based off of {:,} messages, using server {!r} | {!s}".format(
len(messages) - 2,

View file

@ -162,7 +162,7 @@ bot = Client(
intents=discord.Intents.all(),
)
for module in CONFIG["jimmy"].get("modules", ["cogs/*.py"]):
for module in ["jishaku", *CONFIG["jimmy"].get("modules", ["cogs/*.py"])]:
try:
bot.load_extension(module)
except (discord.ExtensionNotFound, ModuleNotFoundError):