Skip to content

Commit dae325c

Browse files
committed
added reading and writing preferences, a my_preferences command, and some other stuff
1 parent 31b5462 commit dae325c

File tree

5 files changed

+36
-17
lines changed

5 files changed

+36
-17
lines changed

Diff for: files/congratsMessages

-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ Huge congratulations, uname!
66
You deserve all this success and more, uname!
77
You are our shining star. Well done, uname.
88
Heartiest congratulations! You did it, uname!
9-
Felicitations, acclamations and congratulations, uname.
109
Hats off to you, uname.
1110
We could not be more proud of you, uname.
1211
I’m in awe of you, uname!
@@ -18,5 +17,4 @@ Cheers to you, uname!
1817
You are unstoppable, uname!
1918
Thanks for giving us a reason to celebrate, uname!
2019
You’re a class act. Congrats, uname.
21-
https://tenor.com/view/thank-you-nailed-it-raised-eyebrows-slay-gif-16917227
2220
https://tenor.com/view/thumbs-up-double-thumbs-up-like-agreed-yup-gif-14284264219182206721

Diff for: files/goofyCongratsMessages

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,5 @@ https://tenor.com/view/noice-nooice-nice-swag-bling-gif-5935775
4848
https://tenor.com/view/die-laughing-funny-kids-dies-gif-24902870
4949
https://tenor.com/view/great-job-yes-yeah-scream-baby-gif-4890580191188789133
5050
https://tenor.com/view/mr-bean-thumbs-up-doctor-gif-19720132
51-
https://tenor.com/view/thumbs-up-well-done-good-job-well-said-accurate-gif-20365141
51+
https://tenor.com/view/thumbs-up-well-done-good-job-well-said-accurate-gif-20365141
52+
https://tenor.com/view/thank-you-nailed-it-raised-eyebrows-slay-gif-16917227

Diff for: files/helpMessage

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ OR
44
mb <command> <value>
55

66
commands:
7-
help
7+
help | h
88
prints this message
99
no_congrats
1010
disables congrats messages
@@ -20,5 +20,7 @@ commands:
2020
will put you back on the rekkening
2121
goofy_ratio
2222
on a scale of 1-10, how often do you want to receive goofy messages, rather than the normal ones? Default: 0
23+
my_preferences | mp
24+
responds with your preferences
2325

2426
Alternatively, just tell Nick what you want, and he'll run the command for you.

Diff for: files/helpMessageAdmin

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ say channel message
44

55
react channel messageID emoji
66

7-
reply channel messageID message
7+
reply channel messageID message
8+
9+
read_info | ri

Diff for: miniBot.py

+28-12
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,10 @@ def check_result(self, message_content: str) -> Result:
222222
# lanes and nuttings: 1177377997993549824
223223
# test: 1213896278614745158
224224
def read_preferences(self):
225-
guild = client.get_guild(1213896278614745158) # TODO change this to lanes and nuttings
225+
guild = self.client.get_guild(1177377997993549824)
226+
if not guild:
227+
print('not guild')
228+
return 1
226229
file = open('files/preferences', 'r')
227230
file_contents = file.readlines()
228231
file.close()
@@ -245,13 +248,13 @@ def read_preferences(self):
245248
# add them to the system if they're not already in it
246249
my_user = self.get_mb_user(duser)
247250
if not my_user:
248-
self.users.append(MbUser(my_user))
251+
my_user = MbUser(duser)
252+
self.users.append(my_user)
249253
for preference in preferences:
250254
pref_tokens = preference.split(':')
251255
my_user.set_preference(Preference(pref_tokens[0], int(pref_tokens[1])))
252256

253257

