From 32bf25889553e91663c08622ce4f3b7c913255ee Mon Sep 17 00:00:00 2001 From: TheScriptPony Date: Fri, 4 Dec 2020 23:27:50 -0500 Subject: [PATCH] added bify Co-authored-by: Sydney --- memeify/__init__.py | 5 ++++ memeify/info.json | 9 +++++++ memeify/memeify.py | 60 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 memeify/__init__.py create mode 100644 memeify/info.json create mode 100644 memeify/memeify.py diff --git a/memeify/__init__.py b/memeify/__init__.py new file mode 100644 index 0000000..e4c02e7 --- /dev/null +++ b/memeify/__init__.py @@ -0,0 +1,5 @@ +from .memeify import Memeify + + +def setup(bot): + bot.add_cog(Memeify(bot)) diff --git a/memeify/info.json b/memeify/info.json new file mode 100644 index 0000000..211ecc2 --- /dev/null +++ b/memeify/info.json @@ -0,0 +1,9 @@ +{ + "author": [ + "TheScriptPony" + ], + "description": "Meakes things memey.", + "install_msg": "( ͡° ͜ʖ ͡°)", + "hidden": false, + "end_user_data_statement": "This cog does not store user data." +} \ No newline at end of file diff --git a/memeify/memeify.py b/memeify/memeify.py new file mode 100644 index 0000000..a705d4c --- /dev/null +++ b/memeify/memeify.py @@ -0,0 +1,60 @@ +from redbot.core import Config, commands +import re + + +class Memeify(commands.Cog): + """Makes things memey.""" + + def __init__(self, bot): + super().__init__() + + self.config = Config.get_conf(self, identifier=2934875294) + self.bot = bot + + @commands.command() + async def b(self, ctx, *, content: str = None): + """Replaces all B's with :b:'s""" + if not content: + # gets above message + msg = (await ctx.channel.history(limit=2).flatten())[1].clean_content + if msg: + await ctx.send(self.__bify(msg, False)) + else: + await ctx.send("Where's the :b:essage?") + else: + await ctx.send(self.__bify(ctx.message.clean_content, True)) + + # takes a clean discord message and replaces all B's and + # first characters with :b:, unless the word is 1 + # character long, a custon emoji, or a ping. unicode + # emojis are a bit fucked tho + def __bify(self, bify_str, cmd) -> str: + mention = re.compile("^@|^#|^&") + bify = bify_str.split() + # remove first letter if it bifys the command message itself + if cmd: + bify.pop(0) + b = [] + for i in bify: + # no code blocks >:( + i = i.replace("`", "") + # special cases for custom emojis and mentions + if i[0] == ":" and i[-1] == ":": + b.append(i + " ") + continue + elif mention.match(i): + b.append(i[0] + self.__bify_f(i[1:]) + " ") + continue + # adds the result to the list + b.append(self.__bify_f(i) + " ") + return "".join(b) + + def __bify_f(self, bif) -> str: + vowel = re.compile("^[aeiouAEIOU]") + if vowel.match(bif) and len(bif) > 1: + # adds b in front of the word + bif = "b" + bif + elif len(bif) > 1: + # replaces first letter with b + bif = "b" + bif[1:] + return bif.replace("b", ":b:")