Compare commits
2 commits
8b6da55729
...
5a658a107f
Author | SHA1 | Date | |
---|---|---|---|
xenofem | 5a658a107f | ||
xenofem | 2d9d30f4f7 |
59
bot.py
59
bot.py
|
@ -8,10 +8,22 @@ import discord
|
||||||
STATE_FILE = 'state.json'
|
STATE_FILE = 'state.json'
|
||||||
CHANNEL_NAME = 'therapy-elevator'
|
CHANNEL_NAME = 'therapy-elevator'
|
||||||
DELETION_SECONDS = 300
|
DELETION_SECONDS = 300
|
||||||
|
TYPING_DELAY = 2
|
||||||
|
|
||||||
SETUP_MESSAGE = 'Welcome to Nemuro Memorial Hall. Please give your name and class year for our records.'
|
SETUP_MESSAGE = 'Welcome to Nemuro Memorial Hall. Please give your name and class year for our records.'
|
||||||
INITIAL_MESSAGE = 'All right, please begin.'
|
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.'
|
FINAL_MESSAGE = 'I understand. Your only choice is to revolutionize the world. The path you must take has been prepared for you.'
|
||||||
ROSE = '🌹'
|
ROSE = '🌹'
|
||||||
|
|
||||||
|
@ -21,6 +33,13 @@ async def try_send(channel, message):
|
||||||
except discord.DiscordException as e:
|
except discord.DiscordException as e:
|
||||||
print(f"error sending message in channel {channel}: {e}", file=sys.stderr)
|
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):
|
def text_only(channels):
|
||||||
return [channel for channel in channels if isinstance(channel, discord.TextChannel)]
|
return [channel for channel in channels if isinstance(channel, discord.TextChannel)]
|
||||||
|
|
||||||
|
@ -40,6 +59,7 @@ class MikageClient(discord.Client):
|
||||||
|
|
||||||
async def on_ready(self):
|
async def on_ready(self):
|
||||||
print(f"logged in as {self.user}", file=sys.stderr)
|
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:
|
for guild in self.guilds:
|
||||||
await self.initialize_elevator(guild)
|
await self.initialize_elevator(guild)
|
||||||
|
|
||||||
|
@ -76,24 +96,18 @@ class MikageClient(discord.Client):
|
||||||
channels = text_only(channels)
|
channels = text_only(channels)
|
||||||
channel_index = channels.index(message.channel)
|
channel_index = channels.index(message.channel)
|
||||||
|
|
||||||
if channel_index == len(channels) - 1:
|
if category_index == 0 and channel_index == 0:
|
||||||
|
await try_send(message.channel, INITIAL_MESSAGE)
|
||||||
|
|
||||||
if category_index == len(categories) - 1:
|
if category_index == len(categories) - 1:
|
||||||
return
|
return
|
||||||
target_category = categories[category_index+1][0]
|
if channel_index == len(channels) - 1:
|
||||||
target_position = 0
|
if category_index == len(categories) - 2:
|
||||||
else:
|
await message.channel.move(category=categories[-1][0], end=True)
|
||||||
target_category = category
|
await try_send(message.channel, CRASH)
|
||||||
target_position = channel_index+1
|
await asyncio.sleep(TYPING_DELAY)
|
||||||
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, FINAL_MESSAGE)
|
||||||
|
await asyncio.sleep(TYPING_DELAY)
|
||||||
await try_send(message.channel, ROSE)
|
await try_send(message.channel, ROSE)
|
||||||
await asyncio.sleep(DELETION_SECONDS)
|
await asyncio.sleep(DELETION_SECONDS)
|
||||||
try:
|
try:
|
||||||
|
@ -105,12 +119,13 @@ class MikageClient(discord.Client):
|
||||||
return
|
return
|
||||||
await self.initialize_elevator(message.guild)
|
await self.initialize_elevator(message.guild)
|
||||||
return
|
return
|
||||||
|
else:
|
||||||
if category_index == 0 and channel_index == 0:
|
await try_move(message.channel, category=categories[category_index+1][0], beginning=True)
|
||||||
await try_send(message.channel, INITIAL_MESSAGE)
|
await try_send(message.channel, BUTTERFLIES[int(category_index*len(BUTTERFLIES)/(len(categories)-2))])
|
||||||
if target_position == 0:
|
else:
|
||||||
await try_send(message.channel, random.choice(BUTTERFLIES))
|
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()
|
client = MikageClient()
|
||||||
with open('token', encoding='utf-8') as f:
|
with open('token', encoding='utf-8') as f:
|
||||||
|
|
Loading…
Reference in a new issue