[NoFlippedTables] Initial commit

This commit is contained in:
aikaterna
2019-12-06 12:52:25 -08:00
parent 11b7eb2e1f
commit 898dae5e6f
4 changed files with 130 additions and 0 deletions

View File

@@ -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.

View File

@@ -0,0 +1,5 @@
from .noflippedtables import NoFlippedTables
def setup(bot):
bot.add_cog(NoFlippedTables(bot))

View File

@@ -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
}

View File

@@ -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)