-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtrivia.py
More file actions
1777 lines (1642 loc) · 88.1 KB
/
trivia.py
File metadata and controls
1777 lines (1642 loc) · 88.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#! /usr/bin/python3
# Mode60 Ultra-beta Prototype
# ======================================================================================================================
# Title.............: 'Trivia-Master I'
# Filename..........: trivia.py (zCore plugin module)
# Version...........: 1.00
# Author............: Neo Nemesis
# Description.......: Interactive trivia game
# Remarks...........: This is the prototype-II build of zCore plugin module
# Author Notes......: This is just a ultra-beta demonstration and not an official release.
# ======================================================================================================================
# Import whatever python stuff is needed here
import sys_zcore as pc # Required for sys_zcore scripting features
import asyncio # Required
import logging # Optional, only if you want to log debug (mprint) to log.txt file
# Other Imports (as needed)
import time # For Trivia
import random # For Trivia
import threading # For Trivia
from configparser import RawConfigParser # For Trivia
# declare data map
pdata = {}
# Set up logging (optional)
logging.basicConfig(filename='./zcorelog.txt', level=logging.DEBUG) # For error and debug logging
pdata['debuglog'] = 'on' # turn 'on' for testing, otherwise 'off'
# For remote loading (required for plugin modules)
def plugin_chk_():
return True
# For start up loading (required if importing system module functions)
def system_req_():
return 'sys_zcore'
# shutting down the module
def plugin_exit_():
global pdata
mprint(f'Shutting down...')
for x in range(len(pdata['server'])):
server = pdata['server'][x]
for y in range(len(pdata[server, 'channel'])):
chan = pdata[server, 'channel'][x].replace('#', '')
if pdata[server, chan]['thread'] != '0':
pdata[server, chan]['thread'].join()
continue
continue
pdata = {}
return
# stopping the module on specific server and it's channels (connection loss)
# SSLError and OSError reconnects from zCore
def plugin_stop_(server):
global pdata
if pdata != {}:
mprint(f'Core Override: Trivia has been stopped on {server} by zCore')
for x in range(len(pdata[server, 'channel'])):
trivia(server, pdata[server, 'channel'][x], 'inter')
continue
return 1
return 0
# Start up init
def plugin_init_():
global pdata # always call this first from every function
# -[ Plugin Title ]-------------------------------------------------------------------------------------------------
pdata['ptitle'] = 'Trivia Master' # title of plugin (anything)
pdata['pversion'] = '1.00' # version (anything)
pdata['pauthor'] = 'Neo Nemesis' # who wrote it
pdata['mreqver'] = '0.1x'
# ############## TRIVIA CONTROL ################
# Trivia Control
pdata['trivia'] = False # Automatically start trivia (False to disable)
# Trivia Control
# ##############################################
# ############## MODULE PRINT ################
pdata['moduleprint'] = True # Screen printing, True For testing, normally False
# ############################################
# -[ Assign Data to map from trivia.cnf ] ----------------------------------------------------------------------------
# Trivia stuff
pdata['startmode'] = 'random' # change to different start modes, random, 123, randcat
pdata['categories'] = pc.cnfread('trivia.cnf', 'trivia', 'categories').lower() # category list
pdata['category'] = pdata['categories'].split(',') # individual category name pdata['category'][x]
pdata['defmode'] = 'random' # default start mode
pdata['c_hour'] = pc.cnfread('trivia.cnf', 'trivia', 'hour') # Last saved hour of the day (no minutes)
pdata['c_day'] = pc.cnfread('trivia.cnf', 'trivia', 'day') # Last saved day of the year
pdata['c_week'] = pc.cnfread('trivia.cnf', 'trivia', 'week') # Last saved week of the year
pdata['c_month'] = pc.cnfread('trivia.cnf', 'trivia', 'month') # Last saved month of the year
pdata['c_year'] = pc.cnfread('trivia.cnf', 'trivia', 'year') # Last saved year
# IRC stuff
pdata['serverlist'] = pc.cnfread('trivia.cnf', 'trivia', 'serverlist').lower() # server list
pdata['server'] = pdata['serverlist'].split(',')
# run thru the list for server and decalre channel specific data
for x in range(len(pdata['server'])):
server = pdata['server'][x]
# declare channel data
pdata[server, 'channels'] = pc.cnfread('trivia.cnf', server, 'channels').lower()
pdata[server, 'botname'] = pc.cnfread('zcore.cnf', server, 'botname')
# declare each server/channel
pdata[server, 'channel'] = pdata[server, 'channels'].split(',')
# trivia stuff
for y in range(len(pdata[server, 'channel'])):
# check if channel data exists, if not create entry
# chann = pdata[server, 'channel'][y].lower()
# if pc.cnfexists('trivia.cnf', server + '_' + chann.decode(), 'cache') is False:
# pc.cnfwrite('trivia.cnf', server + '_' + chann.decode(), 'cache', '0')
# set channel stats
chan = pdata[server, 'channel'][y].replace('#', '')
chan = chan.lower()
pdata[server, chan] = {}
pdata[server, chan]['data'] = server + '_' + chan
if pc.cnfexists('trivia.cnf', pdata[server, chan]['data'], 'cache') is False:
pc.cnfwrite('trivia.cnf', pdata[server, chan]['data'], 'cache', '0')
pdata[server, chan]['trivia'] = False # Is trivia playing True or not playing False
pdata[server, chan]['game'] = '0' # current game logic position
pdata[server, chan]['mode'] = '0' # current game mode (random, 123, randcat)
pdata[server, chan]['category'] = '0' # current category
pdata[server, chan]['file'] = '0' # category filename (no path)
pdata[server, chan]['question'] = '0' # current question
pdata[server, chan]['answer'] = '0' # current answer
pdata[server, chan]['hints'] = -1 # Keeps track of how many hints (max 3)
pdata[server, chan]['hint'] = '0' # Keeps track of actual hint (*****)
pdata[server, chan]['qnum'] = 0 # Keeps track of the question number
pdata[server, chan]['timer'] = '0' # For timer
pdata[server, chan]['timerun'] = False # For timer
pdata[server, chan]['thread'] = '0' # For timer
pdata[server, chan]['pointimer'] = '0' # for keeping track of points decline as hints are revealed
pdata[server, chan]['points'] = '0' # keeps track of winnable points
pdata[server, chan]['response'] = '0' # keeps track of response times
pdata[server, chan]['streakname'] = '0'
pdata[server, chan]['streakcount'] = 0
# pdata[server, chan]['fpotd'] = '0'
# time control (for hourly, daily, weekly, etc)
pdata[server, chan]['time_control'] = pc.cnfread('trivia.cnf', server, 'time_control')
pdata[server, chan]['control_main'] = '' # Main control thread for #channel on server
pdata[server, chan]['control_timer1'] = '0' # control timer for hourly stats
# pdata[server, chan]['control_timer2'] = '0' # control timer for daily, weekly and monthly stats
# pdata[server, chan]['control_timer3'] = '0' # control timer for alltime and yearly
pdata[server, chan]['controlA'] = '0' # for timer1 event tracking do not change
# pdata[server, chan]['controlB'] = '0' # for timer2 event tracking do not change
# pdata[server, chan]['controlC'] = '0' # for timer3 event tracking do not change
# pdata[server, chan]['control_run'] = False
tok = 'h,d,w,m,y'
token = tok.split(',')
for z in range(len(token)):
dckt = server + '_tcd'
chantag = chan + '_' + token[z]
if pc.cnfexists('trivia.cnf', dckt, chantag) is False:
pc.cnfwrite('trivia.cnf', dckt, chantag, '0')
pdata[server, chan][token[z]] = ''
continue
elif pc.cnfread('trivia.cnf', dckt, chantag) == '0':
pdata[server, chan][token[z]] = ''
continue
else:
pdata[server, chan][token[z]] = pc.cnfread('trivia.cnf', dckt, chantag)
continue
continue
continue
# data map complete
mprint(f"{pdata['ptitle']} * Version: {pdata['pversion']} By: {pdata['pauthor']} - Loaded successfully.")
# Screen printing [*REQUIRED FUNCTION*]---------------------------------------------------------------------------------
# For module printing, logging and testing purposes, AFTER plugin is loaded use this instead of print()
# function name 'mprint' can be anything you define
# set pdata['moduleprint'] = False above to disable screen print
# set pdata['debug'] = False (at the top) to disable logging
def mprint(string):
global pdata # always call this first from every function
if pdata['moduleprint'] is True:
print(f'[T-M] * {string}') # This can be print(f'{string}') or print(f'Anything: {string}')
# logging is optional
if pdata['debuglog'] == 'on':
logging.debug(f'[T-M] * {string}') # Make sure to copy the same text format for cleaner logging!
return
# End mprint() ---------------------------------------------------------------------------------------------------------
# EVENTS ---------------------------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------------------------------
# evt_join('servername', b':Username!~Host@mask.net JOIN :#Channel')
# JOIN
async def evt_join(server, joindata):
global pdata
jdata = joindata.split(b' ')
username = pc.gettok(jdata[0], 0, b'!')
username = username.replace(b':', b'')
dusername = username.decode()
channel = jdata[2].replace(b':', b'')
dchannel = channel.decode()
dchannel = dchannel.lower()
chan = dchannel.replace('#', '')
if server not in pdata['server']:
return
if dchannel not in pdata[server, 'channel']:
return
# auto start
if pdata['trivia'] is True and dusername.lower() == pdata[server, 'botname'].lower():
time.sleep(0.75)
await trivia(server, dchannel, 'start')
return
# trivia join message
if pdata[server, chan]['trivia'] is True and pdata[server, chan]['game'] != 0:
if pdata[server, chan]['game'] == 'time':
ctime = 15 - round(time.time() - float(pdata[server, chan]['timer']))
if ctime < 0:
await trivia(server, dchannel, 'stop')
time.sleep(1)
await trivia(server, dchannel, 'start')
return
# need to check for time errors here and restart trivia
#
time.sleep(0.05)
pc.privmsg_(server, channel, '\x0315,1Welcome to \x02\x0311,1Trivia-Master\x02\x0310,1 on ' + channel.decode() + '! \x0315,1Next question in\x02\x033,1 ' + str(ctime) + ' \x02\x0315,1seconds. Use \x0310,1!thelp\x0315,1 for help.\x03')
return
if pdata[server, chan]['game'] == 'play':
time.sleep(0.05)
hintmsg = pdata[server, chan]['hint']
if pdata[server, chan]['hints'] > 1:
hintmsg = pdata[server, chan]['hint2']
if pdata[server, chan]['hints'] > 2:
hintmsg = pdata[server, chan]['hint3']
pc.privmsg_(server, channel, '\x0315,1Welcome to \x02\x0311,1Trivia-Master\x02\x0310,1 on ' + channel.decode() + '!\x0315,1 Use \x0310,1!thelp\x0315,1 for help. \x02\x033,1CURRENT TRIVIA:\x02\x0315,1 ' + pdata[server, chan]['question'] + ' \x02\x033,1HINT:\x02\x0310,1 ' + str(hintmsg) + '\x03')
return
else:
return
# ----------------------------------------------------------------------------------------------------------------------
# evt_privmsg('servername', b':Username!~Host@mask.net PRIVMSG target :Message data')
# PRIVMSG
# (( TRIVIA COMMANDS AND CORRECT ANSWER INPUT ))
async def evt_privmsg(server, message):
global pdata # always call this first from every function
mdata = message.split(b' ')
umsg = pc.gettok(message, 2, b':')
umsg = umsg.decode()
umsg = umsg.lower()
# split up the message into single words and values
username = pc.gettok(mdata[0], 0, b'!')
username = username.replace(b':', b'')
dusername = username.decode()
dusername = dusername.lower()
channel = mdata[2]
dchannel = channel.decode()
dchannel = dchannel.lower()
chan = dchannel.replace('#', '')
chandat = server + '_' + chan
if server not in pdata['server']:
return
if dchannel not in pdata[server, 'channel'] and b'#' in mdata[2]:
return
# mprint(f'umsg: {umsg}')
# keep data case lower
# /privmsg commands
if b'#' not in mdata[2] and pc.is_admin(server, dusername) is True:
# --------------------------------------------------------------------------------------------------------------
# /privmsg botname rem-q category X
# Removes question #X from the specified category
if mdata[3].lower() == b':rem-q' and pc.is_botmaster(dusername) is True:
if len(mdata) != 6:
pc.notice_(server, username, '[T-M] * ERROR: Invalid syntax. /msg <botname> rem-q X')
return
mdata5 = mdata[5].decode()
if mdata5.isnumeric() is False or isinstance(str(mdata5), float) is True:
pc.notice_(server, username, '[T-M] * ERROR: Invalid syntax. /msg <botname> rem-q X')
return
cat = mdata[4].decode()
filename = './qafiles/' + cat.lower() + '.txt'
if pc.iistok(pdata['categories'], cat.lower(), ',') is False or pc.isfile(filename) is False:
pc.notice_(server, username, '[T-M] * ERROR: Category ' + cat.lower() + ' not found.')
return
qnum = mdata5
file = open(filename, 'r')
filelines = file.readlines()
if int(qnum) > len(filelines) or int(qnum) <= 0:
pc.notice_(server, username, '[T-M] * ERROR: Question No.' + str(qnum) + ' exceeds the category ' + cat.lower() + '. This category contains: ' + str(len(filelines)) + ' questions')
return
file = open(filename, 'r')
filelines = file.readlines()
file.close()
open(filename, 'w').close()
file = open(filename, 'a')
for x in range(len(filelines)):
if x + 1 == int(qnum):
continue
file.write(filelines[x])
continue
pc.notice_(server, username, '[T-M] * Question No.' + str(qnum) + ' successfully removed from category ' + cat.lower() + '.')
mprint(f'Trivia question No.{str(qnum)} has been removed from ./qafiles/{cat.lower()}.txt by {username.decode()} - {pc.cdate()} - {pc.ctime()}')
return
# --------------------------------------------------------------------------------------------------------------
# /privmsg botname add-q category ^question text`answer text
# Add a question and answer to specified category (bot master only)
if mdata[3].lower() == b':add-q' and pc.is_botmaster(dusername) is True:
if len(mdata) < 6 or pc.numtok(message, b'^') != 2:
pc.notice_(server, username, '[T-M] * ERROR: Invalid syntax. /msg <botname> add-q ^question text goes here here`the answer text')
return
if pc.numtok(message, b'^') != 2:
pc.notice_(server, username, '[T-M] * ERROR: Invalid syntax. /msg <botname> add-q ^question text goes here here`the answer text')
return
cat = mdata[4].decode()
filename = './qafiles/' + cat.lower() + '.txt'
new_q = pc.gettok(message, 1, b'^')
if pc.numtok(new_q, b'`') != 2:
pc.notice_(server, username, '[T-M] * ERROR: Invalid syntax. /msg <botname> add-q ^question text goes here here`the answer text')
return
if pc.iistok(pdata['categories'], cat.lower(), ',') is False or pc.isfile(filename) is False:
pc.notice_(server, username, '[T-M] * ERROR: Category ' + cat.lower() + ' not found.')
return
new_q = new_q.decode()
file = open(filename, 'a')
file.write('\n' + new_q)
file.close()
# pc.txtwrite(filename, new_q)
pc.notice_(server, username, '[T-M] * New question successfully added to category ' + cat.lower() + '.')
mprint(f'New trivia question added to ./qafiles/{cat.lower()}.txt by {username.decode()} - {pc.cdate()} - {pc.ctime()}')
return
# --------------------------------------------------------------------------------------------------------------
# /privmsg botname clean <category>
# /privmsg botname clean all
# This cleans the specified category file, and stores all bad lines in a seperate log for review
if mdata[3].lower() == b':clean' and pc.is_botmaster(dusername) is True:
if len(mdata) < 5:
pc.notice_(server, username, '[T-M] * ERROR: Invalid syntax. /msg <botname> clean <category>')
return
cat = mdata[4].decode()
if cat.lower() == 'all':
pc.notice_(server, username, '[T-M] * Checking all category files for errors...')
await trivia(server, dusername, 'clean', 'all')
return
filename = './qafiles/' + cat.lower() + '.txt'
if pc.isfile(filename) is False:
pc.notice_(server, username, '[T-M] * ERROR: Category ' + cat.lower() + ' file not found.')
return
else:
pc.notice_(server, username, '[T-M] * Checking category ' + cat.lower() + ' for errors...')
await trivia(server, dusername, 'clean', cat.lower())
return
return
# ------------------------------------------------------------------------------------------------------------------
# !testing (botmaster and admin only)
if mdata[3].lower() == b':!testing' and pc.is_admin(server, dusername) is True:
pc.privmsg_(server, channel, 'Testing ABC')
# ------------------------------------------------------------------------------------------------------------------
# !trivia cammond (!trivia on/off category) (botmaster and admin only)
elif mdata[3].lower() == b':!trivia' and len(mdata) > 4:
if pc.is_admin(server, dusername) is False:
return
# !trivia skip
if mdata[4].lower() == b'skip' and pdata[server, chan]['trivia'] is True:
if pdata[server, chan]['game'] == 'play':
await trivia(server, channel.decode(), 'skip')
return
if pdata[server, chan]['game'] == 'time':
ctime = 15 - round(time.time() - float(pdata[server, chan]['timer']))
time.sleep(0.04)
pc.privmsg_(server, channel, '\x0315,1New question coming up in\x02\x033,1 ' + str(ctime) + ' \x02\x03seconds.')
return
if mdata[4].lower() == b'skip' and pdata[server, chan]['trivia'] is False:
time.sleep(0.05)
pc.privmsg_(server, channel, 'Trivia is not currently enabled.')
return
# !trivia on
if mdata[4].lower() == b'on':
if pdata[server, chan]['trivia'] is True:
time.sleep(0.05)
pc.notice_(server, username, 'Trivia is already enabled.')
else:
pdata[server, chan]['trivia'] = True
time.sleep(0.05)
# pc.privmsg_(server, channel, 'Trivia has been enabled.')
await trivia(server, dchannel, 'start')
# !trivia off
if mdata[4].lower() == b'off':
if pdata[server, chan]['trivia'] is False:
time.sleep(0.05)
pc.notice_(server, username, 'Trivia is already disabled.')
else:
pdata[server, chan]['trivia'] = False
time.sleep(0.05)
# pc.notice_(server, username, 'Trivia has been disabled.')
await trivia(server, dchannel, 'stop')
# ------------------------------------------------------------------------------------------------------------------
# !thelp - displays help
elif mdata[3].lower() == b':!thelp' or mdata[3].lower() == b':!help':
if not chan == pdata[server, 'botname'] and pdata[server, chan]['trivia'] is False:
return
time.sleep(0.05)
pc.privmsg_(server, channel, '\x02\x0315,1Trivia Commands:\x02\x033,1 !myscore !highscore !fastest !streaks !thelp\x03')
pc.privmsg_(server, channel, '\x02\x0315,1Trivia Commands:\x02\x033,1 !alltime or !a !hourly or !h !daily or !d !weekly or !w !monthly or !m !yearly or !y\x03')
return
# ------------------------------------------------------------------------------------------------------------------
# !myscore - displays user score and statistics
elif mdata[3].lower() == b':!myscore' or mdata[3] == b':!score':
if pdata[server, chan]['trivia'] is False:
return
if len(mdata) == 5 and mdata[3] == b':!score':
username = mdata[4]
dusername = str(username.decode()).lower()
if pc.cnfexists('trivia.cnf', server + '_' + chan, dusername) is False:
pc.privmsg_(server, channel, '\x02\x0311,1' + str(username.decode()) + '\x02\x0315,1 has not played yet.\x03')
return
score = '\x0310,1[\x033,1Score:\x0311,1 ' + str(playerstats(server, channel, dusername, 'score')) + '\x0310,1]'
wins = '\x0310,1[\x033,1Wins:\x0311,1 ' + str(playerstats(server, channel, dusername, 'wins')) + '\x0310,1]'
streak = '\x0310,1[\x033,1Longest Streak:\x0311,1 ' + str(playerstats(server, channel, dusername, 'streak')) + '\x0310,1]'
best = '\x0310,1[\x033,1Best Time:\x0311,1 ' + str(playerstats(server, channel, dusername, 'best')) + '\x0310,1]\x03'
stats = '\x02\x0315,1PLAYER SCORE:\x02\x0310,1 ' + username.decode() + ' ' + score + wins + streak + best
# add stuff here so can be toggled from privmsg or notice
time.sleep(0.5)
pc.privmsg_(server, channel, stats)
return
# ------------------------------------------------------------------------------------------------------------------
# !highscore - displays high scores
elif mdata[3].lower() == b':!highscore':
if pdata[server, chan]['trivia'] is False:
return
if pc.cnfread('trivia.cnf', chandat, 'cache') == 0:
pc.privmsg(server, channel, '\x0315,1There are currently no high scores.\x03')
return
await score_keep(server, channel, 'hs')
return
# ------------------------------------------------------------------------------------------------------------------
# !streaks - displays winning streaks
elif mdata[3].lower() == b':!streaks':
if pdata[server, chan]['trivia'] is False:
return
if pc.cnfread('trivia.cnf', chandat, 'cache') == 0:
pc.privmsg(server, channel, '\x0315,1There are currently no streaks.\x03')
return
await score_keep(server, channel, 'st')
return
# ------------------------------------------------------------------------------------------------------------------
# !fastest - displays fastest players
# Does not work, here for documentation
# Needs good way of sorting floating number values
elif mdata[3].lower() == b':!fastest':
if pdata[server, chan]['trivia'] is False:
return
if pc.cnfread('trivia.cnf', chandat, 'cache') == 0:
pc.privmsg(server, channel, '\x0315,1There are currently no fastest times.\x03')
return
await score_keep(server, channel, 'fp')
return
# ------------------------------------------------------------------------------------------------------------------
# Timely Functions
# !today -----------------------------------------------------------------------------------------------------------
# General description of hourly and daily scores
# elif mdata[3].lower() == b':!today' or mdata[3].lower() == b':!t':
# describe the daily top player, all time high score, longest streak and fastest time
# !hourly or !h ----------------------------------------------------------------------------------------------------
elif mdata[3].lower() == b':!hourly' or mdata[3].lower() == b':!h':
if pdata[server, chan]['trivia'] is False or pdata[server, chan]['time_control'] == 'off':
return
await time_event(server, dchannel, 'hourly', 'req')
return
# !daily or !d -----------------------------------------------------------------------------------------------------
elif mdata[3].lower() == b':!daily' or mdata[3].lower() == b':!d':
if pdata[server, chan]['trivia'] is False or pdata[server, chan]['time_control'] == 'off':
return
await time_event(server, dchannel, 'daily', 'req')
return
# !weekly or !w ----------------------------------------------------------------------------------------------------
elif mdata[3].lower() == b':!weekly' or mdata[3].lower() == b':!w':
if pdata[server, chan]['trivia'] is False or pdata[server, chan]['time_control'] == 'off':
return
await time_event(server, dchannel, 'weekly', 'req')
return
# !monthly or !m ---------------------------------------------------------------------------------------------------
elif mdata[3].lower() == b':!monthly' or mdata[3].lower() == b':!m':
if pdata[server, chan]['trivia'] is False or pdata[server, chan]['time_control'] == 'off':
return
await time_event(server, dchannel, 'monthly', 'req')
return
# !yearly or !y ----------------------------------------------------------------------------------------------------
elif mdata[3].lower() == b':!yearly' or mdata[3].lower() == b':!y':
if pdata[server, chan]['trivia'] is False or pdata[server, chan]['time_control'] == 'off':
return
await time_event(server, dchannel, 'yearly', 'req')
return
# !alltime or !a ----------------------------------------------------------------------------------------------------
elif mdata[3].lower() == b':!alltime' or mdata[3].lower() == b':!a':
if pdata[server, chan]['trivia'] is False or pdata[server, chan]['time_control'] == 'off':
return
await time_event(server, dchannel, 'alltime', 'req')
return
# ------------------------------------------------------------------------------------------------------------------
# User answer input for Trivia
else:
try:
if chan == pdata[server, 'botname']:
mprint('[ERROR] ************ An error has occured at line 520 of trivia.py and been bypassed.')
return
if pdata[server, chan]['game'] == 'play':
if umsg == pdata[server, chan]['answer'].lower():
if isplayer(server, channel, dusername) is False:
playerstats(server, channel.decode(), dusername, 'new')
# pdata[server, chan]['thread'].join()
# pc.privmsg_(server, channel, 'Correct')
totaltime = round(time.time() - pdata[server, chan]['response'], 2)
pdata[server, chan]['game'] = 'win'
pdata[server, chan]['timerun'] = False
pc.privmsg_(server, channel, '\x02\x0310,1' + username.decode() + '\x02 \x0315,1Wins\x0311,1 ' + str(pdata[server, chan]['points']) + ' points! \x02\x033,1ANSWER ---->\x02 ' + pdata[server, chan]['answer'] + ' \x02\x0315,1TIME:\x02\x0311,1 ' + str(totaltime) + ' seconds\x03')
wins = int(playerstats(server, channel, dusername, 'wins')) + 1
playerstats(server, channel, dusername, 'wins', 'c', str(wins))
points = int(playerstats(server, channel, dusername, 'score')) + int(pdata[server, chan]['points'])
playerstats(server, channel, dusername, 'score', 'c', str(points))
if playerstats(server, channel, dusername, 'best') != 'NA' and totaltime < float(playerstats(server, channel, dusername, 'best')):
pc.privmsg_(server, channel, '\x02\x0310,1' + username.decode() + '\x02 \x0311,1Set a new best time record! \x02\x038,1>\x0311,1 ' + str(totaltime) + ' seconds\x038,1 <\x02\x03')
playerstats(server, channel, dusername, 'best', 'c', str(totaltime))
if playerstats(server, channel, dusername, 'best') == 'NA':
playerstats(server, channel, dusername, 'best', 'c', str(totaltime))
# set up for timely stats
if pdata[server, chan]['time_control'] == 'on':
await time_event(server, channel.decode(), 'add', username.decode(), pdata[server, chan]['points'])
# set up for winning streak
if pdata[server, chan]['streakname'] != dusername:
pdata[server, chan]['streakcount'] = 0
pdata[server, chan]['streakname'] = dusername
pdata[server, chan]['streakcount'] += 1
if pdata[server, chan]['streakcount'] > int(playerstats(server, channel.decode(), dusername, 'streak')):
playerstats(server, channel.decode(), dusername, 'streak', 'c', str(pdata[server, chan]['streakcount']))
if pdata[server, chan]['streakcount'] > 1:
time.sleep(0.2)
pc.privmsg_(server, channel, '\x02\x0310,1' + username.decode() + '\x02 \x0315,1Won\x02\x033,1 ' + str(pdata[server, chan]['streakcount']) + ' \x02\x0315,1in a row! \x02\x0311,1 * WINNING STREAK *\x02\x03')
time.sleep(1.25)
freetriv(server, dchannel)
await trivia(server, dchannel, 'next')
except KeyError:
mprint('[ERROR] ************ An error has occured at line 520 of trivia.py and been bypassed.')
return
# End of EVENTS --------------------------------------------------------------------------------------------------------
# ======================================================================================================================
# Main trivia function
async def trivia(server, channel, opt, cat='', opt2=''):
global pdata
chan = str(channel.replace('#', '')).lower()
cmsg = ''
# ------------------------------------------------------------------------------------------------------------------
# Start trivia
# trivia(server, channel, 'start', 'mode', 'category')
if opt == 'start':
mprint(f'TRIVIA STARTED: {server} {channel} {cat}')
# pdata[server, chan]['game'] = '0'
if cat == '' or cat == 'random':
pdata[server, chan]['mode'] = 'random'
pdata[server, chan]['trivia'] = True
cmsg = 'Random Trivia'
elif cat == '123':
pdata[server, chan]['mode'] = '123'
cmsg = '123 Trivia'
if opt2 != '':
pdata[server, chan]['category'] = opt2
elif cat == 'randcat':
pdata[server, chan]['mode'] = 'randcat'
cmsg = 'Random Category'
if opt2 != '':
pdata[server, chan]['category'] = opt2
pc.privmsg_(server, channel.encode(), '\x02\x0314,1Trivia Master \x033,1 v' + pdata['pversion'] + '\x02\x0315,1 Now running:\x0310,1 \x02' + cmsg + '\x02\x03')
time.sleep(1)
pdata[server, chan]['game'] = 'time'
# time control
if pdata[server, chan]['time_control'] == 'on':
pdata[server, chan]['control_timer1'] = time.time()
# pdata[server, chan]['control_timer2'] = time.time()
# pdata[server, chan]['control_timer3'] = time.time()
# pdata[server, chan]['control_main'] = threading.Thread(target=time_control, args=(server, channel,), daemon=True)
# pdata[server, chan]['control_main'].start()
# mprint(f'AWAIT NEXT')
await trivia(server, channel, 'next')
# ------------------------------------------------------------------------------------------------------------------
# interrupt trivia (similar to 'stop' but used when connection is interrupted)
# trivia(server, channel, 'inter')
if opt == 'inter':
mprint(f'TRIVIA INTERRUPT: {server} {channel}')
pdata[server, chan]['timerun'] = False
pdata[server, chan]['game'] = '0'
pdata[server, chan]['mode'] = '0'
freetriv(server, channel)
pdata[server, chan]['streakname'] = '0'
pdata[server, chan]['streakcount'] = 0
pdata[server, chan]['thread'].join()
return
# ------------------------------------------------------------------------------------------------------------------
# stop trivia
# trivia(server, channel, 'stop')
if opt == 'stop':
mprint(f'TRIVIA STOPPED: {server} {channel}')
pdata[server, chan]['timerun'] = False
pdata[server, chan]['game'] = '0'
pdata[server, chan]['mode'] = '0'
freetriv(server, channel)
pdata[server, chan]['streakname'] = '0'
pdata[server, chan]['streakcount'] = 0
pc.privmsg_(server, channel.encode(), '\x02\x0314,1Trivia Master \x033,1 v' + pdata['pversion'] + '\x02\x0315,1 Stopped.\x03')
return
# ------------------------------------------------------------------------------------------------------------------
# next question
# trivia(server, channel, 'next')
if opt == 'next':
# mprint(f'BEGIN NEXT')
pdata[server, chan]['game'] = 'time'
if pdata[server, chan]['mode'] == 'random':
# mprint(f'BEGIN NEXT RANDOM')
# set category data
catnum = random.randint(0, len(pdata['category']))
catnum = catnum - 1
# mprint(f'catnum: {catnum}')
pdata[server, chan]['category'] = pdata['category'][catnum]
filename = './qafiles/' + pdata['category'][catnum] + '.txt'
# mprint(f'file: {filename}')
file = open(filename, 'r')
filelines = file.readlines()
pdata[server, chan]['qnum'] = random.randint(0, len(filelines))
qnum = pdata[server, chan]['qnum'] - 1
# mprint(f'qnum: {qnum}')
# need to fix this
pdata[server, chan]['question'] = pc.gettok(filelines[qnum], 0, '`')
pdata[server, chan]['answer'] = pc.gettok(filelines[qnum], 1, '`').replace('\n', '')
pdata[server, chan]['points'] = 10000 # Starting points at 1000
mprint(f"CAT: {pdata[server, chan]['category']} NUM: {pdata[server, chan]['qnum']}")
mprint(f'File: {filename}')
mprint(f"Q: {pdata[server, chan]['question']}")
mprint(f"A: {pdata[server, chan]['answer']}")
# set hint data
pdata[server, chan]['hints'] = -1
# pdata[server, chan]['hint'] = hint_gen(pdata[server, chan]['answer'], 0)
# mprint(f'Hint 0: {pdata[server, chan]['hint']}')
pdata[server, chan]['hint'] = randomizer(pdata[server, chan]['answer'], 0)
# pdata[server, chan]['hint1'] = hint_gen(pdata[server, chan]['answer'], 1, pdata[server, chan]['hint'])
# mprint(f'Hint 1: {pdata[server, chan]['hint1']}')
pdata[server, chan]['hint1'] = randomizer(pdata[server, chan]['answer'], 1, pdata[server, chan]['hint'])
# pdata[server, chan]['hint2'] = hint_gen(pdata[server, chan]['answer'], 2, pdata[server, chan]['hint1'])
# mprint(f'Hint 2: {pdata[server, chan]['hint2']}')
pdata[server, chan]['hint2'] = randomizer(pdata[server, chan]['answer'], 2, pdata[server, chan]['hint1'])
# pdata[server, chan]['hint3'] = hint_gen(pdata[server, chan]['answer'], 3, pdata[server, chan]['hint2'])
# mprint(f'Hint 3: {pdata[server, chan]['hint3']}')
pdata[server, chan]['hint3'] = randomizer(pdata[server, chan]['answer'], 3, pdata[server, chan]['hint2'])
# timer data
pdata[server, chan]['timerun'] = True
pdata[server, chan]['timer'] = time.time()
pc.privmsg_(server, channel.encode(), '\x0315,1Next question in\x02\x033,1 15 \x02\x0315,1seconds...\x03')
pdata[server, chan]['thread'] = threading.Thread(target=timer, args=(server, channel,), daemon=True)
pdata[server, chan]['thread'].start()
# ------------------------------------------------------------------------------------------------------------------
# ask question
# trivia(server, channel, 'ask')
if opt == 'ask':
pdata[server, chan]['game'] = 'play'
pdata[server, chan]['response'] = time.time()
pdata[server, chan]['pointimer'] = time.time()
pc.privmsg_(server, channel.encode(), '\x02\x0310,1[\x033,1\x02No.\x02 ' + str(pdata[server, chan]['qnum']) + ' ' + pdata[server, chan]['category'] + '\x0310,1]\x0315,1 \x02 ' + pdata[server, chan]['question'] + '\x03')
pc.privmsg_(server, channel.encode(), '\x0315,1First hint in\x02\x033,1 15 \x02\x0315,1seconds...\x03')
# testing
# mprint(f'Q: {pdata[server, chan]['question']}')
# mprint(f'A: {pdata[server, chan]['answer']}')
# timer info
pdata[server, chan]['timerun'] = True
pdata[server, chan]['timer'] = time.time()
pdata[server, chan]['hints'] = 0
pdata[server, chan]['thread'] = threading.Thread(target=timer, args=(server, channel,), daemon=True)
pdata[server, chan]['thread'].start()
# ------------------------------------------------------------------------------------------------------------------
# give hints
# trivia(server, channel, 'hint')
if opt == 'hint':
# determine points (old way, to be removed)
# math = int(pdata[server, chan]['points']) - 2500
# pdata[server, chan]['points'] = str(math)
pdata[server, chan]['game'] = 'play'
pdata[server, chan]['hints'] += 1
# create hint!!
hintx = 'hint' + str(pdata[server, chan]['hints'])
hint = pdata[server, chan][hintx]
pc.privmsg_(server, channel.encode(), '\x02\x0314,1Hint # ' + str(pdata[server, chan]['hints']) + ': ' + str(hint) + '\x02\x03')
# hint = hint_gen(ans, int(pdata[server, chan]['hints']), hnt)
# pc.privmsg_(server, channel.encode(), 'Hint #' + str(pdata[server, chan]['hints']) + ': ' + hint)
# set timer
pdata[server, chan]['timerun'] = True
pdata[server, chan]['timer'] = time.time()
pdata[server, chan]['thread'] = threading.Thread(target=timer, args=(server, channel,), daemon=True)
pdata[server, chan]['thread'].start()
# ------------------------------------------------------------------------------------------------------------------
# time is up
# trivia(server, channel, 'timeup')
if opt == 'timeup':
pdata[server, chan]['game'] = 'timeup'
pdata[server, chan]['timerun'] = False
pdata[server, chan]['streakname'] = '0'
pdata[server, chan]['streakcount'] = 0
pc.privmsg_(server, channel.encode(), '\x02\x0311,1Time is up!\x02\x0315,1 The answer is:\x02\x033,1 ' + pdata[server, chan]['answer'] + '\x03\x02')
time.sleep(1)
freetriv(server, channel)
await trivia(server, channel, 'next')
# ------------------------------------------------------------------------------------------------------------------
# skip question
# trivia(server, channel, 'skip')
if opt == 'skip':
pdata[server, chan]['game'] = 'skip'
pdata[server, chan]['timerun'] = False
pc.privmsg_(server, channel.encode(), '\x0315,1Skipping question...\x03')
time.sleep(1)
freetriv(server, channel)
await trivia(server, channel, 'next')
# ------------------------------------------------------------------------------------------------------------------
# Check category file(s) for issues or errors and store bad lines in seperate log file
# trivia(server, <dusername>, 'clean', 'category')
if opt == 'clean':
# duser = channel.decode()
# duser = duser.lower()
duser = channel
totalerr = '0^0'
if cat == 'all':
# pc.notice_(server, duser.encode(), 'Check All')
mprint('Checking all trivia categories for errors...')
for x in range(len(pdata['category'])):
filename = './qafiles/' + pdata['category'][x] + '.txt'
mprint('Checking file ' + cat.lower() + '.txt for trivia errors...')
errnum = t_file_clean(filename)
mprint('Error check for ' + pdata['category'][x] + '.txt complete. [Errors fixed: ' + str(pc.gettok(errnum, 1, '^')) + '] [Errors removed: ' + str(pc.gettok(errnum, 0, '^')) + ' and stored in ./qafiles/qlog.txt]')
err = int(pc.gettok(totalerr, 0, '^')) + int(pc.gettok(errnum, 0, '^'))
fix = int(pc.gettok(totalerr, 1, '^')) + int(pc.gettok(errnum, 1, '^'))
totalerr = str(err) + '^' + str(fix)
continue
mprint('Error checking for all trivia categories is complete. [Errors fixed: ' + str(pc.gettok(totalerr, 1, '^')) + '] [Errors removed: ' + str(pc.gettok(totalerr, 0, '^')) + ' and stored in ./zcore/qafiles/qlog.txt]')
pc.notice_(server, duser.encode(), '[T-M] * Check All complete. [Errors fixed: ' + str(pc.gettok(totalerr, 1, '^')) + '] [Errors removed: ' + str(pc.gettok(totalerr, 0, '^')) + ' and stored in ./qafiles/qlog.txt]')
return
else:
filename = './qafiles/' + cat.lower() + '.txt'
# pc.notice_(server, duser.encode(), 'Checking ' + cat.lower())
mprint('Checking file ' + cat.lower() + '.txt for trivia errors...')
errnum = t_file_clean(filename)
mprint('Error check for ' + cat.lower() + '.txt complete. [Errors fixed: ' + str(pc.gettok(errnum, 1, '^')) + '] [Errors removed: ' + str(pc.gettok(errnum, 0, '^')) + ' and stored in ./qafiles/qlog.txt]')
pc.notice_(server, duser.encode(), '[T-M] * Category check for ' + cat.lower() + ' complete. [Errors fixed: ' + str(pc.gettok(errnum, 1, '^')) + '] [Errors removed: ' + str(pc.gettok(errnum, 0, '^')) + ' and stored in ./qafiles/qlog.txt]')
return
# End trivia() =========================================================================================================
# ======================================================================================================================
# Trivia category file cleaner
# File must exist in qafiles folder in zCore directory. ./zcore/qafiles/filename.txt
# ### Improperly formatted trivia data will cause errors in the game.
# ### BUG REMOVAL!! Make sure to scan all new trivia files to fix or remove
# to add better correction for ':'
def t_file_clean(filename):
# Scan the file for improperly formatted questions
fname = filename
file = open(fname, 'r')
filelines = file.readlines()
# filelines = filelines.splitlines()
# properly formatted questions are stored in the 'clean file'
c_file = open('./qafiles/cleanfile.txt', 'a')
# improperly formatted questions are removed and stored in the qlog.txt
qlog = open('./qafiles/qlog.txt', 'a')
# how many errors are found? Starts with 0 same for fixes
errnum = 0
fixnum = 0
# lasttok = ''
# l_tok1 = ''
# l_tok2 = ''
# tokenc = 0
# scanning for and removing improperly formatted questions
for x in range(len(filelines)):
fileline = filelines[x].replace('\n', '')
# Remove questions that do not contain proper token seperator character " ` " (grave accent mark)
if pc.numtok(fileline, '`') != 2:
errnum += 1
qlog.write('ERR-BAD-SYN: ' + fileline + '\n')
continue
else:
q = pc.gettok(fileline, 0, '`')
a = pc.gettok(fileline, 1, '`')
# print(f'Q: {q} TOK: {pc.numtok(q, ': ')}')
# answer is present in question
if a in q:
errnum += 1
qlog.write('ERR-BAD-FRM: ' + fileline + '\n')
continue
# Remove 5 letter answers that contain white spaces
if len(a) == 5 and pc.numtok(a, ' ') > 1:
errnum += 1
qlog.write('ERR-5-CHR: ' + fileline + '\n')
continue
# Fix erroneous colan formats
# Category: Question
if pc.numtok(q, ': ') == 2:
q = pc.gettok(q, 1, ': ')
fixnum += 1
qlog.write('ERR-FIX-MOD1: ' + fileline + '\n')
c_file.write(str(q) + '`' + str(a) + '\n')
continue
# Fix erroneous colan formats (remove Category: and leave Sub-Category:)
# Category: Sub-category: Question
if pc.numtok(q, ': ') == 3:
q = pc.gettok(q, 1, ': ') + ': ' + pc.gettok(q, 2, ': ')
fixnum += 1
# print(f'PRINTEST: {q}`{a}')
qlog.write('ERR-FIX-MOD2: ' + fileline + '\n')
c_file.write(str(q) + '`' + str(a) + '\n')
continue
# Category : Question
if pc.numtok(q, ' : ') == 2:
q = pc.gettok(q, 1, ' : ')
fixnum += 1
qlog.write('ERR-FIX-MOD3: ' + fileline + '\n')
c_file.write(str(q) + '`' + str(a) + '\n')
continue
# Category:Question
if pc.numtok(q, ':') == 2:
q = pc.gettok(q, 1, ':')
fixnum += 1
qlog.write('ERR-FIX-MOD4: ' + fileline + '\n')
c_file.write(str(q) + '`' + str(a) + '\n')
continue
# Remove erroneous excessive colon formats
if pc.numtok(q, ':') >= 4:
errnum += 1
qlog.write('ERR-TOK-EXC: ' + fileline + '\n')
continue
# Properly formatted question, write to file.
c_file.write(fileline + '\n')
continue
file.close()
c_file.close()
qlog.close()
# removing old and resaving the 'cleaned list' as the category file.
pc.remfile(filename)
pc.renamefile('./qafiles/cleanfile.txt', filename)
# returns the number of errors found and fixed or removed
return str(errnum) + '^' + str(fixnum)
# ----------------------------------------------------------------------------------------------------------------------
# free up resources (test)
def freetriv(server, channel):
global pdata
chan = channel.lower()
chan = chan.replace('#', '')
pdata[server, chan]['question'] = '0'
pdata[server, chan]['answer'] = '0'
pdata[server, chan]['hints'] = -1 # Keeps track of how many hints (max 3)
pdata[server, chan]['hint'] = '0' # Keeps track of actual hint (*****)
pdata[server, chan]['qnum'] = 0
pdata[server, chan]['timer'] = '0' # For timer
pdata[server, chan]['timerun'] = False # For timer
pdata[server, chan]['thread'] = '0' # For timer
pdata[server, chan]['points'] = '0'
pdata[server, chan]['response'] = '0'
return
# ======================================================================================================================
# Trivia timer
# Controls the game position and turn
# async def timer(server, channel):
def timer(server, channel):
global pdata
chan = channel.replace('#', '')
chan = chan.lower()
# while pdata[server, chan]['timerun'] is True:
while pdata[server, chan]['game'] != '0':
if pdata[server, chan]['timerun'] is False: # ???
break
# if pdata[server, chan]['game'] == '0': # This is useful or not idk
# pdata[server, chan]['timerun'] = False
# break
time.sleep(0.1)
# after timer sleep, check stats
if pdata[server, chan]['timerun'] is False:
break
# Time Control (only performed between questions on a 1 hour timer!)
if pdata[server, chan]['time_control'] == 'on' and pdata[server, chan]['game'] == 'time':
# hour has changed
if pdata['c_hour'] != pc.chour():
pc.cnfwrite('trivia.cnf', 'trivia', 'hour', str(pc.chour()))
pdata['c_hour'] = pc.chour()
pdata[server, chan]['control_timer1'] = time.time()
pdata[server, chan]['controlA'] = '0'
mprint(f"Hour has changed to: {pdata['c_hour']}")
asyncio.run(time_event(server, channel, 'hourly', 'new'))
# day has changed
if pdata['c_day'] != pc.cday():
pc.cnfwrite('trivia.cnf', 'trivia', 'day', str(pc.cday()))
pdata['c_day'] = pc.cday()
mprint(f"Day has changed to: {pdata['c_day']}")
asyncio.run(time_event(server, channel, 'daily', 'new'))
# week has changed
if pdata['c_week'] != pc.cweek():
pc.cnfwrite('trivia.cnf', 'trivia', 'week', str(pc.cweek()))
pdata['c_week'] = pc.cweek()
mprint(f"Week has changed to: {pdata['c_week']}")
asyncio.run(time_event(server, channel, 'weekly', 'new'))
# month has changed
if pdata['c_month'] != pc.cmonth():
pc.cnfwrite('trivia.cnf', 'trivia', 'month', str(pc.cmonth()))
pdata['c_month'] = pc.cmonth()
mprint(f"Month has changed to: {pdata['c_month']}")
asyncio.run(time_event(server, channel, 'monthly', 'new'))
# year has changed
if pdata['c_year'] != pc.cyear():
pc.cnfwrite('trivia.cnf', 'trivia', 'year', str(pc.cyear()))
pdata['c_year'] = pc.cyear()
mprint(f"Year has changed to: {pdata['c_year']}")
asyncio.run(time_event(server, channel, 'yearly', 'new'))
tcu = time.time() - float(pdata[server, chan]['control_timer1'])
# 10 minutes - Today's Top Players
if round(tcu) >= 600 and pdata[server, chan]['controlA'] == '0':
pdata[server, chan]['controlA'] = 'A'
asyncio.run(time_event(server, channel, 'daily', 'auto'))
# 20 minutes - All Time Top Players
elif round(tcu) >= 1200 and pdata[server, chan]['controlA'] == 'A':
pdata[server, chan]['controlA'] = 'B'
asyncio.run(time_event(server, channel, 'alltime', 'auto'))
# 30 minutes - Hourly Top Players
elif round(tcu) >= 1800 and pdata[server, chan]['controlA'] == 'B':
pdata[server, chan]['controlA'] = 'C'
asyncio.run(time_event(server, channel, 'hourly', 'auto'))
# 40 minutes - Weekly Top Players
elif round(tcu) >= 2400 and pdata[server, chan]['controlA'] == 'C':
pdata[server, chan]['controlA'] = 'D'
asyncio.run(time_event(server, channel, 'weekly', 'auto'))
# 50 minutes - Monthly Top Players
elif round(tcu) >= 3000 and pdata[server, chan]['controlA'] == 'D':
pdata[server, chan]['controlA'] = 'E'
asyncio.run(time_event(server, channel, 'monthly', 'auto'))
# 59min 59seconds 59 milsec - end of timer, restart
elif tcu >= 3599.9983 and pdata[server, chan]['controlA'] == 'E':
pdata[server, chan]['controlA'] = '0'
pdata[server, chan]['control_timer1'] = time.time()