diff --git a/bot/__main__.py b/bot/__main__.py index d862b77..d6bacbc 100644 --- a/bot/__main__.py +++ b/bot/__main__.py @@ -19,6 +19,7 @@ from bot.cogs.theinherentlyindescribablenatureoftheuniverse import Theinherentlyindescribablenatureoftheuniverse # noqa E501 from bot.cogs.tiles import Tiles from bot.cogs.wiki import Wiki +from bot.cogs.orb import Orb from bot.shared import config @@ -76,6 +77,7 @@ async def on_command_error(ctx, error): bot.add_cog(Theinherentlyindescribablenatureoftheuniverse(bot)) bot.add_cog(Tiles(bot)) bot.add_cog(Wiki(bot)) + bot.add_cog(Orb(bot)) bot.run(config['Discord token']) diff --git a/bot/cogs/orb.py b/bot/cogs/orb.py new file mode 100644 index 0000000..dfc749a --- /dev/null +++ b/bot/cogs/orb.py @@ -0,0 +1,97 @@ +import logging +import re +import random +import asyncio + +import discord +from discord.ext.commands import Cog, Bot +from discord.message import Message +from bot.shared import config +from discord import DeletedReferencedMessage + + +log = logging.getLogger('bot.' + __name__) + +orb_command = re.compile(r"(^\w?\^\w?orb)", re.IGNORECASE) +orbs = [ + '๐Ÿ”ด', + '๐ŸŸ ', + '๐ŸŸก', + '๐ŸŸข', + '๐Ÿ”ต', + '๐ŸŸฃ', + '๐ŸŸค', + 'โšซ', + 'โšช', + '๐ŸŒ•', + '๐Ÿชฉ', + '๐Ÿซง', + '๐Ÿ”ฎ', + '๐ŸŽฑ', + '<:orb:1357170327657906307>', + '<:baetyl:957116466673618994>' +] +strange_orbs = [ + '๐ŸฅŽ', + 'โšฝ', + '๐Ÿ€', + '๐Ÿง‹', + '๐Ÿงถ', + '๐Ÿช€', + '๐Ÿ’ฟ' +] +confirm_text = ["Launching orbs!", + "Initiating orb strategy mode.", + "With the power of every server member!", + "Orbs."] + + +class Orb(Cog): + """Initiate Orb Strategy. + + Usage: Reply to a message with '^orb this fool' + other usages: + ^orbify + ^orb this delver, ex.""" + def __init__(self, bot: Bot): + self.bot = bot + self.config = config['Orb'] + + @Cog.listener() + async def on_message(self, msg: Message): + if msg.author.id in self.config['ignore'] or msg.author == self.bot.user: + return # ignore ignored users and bots + if msg.reference is None: + return + if not orb_command.match(msg.content): + return + # Grab only replies. Or at least, as best it can with this + # version of discord.py. + msg_ref = msg.reference + if (not msg_ref.resolved or + type(msg_ref.resolved) is DeletedReferencedMessage): + + log.info(f'({msg.channel}) <{msg.author}> tried to orb someone but was unsuccessful.') + msg.channel.send( + "I couldn't see the msg you replied to, sorry.") + if msg_ref.message_id: + # Grab message the reply was for. + replied_msg = await msg.channel.fetch_message(msg_ref.message_id) + if replied_msg.author.id == msg.author.id: + # You can't orb yourself + return # change to pass for lonely testers + log.info(f'({msg.channel}) <{msg.author}> orbed {replied_msg.author}') + # Shuffle order of orb, and add in a few Strange Orb + random_orbs = random.sample(orbs, k=16) + for strange_orb in random.sample(strange_orbs, + k=random.randrange(1, 3)): + random_orbs.insert(random.randrange(0, len(random_orbs)), + strange_orb) + # Orb this fool! + msg.channel.send(confirm_text[random.randrange(0, 4)]) + for orb in random_orbs: + try: + await replied_msg.add_reaction(orb) + except discord.errors.HTTPException as e: + print(f"Error when trying to grab emoji {orb}:{e.text}") + await asyncio.sleep(0.5) diff --git a/config.example.yml b/config.example.yml index 7560484..fc7798a 100644 --- a/config.example.yml +++ b/config.example.yml @@ -6,22 +6,23 @@ Log folder: logs # Game installation to read from: Qud install folder: C:\Steam\steamapps\common\Caves of Qud - ############################# # Configs for individual cogs ############################# Bugs: - channels: [ # Channels to listen for bug reacts in: - 449667247297003520, # #bugs - 459482205635215360, # #beta-bugs - 449312747683971072, # #modding - ] - allowed roles: [ # Roles that can open a new issue via react: - 443578758629425152, # Sultan - 447173558330982400, # Mayor - 579024675598761995, # Tinker - 707378307649241210, # Bug Herder - ] + channels: # Channels to listen for bug reacts in: + [ + 449667247297003520, # #bugs + 459482205635215360, # #beta-bugs + 449312747683971072, # #modding + ] + allowed roles: # Roles that can open a new issue via react: + [ + 443578758629425152, # Sultan + 447173558330982400, # Mayor + 579024675598761995, # Tinker + 707378307649241210, # Bug Herder + ] trigger: ๐Ÿ› success reaction: โ˜‘ fail reaction: โš ๏ธ @@ -31,16 +32,18 @@ Bugs: bot password: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Decode: - channels: [ # Channels to listen for character build codes in: - 449342897788026882, # #character-builds - 571405896597635073, # #build-club - 716755952967352420, # #bot-spam - 482714670860468234, # #trash-divining - ] + channels: # Channels to listen for character build codes in: + [ + 449342897788026882, # #character-builds + 571405896597635073, # #build-club + 716755952967352420, # #bot-spam + 482714670860468234, # #trash-divining + ] # ignoring bots should be redundant, but specify anyway - ignore: [ # Users to ignore: - 502293569764327444, # Cryptogull - ] + ignore: # Users to ignore: + [ + 502293569764327444, # Cryptogull + ] Reddit: client ID: xxxxxxxxxxxxxx @@ -61,3 +64,8 @@ Wiki: site: wiki.cavesofqud.com basic search limit: 10 fulltext search limit: 5 + +Orb: + ignore: [ + 502293569764327444, # Cryptogull + ]