@@ -222,7 +222,10 @@ def check_result(self, message_content: str) -> Result:
222
222
# lanes and nuttings: 1177377997993549824
223
223
# test: 1213896278614745158
224
224
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
226
229
file = open ('files/preferences' , 'r' )
227
230
file_contents = file .readlines ()
228
231
file .close ()
@@ -245,13 +248,13 @@ def read_preferences(self):
245
248
# add them to the system if they're not already in it
246
249
my_user = self .get_mb_user (duser )
247
250
if not my_user :
248
- self .users .append (MbUser (my_user ))
251
+ my_user = MbUser (duser )
252
+ self .users .append (my_user )
249
253
for preference in preferences :
250
254
pref_tokens = preference .split (':' )
251
255
my_user .set_preference (Preference (pref_tokens [0 ], int (pref_tokens [1 ])))
252
256
253
257
254
- #TODO write preferences
255
258
def write_preferences (self ):
256
259
file = open ('files/preferences' , 'r' )
257
260
file_contents = file .readlines ()
@@ -281,13 +284,14 @@ def read_in_info(self):
281
284
#TODO run command, where I can tell the bot to run a bash command, and it prints out the results
282
285
# at this point, command.content doesn't contain 'minibot' or anything like that
283
286
async def run_command (self , command : Command ):
287
+ setting_preference = False
284
288
if len (command .content .split ()) == 0 :
285
289
return
286
290
command_content_original = command .content
287
291
command .content = command .content .lower ()
288
292
command_zero = command .content .split ()[0 ]
289
293
# ------------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' ]
291
295
if command .type == 'user' :
292
296
user = self .get_mb_user (command .user )
293
297
if not user :
@@ -297,6 +301,7 @@ async def run_command(self, command: Command):
297
301
# await self.run_command(Command('user', 'help', user, command.message))
298
302
return
299
303
if command_zero == 'goofy_ratio' and len (command .content .split ()) > 1 :
304
+ setting_preference = True
300
305
self .get_mb_user (command .user ).set_preference (Preference ('goofy_ratio' , int (command .content .split ()[1 ])))
301
306
elif command_zero == 'help' or command_zero == 'h' :
302
307
file = open ('files/helpMessage' , 'r' )
@@ -306,16 +311,21 @@ async def run_command(self, command: Command):
306
311
file .close ()
307
312
await command .message .reply (help_message )
308
313
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 )
309
317
else : # it's 'no_congrats', 'yes_congrats', 'no_rekkening', 'yes_rekkening', 'no_leaderboard', 'yes_leaderboard'
318
+ setting_preference = True
310
319
self .get_mb_user (command .user ).set_preference (Preference (command .content .split ()[0 ], 1 ))
311
320
responses = ['Okay' , 'Awesome' , 'Sweet' , 'Cool' , 'Gotcha' ]
312
321
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 ()
315
325
return
316
326
# ---------------admin commands--------------------------
317
327
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' ]
319
329
320
330
if not self .per .has_permission (command .user .name , 'admin' ):
321
331
await command .message .reply ('Permission denied.' )
@@ -377,6 +387,8 @@ async def run_command(self, command: Command):
377
387
await message_to_reply .reply (command .message .content [beginning_length :])
378
388
except discord .errors .NotFound :
379
389
await command .message .reply ('discord.errors.NotFound' )
390
+ if command_zero == 'read_info' or command_zero == 'ri' :
391
+ self .read_in_info ()
380
392
admin_responses = ['You got it, boss' , 'Sure thing, boss' ]
381
393
response = admin_responses [random .randrange (0 ,len (admin_responses ))]
382
394
await command .message .reply (response )
@@ -427,15 +439,18 @@ async def feed(self, message: discord.Message):
427
439
else :
428
440
await self .check_command (message )
429
441
430
- # TODO remove this, testing
431
- # await self.write_to_file()
432
442
433
443
# returns a string representation of time - seconds:int -> 'm:ss'
434
444
def format_time (time : int ) -> str :
435
445
if time < 60 :
436
446
return str (time )
437
447
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
439
454
440
455
async def daily_leaderboard (self ):
441
456
guild = discord .utils .get (client .guilds , name = 'Lanes and Nuttings' )
@@ -473,13 +488,14 @@ async def daily_leaderboard(self):
473
488
intents = discord .Intents .default ()
474
489
intents .messages = True
475
490
intents .message_content = True
491
+ intents .members = True
476
492
client = discord .Client (intents = intents )
477
493
478
494
479
495
# TODO handle data so that it won't be lost when disconnecting and/or restarting
480
496
# TODO handle global object properly
481
497
# 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 )
483
499
484
500
# Event handler for when the bot is ready
485
501
@client .event
@@ -512,7 +528,7 @@ async def daily_scheduler():
512
528
513
529
514
530
# bot's token
515
- token_file = open ('files/testToken ' , 'r' ) # TODO change this back
531
+ token_file = open ('files/token ' , 'r' )
516
532
token = token_file .read ()
517
533
token_file .close ()
518
534
0 commit comments