1
- from distutils . command . check import check
1
+ from json import load as json_load
2
2
from os import environ , getenv , listdir
3
3
from os .path import dirname
4
- from requests import get as requests_get
5
4
6
5
import discord
7
6
from discord .ext import commands
8
7
from dotenv import load_dotenv
9
8
from firebase_admin import credentials , db , initialize_app
9
+ from requests import get as requests_get
10
10
11
11
# Read environment variables set at ./.env
12
12
if not load_dotenv (f"{ dirname (__file__ )} /.env" ):
@@ -286,6 +286,46 @@ async def delete_data(ctx, name):
286
286
print (e .__traceback__ )
287
287
288
288
289
+ def fetch_points_for_each_task () -> dict [str , int ]:
290
+ """
291
+ Reads file at `points.json` to understand how many points to give for each task. If file is absent or error comes up, uses hardcoded values
292
+ """
293
+ try :
294
+ with open (f"{ dirname (__file__ )} /points.json" ) as f :
295
+ points_dict : dict [str , int ] = json_load (f )
296
+ if not isinstance (points_dict , dict ) or not points_dict :
297
+ raise ValueError
298
+
299
+ except (FileNotFoundError , ValueError ) as e :
300
+ print (
301
+ f"Could not read points.json in current directory so using hardcoded points. Error - { e } "
302
+ )
303
+ points_dict = {
304
+ "pull request" : 20 ,
305
+ "info" : 40 ,
306
+ "blog" : 60 ,
307
+ "sm posting" : 7 ,
308
+ "weekly work" : 5 ,
309
+ "idea" : 3 ,
310
+ "brochure" : 10 ,
311
+ "news" : 40 ,
312
+ "demos" : 20 ,
313
+ "oc volunteer" : 30 ,
314
+ "oc assigned" : 20 ,
315
+ "oc no work" : 10 ,
316
+ "oc manager" : 50 ,
317
+ "wtf" : 75 ,
318
+ "discord" : 10 ,
319
+ "marketing" : 20 ,
320
+ "mini project" : 100 ,
321
+ "complete project" : 200 ,
322
+ "promotion medium" : 25 ,
323
+ "promotion large" : 50 ,
324
+ }
325
+
326
+ return points_dict
327
+
328
+
289
329
@bot .command ()
290
330
@commands .has_any_role ("Leaderboard" , "Cabinet Member" )
291
331
async def contribution (ctx , name , task ):
@@ -297,28 +337,6 @@ async def contribution(ctx, name, task):
297
337
if value ["Name" ].casefold () == name .casefold ():
298
338
selector = leaderboard_ref .child (key )
299
339
ref = selector .get ()
300
- points_dict = {
301
- "pull request" : 20 ,
302
- "info" : 40 ,
303
- "blog" : 60 ,
304
- "sm posting" : 7 ,
305
- "weekly work" : 5 ,
306
- "idea" : 3 ,
307
- "brochure" : 10 ,
308
- "news" : 40 ,
309
- "demos" : 20 ,
310
- "oc volunteer" : 30 ,
311
- "oc assigned" : 20 ,
312
- "oc no work" : 10 ,
313
- "oc manager" : 50 ,
314
- "wtf" : 75 ,
315
- "discord" : 10 ,
316
- "marketing" : 20 ,
317
- "mini project" : 100 ,
318
- "complete project" : 200 ,
319
- "promotion medium" : 25 ,
320
- "promotion large" : 50 ,
321
- }
322
340
323
341
rating = ref ["Rating" ] + points_dict [task .casefold ()]
324
342
contributions = ref ["Contributions" ] + 1
@@ -430,4 +448,8 @@ def fetch_spreadsheet(speadsheet_id: str):
430
448
...
431
449
432
450
451
+ # Fetch points for each task
452
+ points_dict : dict [str , int ] = fetch_points_for_each_task ()
453
+
454
+ # Run the bot
433
455
bot .run (getenv ("BOT_TOKEN" ))
0 commit comments