From 898dae5e6f24fac65717e986ec6b8989184c99e2 Mon Sep 17 00:00:00 2001 From: aikaterna <20862007+aikaterna@users.noreply.github.com> Date: Fri, 6 Dec 2019 12:52:25 -0800 Subject: [PATCH] [NoFlippedTables] Initial commit --- README.md | 2 + noflippedtables/__init__.py | 5 ++ noflippedtables/info.json | 9 +++ noflippedtables/noflippedtables.py | 114 +++++++++++++++++++++++++++++ 4 files changed, 130 insertions(+) create mode 100644 noflippedtables/__init__.py create mode 100644 noflippedtables/info.json create mode 100644 noflippedtables/noflippedtables.py diff --git a/README.md b/README.md index 0b7d5db..bd0a8d6 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,8 @@ inspirobot - Fetch "inspirational" messages from inspirobot.me with [p]inspireme leveler - A v3 port of Stevy's v2 leveler, originally by Fixator and modified by me. Add the repo at: https://github.com/aikaterna/Fixator10-Cogs +noflippedtables - A v3 port of irdumb's v2 cog with a little extra surprise included. Unflip all the tables. + nolinks - A very blunt hammer to remove anything that looks like a link. Roles can be whitelisted and it can watch multiple channels. otherbot - Alert a role when bot(s) go offline. diff --git a/noflippedtables/__init__.py b/noflippedtables/__init__.py new file mode 100644 index 0000000..bf8963f --- /dev/null +++ b/noflippedtables/__init__.py @@ -0,0 +1,5 @@ +from .noflippedtables import NoFlippedTables + + +def setup(bot): + bot.add_cog(NoFlippedTables(bot)) diff --git a/noflippedtables/info.json b/noflippedtables/info.json new file mode 100644 index 0000000..37195e3 --- /dev/null +++ b/noflippedtables/info.json @@ -0,0 +1,9 @@ +{ + "name" : "NoFlippedTables", + "author" : ["irdumb", "aikaterna"], + "short" : "Unflip some tables.", + "description" : "Unflip all the flipped tables.", + "install_msg" : "Usage: [p]help tableset", + "tags" : ["noflippedtables", "no flip", "tables"], + "disabled" : false +} \ No newline at end of file diff --git a/noflippedtables/noflippedtables.py b/noflippedtables/noflippedtables.py new file mode 100644 index 0000000..554edf0 --- /dev/null +++ b/noflippedtables/noflippedtables.py @@ -0,0 +1,114 @@ +import asyncio +from random import uniform as randfloat +import re +from redbot.core import commands, checks, Config +from redbot.core.utils.chat_formatting import box + +class NoFlippedTables(commands.Cog): + """For the table sympathizers""" + + def __init__(self, bot): + self.bot = bot + self.config = Config.get_conf(self, 2712290002, force_registration=True) + + default_guild = { + "ALL_TABLES": True, + "BOT_EXEMPT": False, + "SNACKBEAR": False, + } + + self.config.register_guild(**default_guild) + + self.flippedTables = {} + + @checks.mod_or_permissions(manage_guild=True) + @commands.group() + async def tableset(self, ctx): + """Got some nice settings for my UNflipped tables""" + if ctx.invoked_subcommand is None: + settings = await self.config.guild(ctx.guild).all() + msg = "[Current Settings]\n" + for k, v in settings.items(): + msg += str(k) + ": " + str(v) + "\n" + await ctx.send(box(msg, lang="ini")) + + @tableset.command() + async def flipall(self, ctx): + """Enables/disables right all unflipped tables in a message""" + settings = await self.config.guild(ctx.guild).ALL_TABLES() + await self.config.guild(ctx.guild).ALL_TABLES.set(not settings) + if not settings: + await ctx.send("All tables will now be unflipped.") + else: + await ctx.send("Now only one table unflipped per message.") + + @tableset.command() + async def flipbot(self, ctx): + """Enables/disables allowing bot to flip tables""" + settings = await self.config.guild(ctx.guild).BOT_EXEMPT() + await self.config.guild(ctx.guild).BOT_EXEMPT.set(not settings) + if not settings: + await ctx.send("Bot is now allowed to leave its own tables flipped.") + else: + await ctx.send("Bot must now unflip tables that itself flips.") + + @tableset.command() + async def snackbear(self, ctx): + """Snackbear is unflipping tables!""" + settings = await self.config.guild(ctx.guild).SNACKBEAR() + await self.config.guild(ctx.guild).SNACKBEAR.set(not settings) + if not settings: + await ctx.send("Snackbear will now unflip tables.") + else: + await ctx.send("Snackbear is heading off for his errands!") + + @commands.Cog.listener() + #so much fluff just for this OpieOP + async def on_message(self, message): + channel = message.channel + user = message.author + if hasattr(user, 'bot') and user.bot is True: + return + if channel.id not in self.flippedTables: + self.flippedTables[channel.id] = {} + #┬─┬ ┬┬ ┻┻ ┻━┻ ┬───┬ ┻━┻ will leave 3 tables left flipped + #count flipped tables + for m in re.finditer('┻━*┻|┬─*┬', message.content): + t = m.group() + bot_exempt = await self.config.guild(message.guild).BOT_EXEMPT() + if '┻' in t and not (message.author.id == self.bot.user.id and bot_exempt): + if t in self.flippedTables[channel.id]: + self.flippedTables[channel.id][t] += 1 + else: + self.flippedTables[channel.id][t] = 1 + all_tables = await self.config.guild(message.guild).ALL_TABLES() + if not all_tables: + break + else: + f = t.replace('┬','┻').replace('─','━') + if f in self.flippedTables[channel.id]: + if self.flippedTables[channel.id][f] <= 0: + del self.flippedTables[channel.id][f] + else: + self.flippedTables[channel.id][f] -= 1 + #wait random time. some tables may be unflipped by now. + await asyncio.sleep(randfloat(0,1.5)) + tables = "" + + deleteTables = [] + #unflip tables in self.flippedTables[channel.id] + for t, n in self.flippedTables[channel.id].items(): + snackburr = await self.config.guild(message.guild).SNACKBEAR() + if snackburr: + unflipped = t.replace('┻','┬').replace('━','─') + " ノʕ •ᴥ•ノʔ" + "\n" + else: + unflipped = t.replace('┻','┬').replace('━','─') + " ノ( ゜-゜ノ)" + "\n" + for i in range(0,n): + tables += unflipped + #in case being processed in parallel + self.flippedTables[channel.id][t] -= 1 + deleteTables.append(t) + for t in deleteTables: + del self.flippedTables[channel.id][t] + if tables != "": + await channel.send(tables)