Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat(abbrev): add abbreviationExplainer plugin #215

Draft
wants to merge 2 commits into
base: beta
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions plugins/abbreviationExplainer/abbreviationExplainer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
"""
Ce programme est régi par la licence CeCILL soumise au droit français et
respectant les principes de diffusion des logiciels libres. Vous pouvez
utiliser, modifier et/ou redistribuer ce programme sous les conditions
de la licence CeCILL diffusée sur le site "http://www.cecill.info".
"""

import discord
from discord.ext import commands

from utils import Gunibot, MyContext
# pylint: disable=relative-beyond-top-level
from .abbreviations import abbreviations


async def setup(bot: Gunibot = None):
await bot.add_cog(Abbrev(bot))


class Abbrev(commands.Cog):
def __init__(self, bot: Gunibot):
self.bot = bot
self.file = "abbreviationExplainer"
self.cache = {}

self.bot.get_command("config").add_command(self.config_enable_abbreviation_explainer)

@commands.command(name="enable_abbreviation_explainer")
async def config_enable_abbreviation_explainer(self, ctx: MyContext, value: bool):
"""Enable or disable the XP system in your server"""
await ctx.send(
await self.bot.sconfig.edit_config(ctx.guild.id, "enable_abbreviation_explainer", value)
)


@commands.Cog.listener()
async def on_message(self, message: discord.Message):
# check if server has enabled the abbreviation explainer
if not self.bot.server_configs[message.guild.id].get("enable_abbreviation_explainer", False):
return

# check if message is not from a bot
if message.author.bot:
return

# retrieve a list of all abbreviations in the message
words = message.content.split()
abbreviations_lang = abbreviations.keys()
abbreviations_in_message = {lang: [] for lang in abbreviations_lang}
for word in words:
for lang in abbreviations_lang:
if word.lower() in abbreviations[lang]:
abbreviations_in_message[lang].append(word.lower())

# don't do anything if there are no abbreviations in the message
if not any(abbreviations_in_message.values()):
return

buttons = discord.ui.View()
for lang in abbreviations_in_message:
for word in abbreviations_in_message[lang]:
label = f"{word} : {abbreviations[lang][word]}"
buttons.add_item(discord.ui.Button(label=label, style=discord.ButtonStyle.blurple, disabled=True))

# create a webhook to send the message
webhook = await message.channel.create_webhook(name="Abbreviation Explainer")

# if the message is a reply, create a reply embed
embed = None
if message.reference:
reference = await message.channel.fetch_message(message.reference.message_id)
embed = discord.Embed(
description=await self.bot._(
message.guild.id,
"wormhole.reply_to",
link=reference.jump_url,
),
colour=0x2F3136, # 2F3136
).set_footer(
text=reference.content, icon_url=reference.author.display_avatar
)

# resend the message with the abbreviations explained
await webhook.send(
message.content,
username=message.author.display_name,
avatar_url=message.author.avatar.url if message.author.avatar else None,
view=buttons,
wait=True,
embed=embed
)

# delete the original message
await message.delete()

# delete the webhook
await webhook.delete()

84 changes: 84 additions & 0 deletions plugins/abbreviationExplainer/abbreviations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
abbreviations = {
"en": {
"lol": "laughing out loud",
"brb": "be right back",
"omg": "oh my god",
"btw": "by the way",
"idk": "I don't know",
"gtg": "got to go",
"fyi": "for your information",
"wtf": "what the fuck",
"afk": "away from keyboard",
"bff": "best friends forever",
"imho": "in my humble opinion",
"irl": "in real life",
"rofl": "rolling on the floor laughing",
"thx": "thanks",
"ttyl": "talk to you later",
"omw": "on my way",
"wb": "welcome back",
"ty": "thank you",
"yolo": "you only live once",
"imo": "in my opinion",
"jk": "just kidding",
"idc": "I don't care",
"smh": "shaking my head",
"tbh": "to be honest",
"lmk": "let me know",
"gr8": "great",
"rn": "right now",
"pls": "please",
"tho": "though",
"gg": "good game",
"afaik": "as far as I know",
"bfn": "bye for now",
"dw": "don't worry",
"fomo": "fear of missing out",
"hmu": "hit me up",
"icymi": "in case you missed it",
"jic": "just in case",
"lmao": "laughing my ass off",
"np": "no problem",
"nvm": "never mind",
"oml": "oh my lord",
"pov": "point of view",
"smdh": "shaking my damn head",
"tbt": "throwback Thursday",
"tgif": "thank god it's Friday",
"til": "today I learned",
"tmi": "too much information",
"wbu": "what about you",
"wth": "what the hell",
"yw": "you're welcome"
},
"fr": {
"bjr": "bonjour",
"slt": "salut",
"mdr": "mort de rire",
"cc": "coucou",
"svp": "s'il vous plaît",
"mercii": "merci",
"stp": "s'il te plaît",
"bcp": "beaucoup",
"tg": "ta gueule",
"pk": "pourquoi",
"psq": "parce que",
"dsl": "désolé",
"bsr": "bonsoir",
"ok": "d'accord",
"rdv": "rendez-vous",
"aprem": "après-midi",
"a+": "à plus",
"koi": "quoi",
"jtm": "je t'aime",
"stv": "ça va",
"bsx": "bisous",
"pkoi": "pourquoi",
"pkpas": "pourquoi pas",
"ptdr": "pété de rire",
"wsh": "qu'est-ce qu'il se passe",
"jpp": "j'en peux plus",
"bis": "bises",
"tkt": "t'inquiète"
}
}
7 changes: 7 additions & 0 deletions plugins/abbreviationExplainer/config/options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"enable_abbreviation_explainer": {
"default": false,
"type": "boolean",
"command": "enable_abbreviation_explainer"
}
}
9 changes: 9 additions & 0 deletions plugins/abbreviationExplainer/credits.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Copyright © ZRunner 2021
Copyright © Leirof 2021 - 2022
Copyright © Aeris One 2022
Copyright © ascpial 2023

Ce programme est régi par la licence CeCILL soumise au droit français et
respectant les principes de diffusion des logiciels libres. Vous pouvez
utiliser, modifier et/ou redistribuer ce programme sous les conditions
de la licence CeCILL diffusée sur le site "http://www.cecill.info".