forked from m0de-60/super-duckhunt-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
4493 lines (4245 loc) · 296 KB
/
main.py
File metadata and controls
4493 lines (4245 loc) · 296 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 https://m0de-60.github.io/web - SDH1.1.4 Final
# ABOUT INFO# ==========================================================================================================
# Title..........: Super DuckHunt v1.1.4 Python IRC Bot
# File...........: main.py
# Python version.: v3.12.0
# Script version.: v1.1.4: Stable release, final revision. Enjoy! Look forward to SDH2.0 on zCore!
# Version notes..: 1.1.4: Increased golden duck difficulty and fixed shop item popcorn so it does not consume bread
# until the popcorn is gone. Added !disarm <username> to order username gun confiscation :P
# 1.1.3-2: Addition of a optional SSL connection. See operators manual!
# 1.1.3: Added relay bot capability and more fixes and adjustments from v1.1.2
# 1.1.2: Added /msg botname boost <playername> for players who get stuck with low xp. Added handling
# for reconnecting after excess flood.
# 1.1.0: First major update from 1.0.0 added maintenance features, add game rules functions (infammo,
# gunconf, no hunting, searching bushes etc) recoded level up system, and changed the prize
# system. A lot bug fixes and small tweaks from 1.0.0
# 1.0.0: Beta release
# Language.......: English
# Description....: IRC Bot Script based off original DuckHunt bot by Menz Agitat
# Lots of changes and twists added to this, following suit as Menz Agitat bot was said to be a "port"
# of the NES game for IRC, This one would be equivelent to a SNES version, or a "sequel".
# Author(s)......: Neo_Nemesis (aka coderusa, Neo`Nemesis)
# Modified.......:
# Contributors...: End3r, f, bildramer, Friithian, ComputerTech, esjay, TheFatherMind, KnownSyntax, Salvaje
# IMPORT # =============================================================================================================
from configparser import RawConfigParser
from datetime import date
import threading
import ssl
import socket
import time
import random
import math
import bot
# CONFIGURATION VARIABLES # ============================================================================================
# Do not change these variables here. Instead change them in duckhunt.cnf under section [duckhunt]
# You MUST first manually put the info into duckhunt.cnf under section [duckhunt] before running the bot
# ======================================================================================================================
server = bot.cnfread('duckhunt.cnf', 'duckhunt', 'server').lower()
port = int(bot.cnfread('duckhunt.cnf', 'duckhunt', 'port')) # use only port 6667 or 6697 for SSL
if bot.cnfexists('duckhunt.cnf', 'duckhunt', 'serverssl') is False:
bot.cnfwrite('duckhunt.cnf', 'duckhunt', 'serverssl', 'off')
serverssl = bot.cnfread('duckhunt.cnf', 'duckhunt', 'serverssl')
duckchan = bot.cnfread('duckhunt.cnf', 'duckhunt', 'duckchan').encode()
duckchan = duckchan.lower()
botname = bot.cnfread('duckhunt.cnf', 'duckhunt', 'botname').encode()
botpass = str(bot.cnfread('duckhunt.cnf', 'duckhunt', 'botpass'))
botmaster = bot.cnfread('duckhunt.cnf', 'duckhunt', 'botmaster').lower()
adminlist = bot.cnfread('duckhunt.cnf', 'duckhunt', 'admin').lower()
botignore = bot.cnfread('duckhunt.cnf', 'duckhunt', 'ignore').lower()
spawntime = int(bot.cnfread('duckhunt.cnf', 'duckhunt', 'spawntime'))
flytime = int(bot.cnfread('duckhunt.cnf', 'duckhunt', 'flytime'))
maxducks = int(bot.cnfread('duckhunt.cnf', 'duckhunt', 'maxducks'))
duckexp = int(bot.cnfread('duckhunt.cnf', 'duckhunt', 'duckexp'))
duckfear = int(bot.cnfread('duckhunt.cnf', 'duckhunt', 'duckfear'))
duckgold = int(bot.cnfread('duckhunt.cnf', 'duckhunt', 'duckgold'))
friendrate = int(bot.cnfread('duckhunt.cnf', 'duckhunt', 'friendrate'))
# update 1.1.0 MAINTENANCE VALUES ======================================================================================
maint = int(bot.cnfread('duckhunt.cnf', 'duckhunt', 'maint'))
maint_time = bot.cnfread('duckhunt.cnf', 'duckhunt', 'maint_time')
if str(maint_time) == '0' and maint > 0:
maint_time = str(time.time())
bot.cnfwrite('duckhunt.cnf', 'duckhunt', 'maint_time', str(time.time()))
# update 1.1.0 CONFIGURATION 'RULES' VARIABLES =========================================================================
thebushes = int(bot.cnfread('duckhunt.cnf', 'rules', 'thebushes'))
gunconf = bot.cnfread('duckhunt.cnf', 'rules', 'gunconf')
infammo = bot.cnfread('duckhunt.cnf', 'rules', 'infammo')
gunricochet = int(bot.cnfread('duckhunt.cnf', 'rules', 'gunricochet'))
bang = bot.cnfread('duckhunt.cnf', 'rules', 'bang')
bef = bot.cnfread('duckhunt.cnf', 'rules', 'bef')
# FLOOD CHECK VALUES # =================================================================================================
flood_check = False
if bot.cnfread('duckhunt.cnf', 'duckhunt', 'floodcheck') != '0':
flood_check = True
# ADD-ON FOR RELAY BOTS (WORKING SORT OF) v1.1.3 ===================================================================
if bot.cnfexists('duckhunt.cnf', 'duckhunt', 'relays') is False:
bot.cnfwrite('duckhunt.cnf', 'duckhunt', 'relays', '0')
relaybot = bot.cnfread('duckhunt.cnf', 'duckhunt', 'relays').lower()
# GLOBAL VARIABLES # ===================================================================================================
botversion = b'1.1.4' # Current Bot Version hard code DO NOT CHANGE
# =========================================================
duckhunt = True # Main duckhunt control
# =========================================================
irc = ''
userlist = {} # For channel user monitoring
userchan = 0 # For channel user monitoring
duckexists = False # does a duck exist? always leave this as false
isconnect = False # Determines if server is connected, always leave this false
exitvar = False # For duck_timer, always leave this False
jammedguns = '' # jammed gun user storage, stored by user name
confiscatedguns = '' # confiscated gun user storage, stored by user name
fear_factor = False # for accumulation of duckfear points, always leave this false
flood = 0 # For flood control
flood_time = time.time() # For flood control
flood_cont = False # For flood control
flood_timer = '' # For flood control
duck = {} # Duck spawn array
duckid = '' # duck id for !bang/!bef
start_time = '' # start_time for duck timer
elapsed_time = '' # for duck timer
keep_alive = '' # For SSL stuff, v1.1.3-2
daily = bot.cnfread('duckhunt.cnf', 'top_shot', 'daily') # daily shots
weekly = bot.cnfread('duckhunt.cnf', 'top_shot', 'weekly') # weekly shots
monthly = bot.cnfread('duckhunt.cnf', 'top_shot', 'monthly') # monthly shots
totalshot = bot.cnfread('duckhunt.cnf', 'top_shot', 'totalshot') # total shots
month = bot.cnfread('duckhunt.cnf', 'top_shot', 't_month')
week = bot.cnfread('duckhunt.cnf', 'top_shot', 't_week')
day = bot.cnfread('duckhunt.cnf', 'top_shot', 't_day')
# topduck fix #1 of many - update 1.1.0
if not bot.cnfexists('duckhunt.cnf', 'ducks', 'cache'):
bot.cnfwrite('duckhunt.cnf', 'ducks', 'cache', '0')
# CORE FUNCTIONS LIST # ================================================================================================
# These are functions that require using socket irc.send() or data maps - SEE bot.py and func.py for other functions!
# ======================================================================================================================
# duck_exists
# ducksave
# duckstats
# duck_timer
# fleeduck
# ircnamesrf
# level_up
# namecheck
# shopmenu
# spawnduck
# topduck
# top_shot
# ======================================================================================================================
# FUNCTION #============================================================================================================
# Name...........: duck_exists
# Description....: determines if any spawned ducks exist
# Syntax.........: duck_exists()
# Parameters.....: None
# Return values..: Returns True - Duck Exists
# Returns False - Duck Does Not Exist
# ======================================================================================================================
def duck_exists():
for zx in range(maxducks + 1):
if zx == 0:
continue
dkey = 'd' + str(zx)
if duck[dkey] == 'None':
continue
elif duck[dkey] != 'None':
return True
return False
# ===> duck_exists
# FUNCTION #============================================================================================================
# Name...........: duckstats
# Description....: Retreives and delivers statistics of requested player
# Syntax.........: duckstats(user, ruser) (use duckstats(user, ruser, 'opt') for relay bots for PRIVMSG)
# Parameters.....: user - username to send data to
# ruser - username of stats to be displayed
# Return values..: Returns 1 after sending stats to user.
# ======================================================================================================================
# noinspection PyUnboundLocalVariable,PySimplifyBooleanCheck,PyShadowingNames
def duckstats(user, ruser, ext=''):
# No stats/user hasn't played
if bot.cnfexists('duckhunt.cnf', 'ducks', str(ruser)) is False and isconnect is True:
if ext != '':
irc.send(b'PRIVMSG ' + duckchan + b' :' + ruser + b' > Has not played yet.\r\n')
return 0
irc.send(b'NOTICE ' + user + b' :' + ruser + b' > Has not played yet.\r\n')
return 0
# prep stats
bot.iecheck(str(ruser))
rounds = bot.gettok(bot.duckinfo(ruser, b'ammo'), 0, '?').encode()
mags = bot.gettok(bot.duckinfo(ruser, b'ammo'), 1, '?').encode()
mrounds = bot.gettok(bot.duckinfo(ruser, b'ammo'), 2, '?').encode()
mmags = bot.gettok(bot.duckinfo(ruser, b'ammo'), 3, '?').encode()
ducks = bot.duckinfo(ruser, b'ducks').encode()
gducks = bot.duckinfo(ruser, b'gducks').encode()
xp = bot.duckinfo(ruser, b'xp').encode()
level = bot.duckinfo(ruser, b'level').encode()
accuracy = bot.gettok(bot.duckinfo(ruser, b'guninfo'), 0, '?').encode()
reliability = bot.gettok(bot.duckinfo(ruser, b'guninfo'), 1, '?').encode()
mreliability = bot.gettok(bot.duckinfo(ruser, b'guninfo'), 2, '?').encode()
if float(reliability) <= 65:
gunstatus = b'Needs cleaning'
elif bot.istok(jammedguns, str(ruser), ',') is True:
gunstatus = b'Jammed'
elif bot.istok(confiscatedguns, str(ruser), ',') is True and gunconf == 'on':
gunstatus = b'Confiscated'
else:
gunstatus = b'OK'
if bot.duckinfo(ruser, b'best') == 0:
besttime = b'NA'
if bot.duckinfo(ruser, b'best') != 0:
besttime = bot.duckinfo(ruser, b'best').encode()
accidents = bot.duckinfo(ruser, b'accidents').encode()
bread = bot.gettok(bot.duckinfo(ruser, b'bread'), 0, '?').encode()
mbread = bot.gettok(bot.duckinfo(ruser, b'bread'), 1, '?').encode()
loaf = bot.gettok(bot.duckinfo(ruser, b'bread'), 2, '?').encode()
mloaf = bot.gettok(bot.duckinfo(ruser, b'bread'), 3, '?').encode()
friend = bot.duckinfo(ruser, b'friend').encode()
if infammo == 'on':
scorebox = b'\x030,1[SCORE]\x037,1 Best Time:\x034,1 ' + besttime + b' \x030,1|\x037,1 Level:\x034,1 ' + level + b' \x030,1|\x037,1 xp:\x034,1 ' + xp + b' \x030,1|\x037,1 Ducks:\x034,1 ' + ducks + b' \x030,1|\x037,1 Golden Ducks:\x034,1 ' + gducks + b' \x030,1|\x037,1 Befriended Ducks:\x034,1 ' + friend + b' \x030,1|\x037,1 Accidents:\x034,1 ' + accidents
breadbox = b'\x030,1[BREAD BOX]\x037,1 Bread Pieces:\x034,1 ' + bread + b'/' + mbread + b' \x030,1|\x037,1 Loaf: \x02\x033Inf\x02'
gunbox = b'\x030,1[GUN STATS]\x037,1 Status:\x034,1 ' + gunstatus + b' \x030,1|\x037,1 Rounds:\x034,1 ' + rounds + b'/' + mrounds + b' \x030,1|\x037,1 Magazines: \x02\x033Inf\x02\x03 \x030,1|\x037,1 Accuracy:\x034,1 ' + accuracy + b'% \x030,1|\x037,1 Current Reliability:\x034,1 ' + reliability + b'% \x030,1|\x037,1 Max Reliability:\x034,1 ' + mreliability + b'%'
if infammo == 'off':
scorebox = b'\x038,1[SCORE]\x037,1 Best Time:\x034,1 ' + besttime + b' \x030,1|\x037,1 Level:\x034,1 ' + level + b' \x030,1|\x037,1 xp:\x034,1 ' + xp + b' \x030,1|\x037,1 Ducks:\x034,1 ' + ducks + b' \x030,1|\x037,1 Golden Ducks:\x034,1 ' + gducks + b' \x030,1|\x037,1 Befriended Ducks:\x034,1 ' + friend + b' \x030,1|\x037,1 Accidents:\x034,1 ' + accidents
breadbox = b'\x038,1[BREAD BOX]\x037,1 Bread Pieces:\x034,1 ' + bread + b'/' + mbread + b' \x030,1|\x037,1 Loaf:\x034,1 ' + loaf + b'/' + mloaf
gunbox = b'\x038,1[GUN STATS]\x037,1 Status:\x034,1 ' + gunstatus + b' \x030,1|\x037,1 Rounds:\x034,1 ' + rounds + b'/' + mrounds + b' \x030,1|\x037,1 Magazines:\x034,1 ' + mags + b'/' + mmags + b' \x030,1|\x037,1 Accuracy:\x034,1 ' + accuracy + b'% \x030,1|\x037,1 Current Reliability:\x034,1 ' + reliability + b'% \x030,1|\x037,1 Max Reliability:\x034,1 ' + mreliability + b'%'
hbe = bot.inveffect(str(ruser))
huntingbag = bot.gettok(hbe, 0, '::')
huntingbag = huntingbag.encode()
effectsbox = bot.gettok(hbe, 1, '::')
effectsbox = effectsbox.encode()
if isconnect is True:
if ext != '':
irc.send(b'PRIVMSG ' + duckchan + b' :\x038,1[DuckStats:\x037,1 ' + ruser + b'\x038,1] ' + scorebox + b' ' + gunbox + b'\r\n')
irc.send(b'PRIVMSG ' + duckchan + b' :' + breadbox + b' ' + effectsbox + b'\r\n')
irc.send(b'PRIVMSG ' + duckchan + b' :' + huntingbag + b'\r\n')
return 2
irc.send(b'NOTICE ' + user + b' :\x038,1[DuckStats:\x037,1 ' + ruser + b'\x038,1] ' + scorebox + b' ' + gunbox + b'\r\n')
irc.send(b'NOTICE ' + user + b' :' + breadbox + b' ' + effectsbox + b'\r\n')
irc.send(b'NOTICE ' + user + b' :' + huntingbag + b'\r\n')
return 1
return 0
# ===> duckstats
# FUNCTION #============================================================================================================
# Name...........: duck_timer
# Description....: Handles duck spawn and escape.
# Syntax.........: duck_timer()
# Parameters.....: None
# Return values..: None
# Author.........: Neo_Nemesis
# Modified.......:
# ======================================================================================================================
# Continuous Timer Function base - Provided by ComputerTech
# def continuous_timer():
# start_time = time.time()
# while True:
# time.sleep(1) # Wait for 1 second
# elapsed_time = time.time() - start_time
# print(f"Timer: {elapsed_time} seconds")
# main loop stuff
# timer_thread = threading.Thread(target=continuous_timer)
# timer_thread.start()
# noinspection PyUnboundLocalVariable
def duck_timer():
global exitvar
if exitvar != 'Disconnect' and exitvar != 'Disconnect2':
# global declarations
global duckexists
duckexists = False
global fear_factor
fear_factor = False
global start_time
start_time = time.time()
global elapsed_time
global duck
duck = {}
# v1.1.3-2 for SSL Eof handling
global keep_alive
keep_alive = time.time()
# assigns duck variables based off maxducks (duck timers)
for dks in range(maxducks + 1):
if dks == 0:
continue
dkey = 'd' + str(dks)
dval = 'None'
duck[dkey] = dval
# print(dkey + ': ' + duck[dkey])
continue
if exitvar == 'Connect':
exitvar = False
# timer loop
while True:
# this kills the timer on script exit or disconnect ====================================================================
if exitvar is True or exitvar == 'Disconnect':
break
# added 'Disconnect2' for SSL stuff v1.1.32
if exitvar == 'Disconnect2':
break
# duck spawn/flee timer handling =======================================================================================
if not duckhunt:
time.sleep(10)
continue
time.sleep(10) # fastest this way ¯\_(o.O)_/¯
if serverssl == 'on': # v 1.1.3-2 SSL stuff
keepalive()
elapsed_time = time.time() - start_time
# checks for duck openings and spawn/flee timers
for jx in range(maxducks + 1):
if jx == 0:
continue
# spawn a duck
if round(elapsed_time) >= spawntime:
dkey = 'd' + str(jx)
if duck[dkey] == 'None':
# determines if gold or normal duck is spawned based of duckgold value
roldgold = random.randrange(0, 100, 1)
# duck has ability to turn golden
if roldgold <= duckgold:
spawnduck(dkey, 'gold')
start_time = time.time()
break
# normal duck
if roldgold > duckgold:
spawnduck(dkey, 'normal')
start_time = time.time()
break
# duck flies away
if round(elapsed_time) >= flytime:
dkey = 'd' + str(jx)
if duck[dkey] != 'None':
elapsed_time = float(time.time()) - float(bot.gettok(duck[dkey], 0, ','))
if round(elapsed_time) >= flytime:
fleeduck(dkey)
start_time = time.time()
break
continue
# ===> duck_timer
# v.1.1.3-2 keep alive function (derived from zcore development)
def keepalive():
global keep_alive
time_result = round(time.time() - float(keep_alive))
if time_result >= 90:
print('SSL Keep Alive --> PING :PYDUCKQUACK')
irc.send(b'PING :PYDUCKQUACK\r\n')
keep_alive = time.time()
# FUNCTION #============================================================================================================
# Name...........: fleeduck
# Description....: The duck has flown away.
# Syntax.........: fleedduck(d_id)
# Parameters.....: d_id = the duck ID. d1, d2 etc.
# Return values..: None
# Author.........: Neo_Nemesis
# Modified.......:
# ======================================================================================================================
def fleeduck(d_id):
global fear_factor
duck[d_id] = 'None'
if not duck_exists():
fear_factor = False
if isconnect:
irc.send(
b"PRIVMSG " + duckchan + b" :The duck flies away. \x0314\xc2\xb7\xc2\xb0'`'\xc2\xb0-.,\xc2\xb8\xc2\xb8.\xc2\xb7\xc2\xb0'`\r\n")
# start_time = time.time()
return
# ===> fleeduck
# FUNCTION #============================================================================================================
# Name...........: ircnamesrf
# Description....: This handles the user list and parsing /NAMES command
# Syntax.........: ircnamesrf(namesdata, ext)
# Parameters.....: namesdata - the data string from /NAMES numeric 353
# ext - optional (see example below)
# Return values..: None
# Author.........: Neo_Nemesis
# Modified.......:
# Example........: ircnamesrf('String Containung User Names') - parses the list into the userlist
# ircnamesrf('0', 'r') - resets the userlist to be refreshed with new data
# ======================================================================================================================
def ircnamesrf(namesdata, ext=''):
global userlist
global userchan
names = ''
if ext == 'r':
userlist = {}
userchan = 0
return
userchan += 1
if bot.numtok(namesdata, ':') == 3:
names = bot.gettok(namesdata, 2, ':')
if bot.numtok(namesdata, ':') < 3:
names = bot.gettok(namesdata, 1, ':')
names = names.replace('@', '')
names = names.replace('&', '')
names = names.replace('~', '')
names = names.replace('!', '')
names = names.replace('%', '')
names = names.replace('+', '')
names = names.replace("b'", '')
names = names.replace("'", '')
# names = names.replace(']', '')
names = names.replace(',', '')
names = names.lower()
nd_key = 'cl' + str(userchan)
userlist[nd_key] = names
# print(' * NAMES ' + str(nd_key) + ': ' + names)
return
# ===> ircnamesrf
# FUNCTION #============================================================================================================
# Name...........: level_up
# Description....: Level's up specified player
# Syntax.........: level_up(user)
# Parameters.....: user - username to be leveled up
# Return values..: None
# Author.........: Neo_Nemesis
# Modified.......:
# Remarks........: Update 1.1.0 - recoded, changed prizes and altered levelup values
# ======================================================================================================================
# noinspection PyShadowingNames
def level_up(user):
# increase level by 1
level = bot.duckinfo(user, b'level')
level = int(level) + 1
bot.duckinfo(user, b'level', str(level))
# increase level up
xp = bot.duckinfo(user, b'xp')
levelup = int(xp) + 800
if int(xp) > 10000:
levelup = int(xp) + 2400
if 10000 > int(xp) > 5000:
levelup = int(xp) + 1600
bot.duckinfo(user, b'levelup', str(levelup))
global bang
bang = bot.cnfread('duckhunt.cnf', 'rules', 'bang')
# determine prize
drawprize = random.randint(1, 4)
prize = ''
prizedesc = ''
# prize 1 full ammo (or full bread)
if drawprize == 1:
if bang == 'on':
prize = 'Ammo Fill-up'
prizedesc = 'Ammo has been filled.'
# fill ammo
ammo = bot.duckinfo(user, b'ammo')
mrounds = bot.gettok(ammo, 2, '?')
rounds = mrounds
mmags = bot.gettok(ammo, 3, '?')
mags = mmags
ammo = rounds + '?' + mags + '?' + mrounds + '?' + mmags
bot.duckinfo(user, b'ammo', str(ammo))
if bang == 'off':
prize = 'Bread Fill-up'
prizedesc = 'Bread has been filled.'
# fill bread
breadbox = bot.duckinfo(user, b'bread')
mbread = bot.gettok(breadbox, 1, '?')
mloaf = bot.gettok(breadbox, 3, '?')
bread = mbread
loaf = mloaf
breadbox = bread + '?' + mbread + '?' + loaf + '?' + mloaf
bot.duckinfo(user, b'bread', str(breadbox))
# prize 2 rain coat
if drawprize == 2:
prize = 'Rain Coat'
prizedesc = 'This will prevent getting soggy and sheild against a duck bomb for 24 hours.'
bot.cnfwrite('duckhunt.cnf', 'rain_coat', str(user), str(time.time()))
# prize 3 sunglasses
if drawprize == 3:
prize = 'Sunglasses'
prizedesc = 'You are protected from bedazzlement for 24 hours.'
bot.cnfwrite('duckhunt.cnf', 'sunglasses', str(user), str(time.time()))
# prize 4 bread or duck booklet
if drawprize == 4:
if bang == 'on':
prize = 'Bread Fill-up'
prizedesc = 'Bread has been filled.'
# fill bread
breadbox = bot.duckinfo(user, b'bread')
mbread = bot.gettok(breadbox, 1, '?')
mloaf = bot.gettok(breadbox, 3, '?')
bread = mbread
loaf = mloaf
breadbox = bread + '?' + mbread + '?' + loaf + '?' + mloaf
bot.duckinfo(user, b'bread', str(breadbox))
if bang == 'off':
prize = 'Duck Booklet'
prizedesc = 'The booklet earns an extra 45 xp!'
xp = bot.duckinfo(user, b'xp')
xp = int(xp) + 45
bot.duckinfo(user, b'xp', str(xp))
irc.send(b'PRIVMSG ' + duckchan + b' :' + username + b' > Has leveled up! ' + username + b' has reached level ' + bytes(str(level), 'utf-8') + b'! Prize won: ' + bytes(str(prize), 'utf-8') + b'. ' + bytes(str(prizedesc), 'utf-8') + b'\r\n')
return
# ===> level_up
# FUNCTION #============================================================================================================
# Name...........: namecheck
# Description....: checks the userlist for a username
# Syntax.........: namecheck(username)
# Parameters.....: username - the named to be searched for in user list
# Return values..: Returns True - user exists in user list (on channel)
# Returns False - user does not exist in user list (not on channel)
# Author.........: Neo_Nemesis
# Modified.......:
# ======================================================================================================================
def namecheck(name):
# namech = name.replace("b'", '')
# namech = namech.replace("'", '')
namech = name.lower()
# print('userchan ' + str(userchan))
nnx = 1
while nnx <= userchan:
nd_key = 'cl' + str(nnx)
print('NAMES: ' + str(userlist[nd_key]))
if bot.istok(userlist[nd_key], namech, ' '):
return True
if bot.istok(userlist[nd_key], namech + ']', ' '):
return True
nnx += 1
continue
return False
# ===> namecheck
# FUNCTION #============================================================================================================
# Name...........: shopmenu
# Description....: Builds and sends the shop menu to user
# Syntax.........: shopmenu(user)
# Parameters.....: user - requesting username
# Return values..: None
# Author.........: Neo_Nemesis
# Modified.......:
# ======================================================================================================================
def shopmenu(user, opt=''):
# ammo = bot.duckinfo(user, b'ammo')
# rounds = bot.gettok(ammo, 0, '?')
# mags = bot.gettok(ammo, 1, '?')
# mrounds = bot.gettok(ammo, 2, '?')
# mmags = bot.gettok(ammo, 3, '?')
# single bullet
shop1 = '1:\x037,1 Single Round\x034,1 (' + str(bot.shopprice(user, 1)) + ' xp)'
if infammo == 'on':
shop1 = '1:\x0314,1 Single Round (' + str(bot.shopprice(user, 1)) + ' xp)'
# refill magazine
shop2 = '2:\x037,1 Refill Magazine\x034,1 (' + str(bot.shopprice(user, 2)) + ' xp)'
if infammo == 'on':
shop2 = '2:\x0314,1 Refill Magazine (' + str(bot.shopprice(user, 2)) + ' xp)'
# gun cleaning
shop3 = '3:\x037,1 Gun Cleaning\x034,1 (' + str(bot.shopprice(user, 3)) + ' xp)'
# explosive ammo
shop4 = '4:\x037,1 Explosive Ammo\x034,1 (' + str(bot.shopprice(user, 4)) + ' xp)'
# return confiscated gun
shop5 = '5:\x037,1 Return Confiscated Gun\x034,1 (' + str(bot.shopprice(user, 5)) + ' xp)'
if gunconf == 'off':
shop5 = '5:\x0314,1 Return Confiscated Gun (' + str(bot.shopprice(user, 5)) + ' xp)'
# gun grease
shop6 = '6:\x037,1 Gun Grease\x034,1 (' + str(bot.shopprice(user, 6)) + ' xp)'
# gun upgrade
shop7 = '7:\x037,1 Gun Upgrade\x034,1 (' + str(bot.shopprice(user, 7)) + ' xp)'
# Gun Lock
shop8 = '8:\x037,1 Gun Lock\x034,1 (' + str(bot.shopprice(user, 8)) + ' xp)'
# silencer
shop9 = '9:\x037,1 Silencer\x034,1 (' + str(bot.shopprice(user, 9)) + ' xp)'
# lucky charm
shop10 = '10:\x037,1 Lucky Charm\x034,1 (' + str(bot.shopprice(user, 10)) + ' xp)'
# sunglasses
shop11 = '11:\x037,1 Sunglasses\x034,1 (' + str(bot.shopprice(user, 11)) + ' xp)'
# new clothes
shop12 = '12:\x037,1 New Clothes\x034,1 (' + str(bot.shopprice(user, 12)) + ' xp)'
# eye drops
shop13 = '13:\x037,1 Eye Drops\x034,1 (' + str(bot.shopprice(user, 13)) + ' xp)'
# mirror
shop14 = '14:\x037,1 Mirror\x034,1 (' + str(bot.shopprice(user, 14)) + ' xp)'
# handful of sand
shop15 = '15:\x037,1 Handful of Sand\x034,1 (' + str(bot.shopprice(user, 15)) + ' xp)'
# water bucket
shop16 = '16:\x037,1 Water Bucket\x034,1 (' + str(bot.shopprice(user, 16)) + ' xp)'
# sabotage
shop17 = '17:\x037,1 Sabotage\x034,1 (' + str(bot.shopprice(user, 17)) + ' xp)'
# accident insurance
shop18 = '18:\x037,1 Accident Insurance\x034,1 (' + str(bot.shopprice(user, 18)) + ' xp)'
if gunconf == 'off':
shop18 = '18:\x0314,1 Accident Insurance (' + str(bot.shopprice(user, 18)) + ' xp)'
# loaf of bread
shop19 = '19:\x037,1 Loaf of Bread\x034,1 (' + str(bot.shopprice(user, 19)) + ' xp)'
if infammo == 'on':
shop19 = '19:\x0314,1 Loaf of Bread (' + str(bot.shopprice(user, 19)) + ' xp)'
# bag of popcorn
shop20 = '20:\x037,1 Bag of Popcorn\x034,1 (' + str(bot.shopprice(user, 20)) + ' xp)'
# bread box lock
shop21 = '21:\x037,1 Bread Box Lock\x034,1 (' + str(bot.shopprice(user, 21)) + ' xp)'
# rain coat
shop22 = '22:\x037,1 Rain Coat\x034,1 (' + str(bot.shopprice(user, 22)) + ' xp)'
# magazine upgrade
shop23 = '23:\x037,1 Magazine Upgrade\x034,1 (' + str(bot.shopprice(user, 23)) + ' xp)'
# additional magazine
shop24 = '24:\x037,1 Additional Magazine\x034,1 (' + str(bot.shopprice(user, 24)) + ' xp)'
if infammo == 'on':
shop24 = '24:\x0314,1 Additional Magazine (' + str(bot.shopprice(user, 24)) + ' xp)'
# prepares menus
# !bang off !bef on menu
if bang == 'off' and bef == 'on':
menu1 = '\x038,1[Shop Menu]\x034,1 ' + shop10 + ' \x037,1|\x034,1 ' + shop11 + ' \x037,1|\x034,1 ' + shop12 + ' \x037,1|\x034,1 ' + shop13 + ' \x037,1|\x034,1 ' + shop14
menu2 = '\x038,1[Shop Menu]\x034,1 ' + shop16 + ' \x037,1|\x034,1 ' + shop19 + ' \x037,1|\x034,1 ' + shop20 + ' \x037,1|\x034,1 ' + shop21 + ' \x037,1|\x034,1 ' + shop22
if opt != '':
irc.send(b'PRIVMSG ' + duckchan + b' :' + bytes(str(menu1), 'utf-8') + b'\r\n')
irc.send(b'PRIVMSG ' + duckchan + b' :' + bytes(str(menu2), 'utf-8') + b'\r\n')
irc.send(b'PRIVMSG ' + duckchan + b' :\x034,1Syntax:\x037,1 !shop \x037,1[\x037,1id\x037,1] [\x037,1target\x037,1]\r\n')
return
irc.send(b'NOTICE ' + username + b' :' + bytes(str(menu1), 'utf-8') + b'\r\n')
irc.send(b'NOTICE ' + username + b' :' + bytes(str(menu2), 'utf-8') + b'\r\n')
irc.send(b'NOTICE ' + username + b' :\x034,1Syntax:\x037,1 !shop \x037,1[\x037,1id\x037,1] [\x037,1target\x037,1]\r\n')
return
# !bang on !bef off menu
elif bang == 'on' and bef == 'off':
menu1 = '\x038,1[Shop Menu]\x034,1 ' + shop1 + ' \x037,1|\x034,1 ' + shop2 + ' \x037,1|\x034,1 ' + shop3 + ' \x037,1|\x034,1 ' + shop4 + ' \x037,1|\x034,1 ' + shop5 + ' \x037,1|\x034,1 ' + shop6 + ' \x037,1|\x034,1 ' + shop7 + ' \x037,1|\x034,1 ' + shop8 + ' \x037,1|\x034,1 ' + shop9 + ' \x037,1|\x034,1 ' + shop10
menu2 = '\x038,1[Shop Menu]\x034,1 ' + shop11 + ' \x037,1|\x034,1 ' + shop12 + ' \x037,1|\x034,1 ' + shop13 + ' \x037,1|\x034,1 ' + shop14 + ' \x037,1|\x034,1 ' + shop15 + ' \x037,1|\x034,1 ' + shop16 + ' \x037,1|\x034,1 ' + shop17 + ' \x037,1|\x034,1 ' + shop18 + ' \x037,1|\x034,1 ' + shop22
menu3 = '\x038,1[Shop Menu]\x034,1 ' + shop23 + ' \x037,1|\x034,1 ' + shop24
if opt != '':
irc.send(b'PRIVMSG ' + duckchan + b' :' + bytes(str(menu1), 'utf-8') + b'\r\n')
irc.send(b'PRIVMSG ' + duckchan + b' :' + bytes(str(menu2), 'utf-8') + b'\r\n')
irc.send(b'PRIVMSG ' + duckchan + b' :' + bytes(str(menu3), 'utf-8') + b'\r\n')
irc.send(b'PRIVMSG ' + duckchan + b' :\x034,1Syntax:\x037,1 !shop \x037,1[\x037,1id\x037,1] [\x037,1target\x037,1]\r\n')
return
irc.send(b'NOTICE ' + username + b' :' + bytes(str(menu1), 'utf-8') + b'\r\n')
irc.send(b'NOTICE ' + username + b' :' + bytes(str(menu2), 'utf-8') + b'\r\n')
irc.send(b'NOTICE ' + username + b' :' + bytes(str(menu3), 'utf-8') + b'\r\n')
irc.send(b'NOTICE ' + username + b' :\x034,1Syntax:\x037,1 !shop \x037,1[\x037,1id\x037,1] [\x037,1target\x037,1]\r\n')
return
# normal menu (!bang on, !bef on,
elif bang == 'on' and bef == 'on':
menu1 = '\x038,1[Shop Menu]\x034,1 ' + shop1 + ' \x037,1|\x034,1 ' + shop2 + ' \x037,1|\x034,1 ' + shop3 + ' \x037,1|\x034,1 ' + shop4 + ' \x037,1|\x034,1 ' + shop5 + ' \x037,1|\x034,1 ' + shop6 + ' \x037,1|\x034,1 ' + shop7 + ' \x037,1|\x034,1 ' + shop8 + ' \x037,1|\x034,1 ' + shop9 + ' \x037,1|\x034,1 ' + shop10
menu2 = '\x038,1[Shop Menu]\x034,1 ' + shop11 + ' \x037,1|\x034,1 ' + shop12 + ' \x037,1|\x034,1 ' + shop13 + ' \x037,1|\x034,1 ' + shop14 + ' \x037,1|\x034,1 ' + shop15 + ' \x037,1|\x034,1 ' + shop16 + ' \x037,1|\x034,1 ' + shop17 + ' \x037,1|\x034,1 ' + shop18 + ' \x037,1|\x034,1 ' + shop19 + ' \x037,1|\x034,1 ' + shop20
menu3 = '\x038,1[Shop Menu]\x034,1 ' + shop21 + ' \x037,1|\x034,1 ' + shop22 + ' \x037,1|\x034,1 ' + shop23 + ' \x037,1|\x034,1 ' + shop24
if opt != '':
irc.send(b'PRIVMSG ' + duckchan + b' :' + bytes(str(menu1), 'utf-8') + b'\r\n')
irc.send(b'PRIVMSG ' + duckchan + b' :' + bytes(str(menu2), 'utf-8') + b'\r\n')
irc.send(b'PRIVMSG ' + duckchan + b' :' + bytes(str(menu3), 'utf-8') + b'\r\n')
irc.send(b'PRIVMSG ' + duckchan + b' :\x034,1Syntax:\x037,1 !shop \x037,1[\x037,1id\x037,1] [\x037,1target\x037,1]\r\n')
return
irc.send(b'NOTICE ' + username + b' :' + bytes(str(menu1), 'utf-8') + b'\r\n')
irc.send(b'NOTICE ' + username + b' :' + bytes(str(menu2), 'utf-8') + b'\r\n')
irc.send(b'NOTICE ' + username + b' :' + bytes(str(menu3), 'utf-8') + b'\r\n')
irc.send(b'NOTICE ' + username + b' :\x034,1Syntax:\x037,1 !shop \x037,1[\x037,1id\x037,1] [\x037,1target\x037,1]\r\n')
return
# ===> shopmenu
# FUNCTION #============================================================================================================
# Name...........: spawnduck
# Description....: spawns a duck into chat, if maxducks is not reached
# Syntax.........: spawnduck(d_id, type)
# Parameters.....: d_id = the duck ID. d1, d2 etc
# type = normal or gold
# Return values..: None
# Author.........: Neo_Nemesis
# Modified.......:
# ======================================================================================================================
def spawnduck(d_id, d_type):
global fear_factor
if duck[d_id] == 'None':
duck_dat = str(time.time()) + ',' + d_type
duck[d_id] = str(duck_dat)
if fear_factor is False:
fear_factor = 0
if isconnect:
irc.send(b'PRIVMSG ' + duckchan + b" :\x0314-.,\xc2\xb8\xc2\xb8.-\xc2\xb7\xc2\xb0'`'\xc2\xb0\xc2\xb7-.,\xc2\xb8\xc2\xb8.-\xc2\xb7\xc2\xb0'`'\xc2\xb0\xc2\xb7\x0f \x02\\_O<\x02 \x0314QUACK\x0f\r\n")
# start_time = time.time()
return
# ===> spawnduck
# FUNCTION #============================================================================================================
# Name...........: topduck
# Description....: Displays the current top 5 players (could use refining, but works)
# Syntax.........: topduck()
# Parameters.....: None
# Return values..: None - displays topduck message in duckchan
# Author.........: Neo_Nemesis
# Modified.......:
# ======================================================================================================================
def topduck():
# No players?
if bot.cnfread('duckhunt.cnf', 'ducks', 'cache') == '0':
irc.send(b'PRIVMSG ' + duckchan + b' :There are currently no top ducks.\r\n')
return 1
# Gather score information - rank by ducks shot (token 1)
parser = RawConfigParser()
parser.read('duckhunt.cnf')
scores = []
for name, value in parser.items('ducks'):
datkey = '%s' % name
if datkey == 'cache':
continue
dat = bot.cnfread('duckhunt.cnf', 'ducks', datkey)
ducks = int(bot.gettok(dat, 1, ','))
if ducks == 0:
continue
# Strip legacy b'...' wrapper from keys written by older versions
nick = datkey.strip("b'\"")
scores.append((ducks, nick))
if not scores:
irc.send(b'PRIVMSG ' + duckchan + b' :There are currently no top ducks.\r\n')
return 1
# Sort by ducks descending, take top 5
scores.sort(key=lambda x: x[0], reverse=True)
scores = scores[:5]
if len(scores) == 1:
if isconnect:
msg = 'The top duck is: ' + scores[0][1] + ' ' + str(scores[0][0]) + ' ducks'
irc.send(b'PRIVMSG ' + duckchan + b' :' + bytes(msg, 'utf-8') + b'\r\n')
return 1
parts = [s[1] + ' ' + str(s[0]) + ' ducks' for s in scores]
topdmsg = ' | '.join(parts)
if isconnect:
irc.send(b'PRIVMSG ' + duckchan + b' :The top ducks are: ' + bytes(topdmsg, 'utf-8') + b'\r\n')
# ===> topduck
# FUNCTION #============================================================================================================
# Name...........: top_shot
# Description....: manages the shot ducks statistics for daily, weekly, monthly and all time.
# Syntax.........: top_shot()
# Parameters.....: None
# Return values..: None
# Author.........: Neo_Nemesis
# Modified.......:
# ======================================================================================================================
def top_shot():
global daily
global weekly
global monthly
global totalshot
global month
global week
global day
daily = bot.cnfread('duckhunt.cnf', 'top_shot', 'daily')
weekly = bot.cnfread('duckhunt.cnf', 'top_shot', 'weekly')
monthly = bot.cnfread('duckhunt.cnf', 'top_shot', 'monthly')
totalshot = bot.cnfread('duckhunt.cnf', 'top_shot', 'totalshot')
month = bot.cnfread('duckhunt.cnf', 'top_shot', 't_month')
week = bot.cnfread('duckhunt.cnf', 'top_shot', 't_week')
day = bot.cnfread('duckhunt.cnf', 'top_shot', 't_day')
current_day = bot.gettok(str(date.today()), 2, '-')
current_week = date.today().isocalendar()[1]
current_month = bot.gettok(str(date.today()), 1, '-')
if str(current_day) != str(day):
bot.debug('0', 'The total shots for the day has been automatically reset for a new day.')
day = current_day
bot.cnfwrite('duckhunt.cnf', 'top_shot', 't_day', str(day))
if isconnect is True and duckhunt is True:
irc.send(b'PRIVMSG ' + duckchan + b' :Total ducks shot for yesterday: ' + bytes(str(daily), 'utf-8') + b' The daily total shots has been reset for a new day!\r\n')
daily = 0
bot.cnfwrite('duckhunt.cnf', 'top_shot', 'daily', str(daily))
if str(current_week) != str(week):
bot.debug('0', 'The total shots for the week has been automatically reset for a new week.')
week = current_week
bot.cnfwrite('duckhunt.cnf', 'top_shot', 't_week', str(week))
if isconnect is True and duckhunt is True:
irc.send(b'PRIVMSG ' + duckchan + b' :Total ducks shot for last week: ' + bytes(str(weekly), 'utf-8') + b' The weekly total shots has been reset for a new week!\r\n')
weekly = 0
bot.cnfwrite('duckhunt.cnf', 'top_shot', 'weekly', str(weekly))
if str(current_month) != str(month):
month = current_month
bot.cnfwrite('duckhunt.cnf', 'top_shot', 't_month', str(month))
if isconnect is True and duckhunt is True:
irc.send(b'PRIVMSG ' + duckchan + b' :Total ducks shot for last month: ' + bytes(str(monthly), 'utf-8') + b' The monthly total shots has been reset for a new month!\r\n')
monthly = 0
bot.cnfwrite('duckhunt.cnf', 'top_shot', 'monthly', str(monthly))
return
# ===> top_shot
# for UTF error fix v1.1.3
def utfix(datatext):
try:
datatext.decode()
# print('UTFIX: True')
return True
except UnicodeError:
# print('UTFIX: False')
return False
# for SSL error handling (EOF errors??) band-aid pt 1.
# Forces bot to disconnect and reconnect. v.1.1.3-2
def ssl_err(args):
global exitvar
# irc.send(b'QUIT :Restarting...\r\n')
exitvar = 'Disconnect2'
# irc.close()
# irc.send(b'QUIT :SSL connection error has forced the bot to restart...\r\n')
print(f'*** SSL Error: {args.exc_value}')
print(f'*** RESTARTING....')
return
# for SSL error handling (EOF errors??) band-aid pt 2. (Crash prevent?)
# After ssl_err(args) is complete, this begins the reconnection process. v1.1.3-2
def err_reconnect():
global irc
global exitvar
exitvar = 'Connect'
irc.close()
time.sleep(3)
irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
irc.connect((server, port))
if serverssl == 'on':
scontext = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
scontext.check_hostname = False
scontext.verify_mode = ssl.CERT_NONE
scontext.verify_opt = ssl.OP_NO_TLSv1_3
irc = scontext.wrap_socket(irc, server_hostname=server)
irc.send(b"USER " + botname + b" " + botname + b" " + botname + b" :Super DuckHunt Python Version by Neo_Nemesis\r\n")
irc.send(b"NICK " + botname + b"\r\n")
if str(botpass) != '0':
irc.send(b'PASS ' + bytes(str(botpass), 'utf-8') + b'\r\n')
# FUNCTION #============================================================================================================
# Name...........: resetdef
# Description....: Restores duckhunt.cnf to pre-configured original settings
# Syntax.........: resetdef()
# ======================================================================================================================
def resetdef():
bot.cnfwrite('duckhunt.cnf', 'duckhunt', 'maxducks', '6')
global maxducks
maxducks = 6
bot.cnfwrite('duckhunt.cnf', 'duckhunt', 'spawntime', '1800')
global spawntime
spawntime = 1800
bot.cnfwrite('duckhunt.cnf', 'duckhunt', 'flytime', '1500')
global flytime
flytime = 1500
bot.cnfwrite('duckhunt.cnf', 'duckhunt', 'duckexp', '15')
global duckexp
duckexp = 15
bot.cnfwrite('duckhunt.cnf', 'duckhunt', 'duckfear', '45')
global duckfear
duckfear = 45
bot.cnfwrite('duckhunt.cnf', 'duckhunt', 'duckgold', '40')
global duckgold
duckgold = 40
bot.cnfwrite('duckhunt.cnf', 'duckhunt', 'friendrate', '70')
global friendrate
friendrate = 70
bot.cnfwrite('duckhunt.cnf', 'duckhunt', 'floodcheck', '10,8')
global flood_check
flood_check = True
bot.cnfwrite('duckhunt.cnf', 'rules', 'gunricochet', '5')
global gunricochet
gunricochet = 5
bot.cnfwrite('duckhunt.cnf', 'rules', 'thebushes', '15')
global thebushes
thebushes = 15
bot.cnfwrite('duckhunt.cnf', 'rules', 'gunconf', 'on')
global gunconf
gunconf = 'on'
bot.cnfwrite('duckhunt.cnf', 'rules', 'infammo', 'off')
global infammo
infammo = 'off'
bot.cnfwrite('duckhunt.cnf', 'rules', 'bang', 'on')
global bang
bang = 'on'
bot.cnfwrite('duckhunt.cnf', 'rules', 'bef', 'on')
global bef
bef = 'on'
bot.cnfwrite('duckhunt.cnf', 'duckhunt', 'maint', '24')
global maint
maint = '24'
bot.cnfwrite('duckhunt.cnf', 'duckhunt', 'maint_time', str(time.time()))
global maint_time
maint_time = str(time.time())
time.sleep(0.10)
parser = RawConfigParser()
parser.read('duckhunt.cnf')
for name, value in parser.items('flood_protection'):
datkey = '%s' % name
bot.cnfdelete('duckhunt.cnf', 'flood_protection', str(datkey))
continue
time.sleep(0.10)
bot.cnfwrite('duckhunt.cnf', 'flood_protection', '!bang', 'True')
bot.cnfwrite('duckhunt.cnf', 'flood_protection', '!duckstats', 'True')
bot.cnfwrite('duckhunt.cnf', 'flood_protection', '!shop', 'True')
bot.cnfwrite('duckhunt.cnf', 'flood_protection', '!bef', 'True')
bot.cnfwrite('duckhunt.cnf', 'flood_protection', '!reload', 'True')
bot.cnfwrite('duckhunt.cnf', 'flood_protection', '!bomb', 'True')
bot.cnfwrite('duckhunt.cnf', 'flood_protection', '!tshot', 'True')
bot.cnfwrite('duckhunt.cnf', 'flood_protection', '!mshot', 'True')
bot.cnfwrite('duckhunt.cnf', 'flood_protection', '!help', 'True')
bot.cnfwrite('duckhunt.cnf', 'flood_protection', '!swim', 'True')
bot.cnfwrite('duckhunt.cnf', 'flood_protection', '!wshot', 'True')
bot.cnfwrite('duckhunt.cnf', 'flood_protection', '!dshot', 'True')
bot.cnfwrite('duckhunt.cnf', 'flood_protection', '!about', 'True')
bot.cnfwrite('duckhunt.cnf', 'flood_protection', '!topduck', 'True')
bot.cnfwrite('duckhunt.cnf', 'flood_protection', '!reloaf', 'True')
bot.cnfwrite('duckhunt.cnf', 'flood_protection', '!bread', 'True')
bot.cnfwrite('duckhunt.cnf', 'flood_protection', '\x01version\x01', 'True')
bot.cnfwrite('duckhunt.cnf', 'flood_protection', '\x01finger\x01', 'True')
bot.cnfwrite('duckhunt.cnf', 'flood_protection', '\x01ping', 'True')
bot.cnfwrite('duckhunt.cnf', 'flood_protection', 'version', 'True')
bot.cnfwrite('duckhunt.cnf', 'flood_protection', 'finger', 'True')
bot.cnfwrite('duckhunt.cnf', 'flood_protection', 'ping', 'True')
time.sleep(0.10)
resetshot()
time.sleep(0.10)
statreset()
return
# ===> resetdef
# ======================================================================================================================
# MAIN LOOP STUFF
# ======================================================================================================================
print(f'Super DuckHunt {botversion} by Mode60/Neo Nemesis is starting up!')
# ======================================================================================================================
# Connect to server
# ======================================================================================================================
irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
irc.connect((server, port))
if serverssl == 'on':
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE
irc = context.wrap_socket(irc, server_hostname=server)
irc.send(b"USER " + botname + b" " + botname + b" " + botname + b" :Super DuckHunt by Neo_Nemesis\r\n")
irc.send(b"NICK " + botname + b"\r\n")
if str(botpass) != '0':
irc.send(b'PASS ' + bytes(str(botpass), 'utf-8') + b'\r\n')
# ======================================================================================================================
# main loop - start
# ======================================================================================================================
while 1:
# if bot gets disocnnect, will attempt to reconnect.
# Added 'Disconnect2' for adding SSL v1.1.3-2
if exitvar == 'Disconnect' or exitvar == 'Disconnect2':
if exitvar == 'Disconnect2':
err_reconnect()
continue
time.sleep(5)
exitvar = 'Connect'
irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
irc.connect((server, port))
if serverssl == 'on':
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE
context.verify_opt = ssl.OP_NO_TLSv1_3
irc = context.wrap_socket(irc, server_hostname=server)
irc.send(b"USER " + botname + b" " + botname + b" " + botname + b" :Super DuckHunt Python Version by Neo_Nemesis\r\n")
irc.send(b"NICK " + botname + b"\r\n")
if botpass != '0':
irc.send(b'PASS ' + bytes(str(botpass), 'utf-8') + b'\r\n')
continue
# total shots timer
if isconnect and duckhunt is True:
# determine bot maintenance
if bot.cnfread('duckhunt.cnf', 'duckhunt', 'maint') != '0':
maint_time = bot.cnfread('duckhunt.cnf', 'duckhunt', 'maint_time')
cmtime = time.time() - float(maint_time)
if float(cmtime) >= float(bot.hourtosec(maint)):
if duckhunt is True:
duckhunt = False
irc.send(b'PRIVMSG ' + duckchan + b' :DuckHunt is temporarily off-line for routine scheduled bot maintenance. Please wait, this will only take a moment...\r\n')
bot.cnfcleanup()
bot.cnfwrite('duckhunt.cnf', 'duckhunt', 'maint_time', str(time.time()))
if duckhunt is False:
duckhunt = True