From e14e92c27bc2d4613e5a0c8c9f85777a4e5bdb47 Mon Sep 17 00:00:00 2001 From: Wreckstation <53310247+Wreckstation@users.noreply.github.com> Date: Sat, 12 Apr 2025 15:23:06 -0400 Subject: [PATCH 1/5] Fix #67 Add additional test for recoloring generated tiles. --- bot/helpers/tiles.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bot/helpers/tiles.py b/bot/helpers/tiles.py index d9f662e..78ebd04 100644 --- a/bot/helpers/tiles.py +++ b/bot/helpers/tiles.py @@ -8,7 +8,7 @@ from hagadias.constants import QUD_COLORS from hagadias.qudtile import QudTile -from hagadias.tileanimator import TileAnimator, GifHelper +from hagadias.tileanimator import TileAnimator, GifHelper, StandInTiles from bot.helpers.find_blueprints import find_name_or_displayname, fuzzy_find_nearest from bot.helpers.tile_variations import parse_variation_parameters, get_tile_variation_details @@ -100,8 +100,9 @@ async def get_tile_data(*args, colorstring = tile.colorstring qudname = tile.qudname raw_transparent = tile.raw_transparent + tile_provider = StandInTiles.get_tile_provider_for(obj) tile = QudTile(filename, colorstring, colors[0], colors[1], qudname, - raw_transparent) + raw_transparent, image_provider=tile_provider) if gif_bytesio is not None: filedata = gif_bytesio elif smalltile: From 96d2511c73521339a1caf4a64b63b100bbb40433 Mon Sep 17 00:00:00 2001 From: Wreckstation <53310247+Wreckstation@users.noreply.github.com> Date: Sat, 12 Apr 2025 15:26:52 -0400 Subject: [PATCH 2/5] add test --- tests/random_tile_test.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/random_tile_test.py b/tests/random_tile_test.py index 2b18f91..23f1161 100644 --- a/tests/random_tile_test.py +++ b/tests/random_tile_test.py @@ -17,3 +17,14 @@ async def test_random_tile(): for i in range(100): name, args = get_random_tile_name() msg, filedata, filename = await get_tile_data(name, *args) + +@pytest.mark.skipif(CI, reason="Skipping due to no textures") +@pytest.mark.asyncio +async def test_random_generated_tile(): + """Calls a random recolor of an object that has its tile generated + based on its glyphs like vortexes or gasses. + + Skipped in integration tests due to textures not being present.""" + + msg, filedata, filename = await get_tile_data('GlitterGas80', *args) + msg, filedata, filename = await get_tile_data("Space-Time Anomaly", *args) \ No newline at end of file From 96bc5d79cf9548097bf5f35f292cead2d20c1f0b Mon Sep 17 00:00:00 2001 From: Wreckstation <53310247+Wreckstation@users.noreply.github.com> Date: Sat, 12 Apr 2025 19:10:51 -0400 Subject: [PATCH 3/5] Revert "add test" This reverts commit 96d2511c73521339a1caf4a64b63b100bbb40433. --- tests/random_tile_test.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/tests/random_tile_test.py b/tests/random_tile_test.py index 23f1161..2b18f91 100644 --- a/tests/random_tile_test.py +++ b/tests/random_tile_test.py @@ -17,14 +17,3 @@ async def test_random_tile(): for i in range(100): name, args = get_random_tile_name() msg, filedata, filename = await get_tile_data(name, *args) - -@pytest.mark.skipif(CI, reason="Skipping due to no textures") -@pytest.mark.asyncio -async def test_random_generated_tile(): - """Calls a random recolor of an object that has its tile generated - based on its glyphs like vortexes or gasses. - - Skipped in integration tests due to textures not being present.""" - - msg, filedata, filename = await get_tile_data('GlitterGas80', *args) - msg, filedata, filename = await get_tile_data("Space-Time Anomaly", *args) \ No newline at end of file From fe2da0df9366429dd66c970ef14f47e487fb129a Mon Sep 17 00:00:00 2001 From: Wreckstation <53310247+Wreckstation@users.noreply.github.com> Date: Sat, 12 Apr 2025 19:11:06 -0400 Subject: [PATCH 4/5] Revert "Fix #67" This reverts commit e14e92c27bc2d4613e5a0c8c9f85777a4e5bdb47. --- bot/helpers/tiles.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bot/helpers/tiles.py b/bot/helpers/tiles.py index 78ebd04..d9f662e 100644 --- a/bot/helpers/tiles.py +++ b/bot/helpers/tiles.py @@ -8,7 +8,7 @@ from hagadias.constants import QUD_COLORS from hagadias.qudtile import QudTile -from hagadias.tileanimator import TileAnimator, GifHelper, StandInTiles +from hagadias.tileanimator import TileAnimator, GifHelper from bot.helpers.find_blueprints import find_name_or_displayname, fuzzy_find_nearest from bot.helpers.tile_variations import parse_variation_parameters, get_tile_variation_details @@ -100,9 +100,8 @@ async def get_tile_data(*args, colorstring = tile.colorstring qudname = tile.qudname raw_transparent = tile.raw_transparent - tile_provider = StandInTiles.get_tile_provider_for(obj) tile = QudTile(filename, colorstring, colors[0], colors[1], qudname, - raw_transparent, image_provider=tile_provider) + raw_transparent) if gif_bytesio is not None: filedata = gif_bytesio elif smalltile: From afb75ee21bd4719e5fc1a4caab1fe35697de2b25 Mon Sep 17 00:00:00 2001 From: Wreckstation <53310247+Wreckstation@users.noreply.github.com> Date: Sat, 12 Apr 2025 19:12:50 -0400 Subject: [PATCH 5/5] Orbs --- bot/__main__.py | 2 + bot/cogs/orb.py | 97 ++++++++++++++++++++++++++++++++++++++++++++++ config.example.yml | 50 ++++++++++++++---------- 3 files changed, 128 insertions(+), 21 deletions(-) create mode 100644 bot/cogs/orb.py 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 + ]