From 2d9d30f4f7d5a37c7a0840dd0ae2a7bb00011f8d Mon Sep 17 00:00:00 2001 From: xenofem Date: Fri, 25 Mar 2022 17:37:39 -0400 Subject: [PATCH] screw around with descent some more --- bot.py | 80 ++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 33 deletions(-) diff --git a/bot.py b/bot.py index fb6703f..004a83b 100644 --- a/bot.py +++ b/bot.py @@ -8,10 +8,22 @@ import discord STATE_FILE = 'state.json' CHANNEL_NAME = 'therapy-elevator' DELETION_SECONDS = 300 +TYPING_DELAY = 2 SETUP_MESSAGE = 'Welcome to Nemuro Memorial Hall. Please give your name and class year for our records.' INITIAL_MESSAGE = 'All right, please begin.' -BUTTERFLIES = ['🦋', '🥐', 'Deeper. Go deeper.', '🐛', '🍃'] +BUTTERFLIES = ['🦋', 'Deeper. Go deeper.', '🥐', '🐛', '🥚', '🍃'] +ELEVATOR_SHIT_PERIOD = 7 +ELEVATOR_SHIT = [ + '*the elevator creaks eerily*', + '*menacing discordant music plays*', + '*drawers rush past on the walls outside*', + '*the lights flicker*', + '*the elevator jolts, then continues its descent*', + '*a rattling. the elevator begins to shake*' + '*a squealing of cables and pulleys*' +] +CRASH = '***the elevator crashes to the bottom***' FINAL_MESSAGE = 'I understand. Your only choice is to revolutionize the world. The path you must take has been prepared for you.' ROSE = '🌹' @@ -21,6 +33,13 @@ async def try_send(channel, message): except discord.DiscordException as e: print(f"error sending message in channel {channel}: {e}", file=sys.stderr) +async def try_move(channel, **kwargs): + try: + await channel.move(**kwargs) + except discord.DiscordException as e: + print(f"error moving channel {channel}: {e}", file=sys.stderr) + await try_send(message.channel, "Dammit, the elevator's stuck!") + def text_only(channels): return [channel for channel in channels if isinstance(channel, discord.TextChannel)] @@ -76,41 +95,36 @@ class MikageClient(discord.Client): channels = text_only(channels) channel_index = channels.index(message.channel) - if channel_index == len(channels) - 1: - if category_index == len(categories) - 1: - return - target_category = categories[category_index+1][0] - target_position = 0 - else: - target_category = category - target_position = channel_index+1 - try: - await message.channel.move(category=target_category, beginning=True, offset=target_position) - except discord.DiscordException as e: - print(f"error moving channel {message.channel} in guild {message.guild}: {e}", file=sys.stderr) - await try_send(message.channel, "Dammit, the elevator's stuck!") - return - - final_category_channels = text_only(message.guild.by_category()[-1][1]) - if len(final_category_channels) > 0 and message.channel == final_category_channels[-1]: - await try_send(message.channel, FINAL_MESSAGE) - await try_send(message.channel, ROSE) - await asyncio.sleep(DELETION_SECONDS) - try: - await message.channel.delete() - del self.state[guild_id] - self.save_state() - except discord.DiscordException as e: - print(f"error deleting elevator for guild {message.guild}: {e}", file=sys.stderr) - return - await self.initialize_elevator(message.guild) - return - if category_index == 0 and channel_index == 0: await try_send(message.channel, INITIAL_MESSAGE) - if target_position == 0: - await try_send(message.channel, random.choice(BUTTERFLIES)) + if category_index == len(categories) - 1: + return + if channel_index == len(channels) - 1: + if category_index == len(categories) - 2: + await message.channel.move(category=categories[-1][0], end=True) + await try_send(message.channel, CRASH) + await asyncio.sleep(TYPING_DELAY) + await try_send(message.channel, FINAL_MESSAGE) + await asyncio.sleep(TYPING_DELAY) + await try_send(message.channel, ROSE) + await asyncio.sleep(DELETION_SECONDS) + try: + await message.channel.delete() + del self.state[guild_id] + self.save_state() + except discord.DiscordException as e: + print(f"error deleting elevator for guild {message.guild}: {e}", file=sys.stderr) + return + await self.initialize_elevator(message.guild) + return + else: + await try_move(message.channel, category=categories[category_index+1][0], beginning=True) + await try_send(message.channel, BUTTERFLIES[int(category_index*len(BUTTERFLIES)/(len(categories)-2))]) + else: + await try_move(message.channel, category=category, beginning=True, offset=channel_index+1) + if random.randrange(ELEVATOR_SHIT_PERIOD) == 0: + await try_send(message.channel, random.choice(ELEVATOR_SHIT)) client = MikageClient() with open('token', encoding='utf-8') as f: