From f4235d824503f2a76ceddc4e1be3be373301f956 Mon Sep 17 00:00:00 2001 From: xenofem Date: Fri, 25 Mar 2022 15:49:31 -0400 Subject: [PATCH 01/13] checker fixes --- bot.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/bot.py b/bot.py index 3895324..e4fd34c 100644 --- a/bot.py +++ b/bot.py @@ -1,16 +1,16 @@ -import discord - import asyncio import json import sys +import discord + STATE_FILE = 'state.json' CHANNEL_NAME = 'therapy-elevator' DELETION_SECONDS = 300 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.', '🐛', '🍃'] FINAL_MESSAGE = 'I understand. Your only choice is to revolutionize the world. The path you must take has been prepared for you.' ROSE = '🌹' @@ -27,14 +27,14 @@ class MikageClient(discord.Client): def __init__(self): super().__init__() try: - with open(STATE_FILE) as f: + with open(STATE_FILE, encoding='utf-8') as f: self.state = json.load(f) - except: + except FileNotFoundError: self.state = {} self.save_state() def save_state(self): - with open(STATE_FILE, 'w') as f: + with open(STATE_FILE, 'w', encoding='utf-8') as f: json.dump(self.state, f) async def on_ready(self): @@ -51,7 +51,7 @@ class MikageClient(discord.Client): if guild_id in self.state and guild.get_channel(self.state[guild_id]['channel']) is not None: return try: - (top_category, channels) = guild.by_category()[0] + top_category = guild.by_category()[0][0] channel = await guild.create_text_channel(CHANNEL_NAME, category=top_category) await channel.move(category=top_category, beginning=True) self.state[guild_id] = {'channel': channel.id} @@ -111,6 +111,6 @@ class MikageClient(discord.Client): await self.initialize_elevator(message.guild) client = MikageClient() -with open('token') as f: +with open('token', encoding='utf-8') as f: token = f.read().strip() client.run(token) From 8b6da557295be4f10c627e51130bc54f89ab5969 Mon Sep 17 00:00:00 2001 From: xenofem Date: Fri, 25 Mar 2022 16:00:49 -0400 Subject: [PATCH 02/13] refactor butterflies --- bot.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/bot.py b/bot.py index e4fd34c..fb6703f 100644 --- a/bot.py +++ b/bot.py @@ -1,5 +1,6 @@ import asyncio import json +import random import sys import discord @@ -75,9 +76,6 @@ class MikageClient(discord.Client): channels = text_only(channels) channel_index = channels.index(message.channel) - if category_index == 0 and channel_index == 0: - await try_send(message.channel, INITIAL_MESSAGE) - if channel_index == len(channels) - 1: if category_index == len(categories) - 1: return @@ -93,9 +91,6 @@ class MikageClient(discord.Client): await try_send(message.channel, "Dammit, the elevator's stuck!") return - if target_position == 0: - await try_send(message.channel, BUTTERFLIES[int(category_index*len(BUTTERFLIES)/(len(categories)-1))]) - 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) @@ -109,6 +104,13 @@ class MikageClient(discord.Client): 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)) + client = MikageClient() with open('token', encoding='utf-8') as f: From 2d9d30f4f7d5a37c7a0840dd0ae2a7bb00011f8d Mon Sep 17 00:00:00 2001 From: xenofem Date: Fri, 25 Mar 2022 17:37:39 -0400 Subject: [PATCH 03/13] 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: From 5a658a107f0dad72faf9271b5f23aa0b26ee8007 Mon Sep 17 00:00:00 2001 From: xenofem Date: Fri, 25 Mar 2022 17:49:49 -0400 Subject: [PATCH 04/13] custom status --- bot.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bot.py b/bot.py index 004a83b..6d4d2b3 100644 --- a/bot.py +++ b/bot.py @@ -59,6 +59,7 @@ class MikageClient(discord.Client): async def on_ready(self): print(f"logged in as {self.user}", file=sys.stderr) + await self.change_presence(activity=discord.Game('the dueling game, for keeps')) for guild in self.guilds: await self.initialize_elevator(guild) From 9117f0dfa19848031eee9fd27080756363b9932e Mon Sep 17 00:00:00 2001 From: xenofem Date: Fri, 25 Mar 2022 17:59:53 -0400 Subject: [PATCH 05/13] tweak elevator shit period --- bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot.py b/bot.py index 6d4d2b3..07b8760 100644 --- a/bot.py +++ b/bot.py @@ -13,7 +13,7 @@ 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.', '🥐', '🐛', '🥚', '🍃'] -ELEVATOR_SHIT_PERIOD = 7 +ELEVATOR_SHIT_PERIOD = 5 ELEVATOR_SHIT = [ '*the elevator creaks eerily*', '*menacing discordant music plays*', From 7d9d6012d982726859ff1131bb77fa272fd46553 Mon Sep 17 00:00:00 2001 From: xenofem Date: Fri, 25 Mar 2022 18:10:27 -0400 Subject: [PATCH 06/13] more styling bits --- bot.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bot.py b/bot.py index 07b8760..6598545 100644 --- a/bot.py +++ b/bot.py @@ -23,7 +23,7 @@ ELEVATOR_SHIT = [ '*a rattling. the elevator begins to shake*' '*a squealing of cables and pulleys*' ] -CRASH = '***the elevator crashes to the bottom***' +CRASH = ('|\n'*10) + '***the elevator crashes to the bottom***' + ('\n'*10) + '...' FINAL_MESSAGE = 'I understand. Your only choice is to revolutionize the world. The path you must take has been prepared for you.' ROSE = '🌹' @@ -73,7 +73,11 @@ class MikageClient(discord.Client): return try: top_category = guild.by_category()[0][0] - channel = await guild.create_text_channel(CHANNEL_NAME, category=top_category) + channel = await guild.create_text_channel( + CHANNEL_NAME, + category=top_category, + topic="the he/they therapist - you know, the one who lives in the morgue in the basement of that building that doesn't exist?" + ) await channel.move(category=top_category, beginning=True) self.state[guild_id] = {'channel': channel.id} self.save_state() From 8c2eeeae3ccfcf30989cffe133013e4edbdf613d Mon Sep 17 00:00:00 2001 From: xenofem Date: Fri, 25 Mar 2022 18:14:43 -0400 Subject: [PATCH 07/13] tweak channel topic --- bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot.py b/bot.py index 6598545..524dd78 100644 --- a/bot.py +++ b/bot.py @@ -76,7 +76,7 @@ class MikageClient(discord.Client): channel = await guild.create_text_channel( CHANNEL_NAME, category=top_category, - topic="the he/they therapist - you know, the one who lives in the morgue in the basement of that building that doesn't exist?" + topic="the he/they therapist - you know, the one who lives in the morgue in the basement of that building that doesn't exist? - is in" ) await channel.move(category=top_category, beginning=True) self.state[guild_id] = {'channel': channel.id} From dc0a6ce68f34cf2395982fd19a95c7af8fe24146 Mon Sep 17 00:00:00 2001 From: xenofem Date: Fri, 25 Mar 2022 18:16:53 -0400 Subject: [PATCH 08/13] much shorter deletion time --- bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot.py b/bot.py index 524dd78..0d45f4b 100644 --- a/bot.py +++ b/bot.py @@ -7,7 +7,7 @@ import discord STATE_FILE = 'state.json' CHANNEL_NAME = 'therapy-elevator' -DELETION_SECONDS = 300 +DELETION_SECONDS = 15 TYPING_DELAY = 2 SETUP_MESSAGE = 'Welcome to Nemuro Memorial Hall. Please give your name and class year for our records.' From b702aaa475b3b917e750962b4eb715c0c2237a15 Mon Sep 17 00:00:00 2001 From: xenofem Date: Fri, 25 Mar 2022 18:35:21 -0400 Subject: [PATCH 09/13] add privacy info --- README.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d9820bf..ce0ca5b 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,15 @@ Discord bot to give questionable elevator therapy +## Privacy + +This bot does not persistently store any data except for the numerical +IDs of each server it's in, and the numerical ID of the channel it +creates for itself in each server. It does not make use of any data +except for the list of channels. It does not read message +contents. It only creates one channel for itself, and does not +interact at all outside of that channel. + ## Discord setup Required permissions: @@ -9,8 +18,7 @@ Required permissions: - Read messages/view channels - Send messages - -## Setup +## Bot setup git clone https://git.xeno.science/xenofem/mikage-bot cd mikage-bot From 26a4fa70000c6d0df5ec80531c4e88cdf71a6ee4 Mon Sep 17 00:00:00 2001 From: xenofem Date: Fri, 25 Mar 2022 19:01:15 -0400 Subject: [PATCH 10/13] fancier falling --- bot.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bot.py b/bot.py index 0d45f4b..e5e845d 100644 --- a/bot.py +++ b/bot.py @@ -23,7 +23,10 @@ ELEVATOR_SHIT = [ '*a rattling. the elevator begins to shake*' '*a squealing of cables and pulleys*' ] -CRASH = ('|\n'*10) + '***the elevator crashes to the bottom***' + ('\n'*10) + '...' +START_FALL = '*the elevator begins freefalling*' +FALL = '|' +FALL_COUNT = 10 +CRASH = '***the elevator crashes to the bottom***' + ('\n'*10) + '...' FINAL_MESSAGE = 'I understand. Your only choice is to revolutionize the world. The path you must take has been prepared for you.' ROSE = '🌹' @@ -107,6 +110,9 @@ class MikageClient(discord.Client): return if channel_index == len(channels) - 1: if category_index == len(categories) - 2: + await try_send(message.channel, START_FALL) + for i in range(FALL_COUNT): + await try_send(message.channel, FALL) await message.channel.move(category=categories[-1][0], end=True) await try_send(message.channel, CRASH) await asyncio.sleep(TYPING_DELAY) From 5e38af2b6392bc49a8c45a1d3a33c337ffb7d117 Mon Sep 17 00:00:00 2001 From: xenofem Date: Fri, 25 Mar 2022 19:03:36 -0400 Subject: [PATCH 11/13] Revert "fancier falling" - doesn't work well with discord ratelimits This reverts commit 26a4fa70000c6d0df5ec80531c4e88cdf71a6ee4. --- bot.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/bot.py b/bot.py index e5e845d..0d45f4b 100644 --- a/bot.py +++ b/bot.py @@ -23,10 +23,7 @@ ELEVATOR_SHIT = [ '*a rattling. the elevator begins to shake*' '*a squealing of cables and pulleys*' ] -START_FALL = '*the elevator begins freefalling*' -FALL = '|' -FALL_COUNT = 10 -CRASH = '***the elevator crashes to the bottom***' + ('\n'*10) + '...' +CRASH = ('|\n'*10) + '***the elevator crashes to the bottom***' + ('\n'*10) + '...' FINAL_MESSAGE = 'I understand. Your only choice is to revolutionize the world. The path you must take has been prepared for you.' ROSE = '🌹' @@ -110,9 +107,6 @@ class MikageClient(discord.Client): return if channel_index == len(channels) - 1: if category_index == len(categories) - 2: - await try_send(message.channel, START_FALL) - for i in range(FALL_COUNT): - await try_send(message.channel, FALL) await message.channel.move(category=categories[-1][0], end=True) await try_send(message.channel, CRASH) await asyncio.sleep(TYPING_DELAY) From b6a7d38bed3f440cf102169bf15c73f95c2fee19 Mon Sep 17 00:00:00 2001 From: xenofem Date: Fri, 25 Mar 2022 21:08:50 -0400 Subject: [PATCH 12/13] lint fixes --- bot.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/bot.py b/bot.py index 0d45f4b..543d511 100644 --- a/bot.py +++ b/bot.py @@ -20,8 +20,8 @@ ELEVATOR_SHIT = [ '*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*' + '*a rattling. the elevator begins to shake*', + '*a squealing of cables and pulleys*', ] CRASH = ('|\n'*10) + '***the elevator crashes to the bottom***' + ('\n'*10) + '...' FINAL_MESSAGE = 'I understand. Your only choice is to revolutionize the world. The path you must take has been prepared for you.' @@ -38,7 +38,7 @@ async def try_move(channel, **kwargs): 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!") + await try_send(channel, "Dammit, the elevator's stuck!") def text_only(channels): return [channel for channel in channels if isinstance(channel, discord.TextChannel)] @@ -123,9 +123,8 @@ class MikageClient(discord.Client): 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))]) + 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: From d8270f558f62bc081edf7f706a13349389ae1266 Mon Sep 17 00:00:00 2001 From: xenofem Date: Fri, 25 Mar 2022 21:20:11 -0400 Subject: [PATCH 13/13] give a ring at the end along with the rose --- bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot.py b/bot.py index 543d511..faa1396 100644 --- a/bot.py +++ b/bot.py @@ -25,7 +25,7 @@ ELEVATOR_SHIT = [ ] CRASH = ('|\n'*10) + '***the elevator crashes to the bottom***' + ('\n'*10) + '...' FINAL_MESSAGE = 'I understand. Your only choice is to revolutionize the world. The path you must take has been prepared for you.' -ROSE = '🌹' +ROSE = '🌹💍' async def try_send(channel, message): try: