17
17
import asyncio #
18
18
import activity #
19
19
import string #
20
+ import schedule #
20
21
#
21
22
#####################################
22
23
@@ -51,15 +52,15 @@ async def on_connect():
51
52
Sets the bot activity to ACTIVITY.
52
53
"""
53
54
54
- logging .warning (f'{ bot .user .name } { VERSION } has sucessfully connected to Discord.' )
55
+ logging .warning (f'{ bot .user .name } { VERSION } has successfully connected to Discord.' )
55
56
await bot .change_presence (activity = ACTIVITY )
56
57
57
58
58
59
@bot .event
59
60
async def on_ready ():
60
61
"""
61
62
Prints a list of guilds the bot is connected to when the bot is finished processing
62
- date from Discord servers. Also calls the initizaling functions in activity.py.
63
+ date from Discord servers. Also calls the initializing functions in activity.py.
63
64
"""
64
65
65
66
logging .info ('Bot loading complete. Current guilds: ' )
@@ -73,6 +74,15 @@ async def on_ready():
73
74
for guild in bot .guilds :
74
75
add_all_users_from_guild_to_database (guild )
75
76
77
+ logging .info ("Scheduling events..." )
78
+ logging .info ("Daily events" )
79
+ schedule .every ().day .at ("00:00" ).do (run_once_every_day )
80
+ logging .info ("Hourly events" )
81
+ schedule .every ().hour .do (run_once_every_hour )
82
+ logging .info ("Minutely events" )
83
+ schedule .every ().minute .do (run_once_every_minute )
84
+ logging .info ("Scheduling complete!" )
85
+
76
86
77
87
@bot .event
78
88
async def on_disconnect ():
@@ -105,7 +115,7 @@ async def on_member_join(member):
105
115
welcome_message = (
106
116
f"Hi { member .name } , welcome to Lounge server. Please set your "
107
117
"nickname to match the naming scheme used on the server. For example, if "
108
- "my name was John, my nickname would be \" Protobot | John\" . Please also "
118
+ "my name was John, my nickname would be \" ProtoBot | John\" . Please also "
109
119
"make sure to read any messages pinned in the #important channel."
110
120
)
111
121
@@ -283,42 +293,33 @@ async def about(ctx):
283
293
await ctx .message .channel .send (f"ProtoBot { VERSION } . Source code and bug tracker: https://github.com/klercke/ProtoBot" )
284
294
285
295
286
- async def run_once_every_day ():
296
+ def run_once_every_day ():
287
297
"""
288
- Runs a block of code every day sometime between 00:00 and 01:00 local time .
298
+ Runs a block of code every day.
289
299
"""
290
300
291
- if (int (time .strftime ('%H' , time .localtime ())) < 1 ):
292
- # This code will run if it is the correct time
293
- logging .info ("Running nightly operations." )
294
- else :
295
- logging .debug ("Attempted to run daily event out of defined hours." )
301
+ logging .info ("Running nightly operations." )
302
+ pass
296
303
297
304
298
- async def run_once_every_minute ():
305
+
306
+ def run_once_every_minute ():
299
307
"""
300
- Runs a block of code every minute
308
+ Runs a block of code every minute.
301
309
"""
302
310
303
- await asyncio .sleep (60 )
304
-
305
311
# Give every user in a voice channel points
306
312
for guild in bot .guilds :
307
313
for channel in guild .voice_channels :
308
314
for user in channel .members :
309
315
change_user_score (user .id , POINTS_PER_MINUTE_TALKING )
310
316
311
317
312
- async def run_once_every_hour ():
318
+ def run_once_every_hour ():
313
319
"""
314
- Runs a block of code every hour
320
+ Runs a block of code every hour.
315
321
"""
316
322
317
- await asyncio .sleep (3600 )
318
-
319
- # Call the once-each-day function so it can do its check
320
- await run_once_every_day ()
321
-
322
323
activity .change_all_scores (- POINT_DECAY_PER_HOUR )
323
324
324
325
@@ -371,9 +372,6 @@ def main():
371
372
]
372
373
)
373
374
374
- bot .loop .create_task (run_once_every_minute ())
375
- bot .loop .create_task (run_once_every_hour ())
376
-
377
375
bot .run (TOKEN )
378
376
379
377
if __name__ == "__main__" :
0 commit comments