254-
#TODO write preferences
255258
def write_preferences(self):
256259
file = open('files/preferences', 'r')
257260
file_contents = file.readlines()
@@ -281,13 +284,14 @@ def read_in_info(self):
281284
#TODO run command, where I can tell the bot to run a bash command, and it prints out the results
282285
# at this point, command.content doesn't contain 'minibot' or anything like that
283286
async def run_command(self, command: Command):
287+
setting_preference = False
284288
if len(command.content.split()) == 0:
285289
return
286290
command_content_original = command.content
287291
command.content = command.content.lower()
288292
command_zero = command.content.split()[0]
289293
# ------------user commands-----------------------
290-
user_commands = ['no_congrats', 'yes_congrats', 'no_rekkening', 'yes_rekkening', 'no_leaderboard', 'yes_leaderboard', 'goofy_ratio', 'help', 'h']
294+
user_commands = ['no_congrats', 'yes_congrats', 'no_rekkening', 'yes_rekkening', 'no_leaderboard', 'yes_leaderboard', 'goofy_ratio', 'help', 'h', 'my_preferences', 'mp']
291295
if command.type == 'user':
292296
user = self.get_mb_user(command.user)
293297
if not user:
@@ -297,6 +301,7 @@ async def run_command(self, command: Command):
297301
# await self.run_command(Command('user', 'help', user, command.message))
298302
return
299303
if command_zero == 'goofy_ratio' and len(command.content.split()) > 1:
304+
setting_preference = True
300305
self.get_mb_user(command.user).set_preference(Preference('goofy_ratio', int(command.content.split()[1])))
301306
elif command_zero == 'help' or command_zero == 'h':
302307
file = open('files/helpMessage', 'r')
@@ -306,16 +311,21 @@ async def run_command(self, command: Command):
306311
file.close()
307312
await command.message.reply(help_message)
308313
return
314+
elif command_zero == 'my_preferences' or command_zero == 'mp':
315+
preferences_string = self.get_mb_user(command.user).get_preferences_string()
316+
await command.message.reply(preferences_string)
309317
else: # it's 'no_congrats', 'yes_congrats', 'no_rekkening', 'yes_rekkening', 'no_leaderboard', 'yes_leaderboard'
318+
setting_preference = True
310319
self.get_mb_user(command.user).set_preference(Preference(command.content.split()[0], 1))
311320
responses = ['Okay', 'Awesome', 'Sweet', 'Cool', 'Gotcha']
312321
response = responses[random.randrange(0,len(responses))]
313-
await command.message.reply(f'{response}, {command.user.display_name}, preference set.')
314-
self.write_preferences()
322+
if setting_preference:
323+
await command.message.reply(f'{response}, {command.user.display_name}, preference set.')
324+
self.write_preferences()
315325
return
316326
# ---------------admin commands--------------------------
317327
else:# it's an admin command
318-
admin_commands = ['say', 'leaderboard', 'lb', 'help', 'h', 'react', 'reply']
328+
admin_commands = ['say', 'leaderboard', 'lb', 'help', 'h', 'react', 'reply', 'read_info', 'ri']
319329

320330
if not self.per.has_permission(command.user.name, 'admin'):
321331
await command.message.reply('Permission denied.')
@@ -377,6 +387,8 @@ async def run_command(self, command: Command):
377387
await message_to_reply.reply(command.message.content[beginning_length:])
378388
except discord.errors.NotFound:
379389
await command.message.reply('discord.errors.NotFound')
390+
if command_zero == 'read_info' or command_zero == 'ri':
391+
self.read_in_info()
380392
admin_responses = ['You got it, boss', 'Sure thing, boss']
381393
response = admin_responses[random.randrange(0,len(admin_responses))]
382394
await command.message.reply(response)
@@ -427,15 +439,18 @@ async def feed(self, message: discord.Message):
427439
else:
428440
await self.check_command(message)
429441

430-
# TODO remove this, testing
431-
# await self.write_to_file()
432442

433443
# returns a string representation of time - seconds:int -> 'm:ss'
434444
def format_time(time: int) -> str:
435445
if time < 60:
436446
return str(time)
437447
else:
438-
return f'{time // 60}:{time % 60}'
448+
minutes = time // 60
449+
seconds = time % 60
450+
minutes_string = str(minutes)
451+
zero = '0' if seconds < 10 else ''
452+
seconds_string = zero + str(seconds)
453+
return minutes_string + ':' + seconds_string
439454

440455
async def daily_leaderboard(self):
441456
guild = discord.utils.get(client.guilds, name='Lanes and Nuttings')
@@ -473,13 +488,14 @@ async def daily_leaderboard(self):
473488
intents = discord.Intents.default()
474489
intents.messages = True
475490
intents.message_content = True
491+
intents.members = True
476492
client = discord.Client(intents=intents)
477493

478494

479495
# TODO handle data so that it won't be lost when disconnecting and/or restarting
480496
# TODO handle global object properly
481497
# global object
482-
bot = MiniBot(client) #TODO change so it starts as none, then in on_ready, initialize so it can read in JSON and remember everyone's info
498+
bot = MiniBot(client)
483499

484500
# Event handler for when the bot is ready
485501
@client.event
@@ -512,7 +528,7 @@ async def daily_scheduler():
512528

513529

514530
# bot's token
515-
token_file = open('files/testToken', 'r') # TODO change this back
531+
token_file = open('files/token', 'r')
516532
token = token_file.read()
517533
token_file.close()
518534

0 commit comments

Comments
 (0)