-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot_body.py
2042 lines (1898 loc) · 107 KB
/
bot_body.py
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
# from logging import FATAL
import sys
from random import randint, choice
import socket
# import json
# from urllib import request
import datetime
import time
import ast
import requests
# from attr import NOTHING
from anyascii import anyascii
import loader
from wfrpgame import tcChargen, game_manager, character_manager
from utils import twitter, commands, quotes, soundcommands, deathcounter, excuse
from chattodb import social_ad, get_active_list
import myTwitch
# import wfrpgame
# import song_request
# import playlist_maker
# Set deathcounter off at init.
death_counter = False
# Method for sending a message
def Send_message(message, *args):
time.sleep(1)
if " ^user " in message:
# print("Message: ", message)
# print(args[0])
message = message.replace(" ^user ", " " + str(args[0]) + " ")
args = []
if " ^user.upper " in message:
# print("Message: ", message)
# print(args[0])
message = message.replace(" ^user.upper", " " + str(args[0]).upper() + " ")
args = []
if "^target" in message:
# print("Message:", message)
# print(args[0])
message = message.replace("^target", str(args[0]))
args = []
args = []
if not args:
try:
s.send(("PRIVMSG #" + chan + " :" + message + "\r\n").encode("UTF-8"))
except ConnectionResetError:
print("there was a connection reset error")
else:
s.send(("PRIVMSG #" + args[0] + " :" + message + "\r\n").encode("UTF-8"))
def ret_char(username):
char_to_return = None
try:
char_to_return = c.execute(
"select gchar from users where uname = ?", (username,)
).fetchone()[0]
if (
c.execute(
"select status from users where uname = ?", (username,)
).fetchone()[0]
== "bot"
):
char_to_return = ""
except TypeError:
print("User in channel that has not been added to the database yet: ", username)
char_to_return = ""
finally:
if char_to_return == "":
return "None"
else:
return ast.literal_eval(char_to_return)
def change_race(username, change_char):
exp = (
int(
c.execute("select exp from users where uname = ?", (username,)).fetchone()[
0
]
)
- 100
)
c.execute("update users set gchar = ? where uname = ?", (change_char, username))
c.execute("update users set exp = ? where uname = ?", (exp, username))
conn.commit()
def enumerate_users(ulist):
lusers = [user[1]["user_login"] for user in enumerate(eval(ulist)["data"])]
# print(lusers)
return lusers
def get_elevated_users(target):
# resp = request.urlopen(f"http://tmi.twitch.tv/group/user/{target}/chatters")
# chatters_all=f"https://api.twitch.tv/helix/chat/chatters?broadcaster_id={bcasterId}&moderator_id={moderatorId}"
vips = f"https://api.twitch.tv/helix/channels/vips?broadcaster_id={bcasterId}"
moderators = (
f"https://api.twitch.tv/helix/moderation/moderators?broadcaster_id={bcasterId}"
)
h2 = {
"Client-ID": ClientID,
"Accept": "application/vnd.twitchtv.v5+json",
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": "Bearer " + OAuthBearer,
}
# chatters = requests.get(url=chatters_all, headers=h1)
viplist = requests.get(url=vips, headers=h2)
modlist = requests.get(url=moderators, headers=h2)
# chatters_json = chatters.content.decode("UTF-8")
vips_json = viplist.content.decode("UTF-8")
mods_json = modlist.content.decode("UTF-8")
# chatters = enumerate_users(chatters_json)
viplist = enumerate_users(vips_json)
modlist = enumerate_users(mods_json)
# print(chatters)
# print(viplist)
# print(modlist)
modlist.append("rhyle_")
eusers = viplist, modlist
eaccess = set([user for sublist in eusers for user in sublist])
return eaccess
def challenge(challenger, victim, amount):
pass
def challenge_result(user, amount, *args):
"""
Used to modify the XP as a result of a pvp challenge.
:param user:
:param amount:
:param other_user:
:return:
"""
winner_exp = int(
c.execute("select exp from users where uname = ?", (user,)).fetchone()[0]
)
loser_exp = 0
if not args:
pass
else:
loser_exp = int(
c.execute("select exp from users where uname = ?", (*args,)).fetchone()[0]
)
loser_exp -= int(amount)
if loser_exp < 0:
loser_exp = 0
c.execute("update users set exp = ? where uname = ?", (loser_exp, *args))
conn.commit()
winner_exp += int(amount)
c.execute("update users set exp = ? where uname = ?", (winner_exp, user))
conn.commit()
def uptime(at_command_time):
return at_command_time - bot_start
def shop(username, *args):
from wfrpgame import itemlist
shoplist = itemlist.load_shop()
shop_items_list = []
shop_message = ""
if not args:
shop_message = (
f"/w {username} Welcome to the shop! The following commands are necessary for using the shop: "
f"(!)shop melee, ranged, armor, or healing will show you the available equipment. (!)shop buy followed by the item you would "
f"like to purchase will allow you to purchase that specific item assuming that you have the available crowns."
)
# elif 'melee' in args[0].lower().strip('\r').strip('\n') or 'ranged' in args[0].lower().strip('\r').strip('\n') or 'armor' in args[0].lower().strip('\r').strip('\n'):
elif (
args[0].lower().strip("\r\n") == "melee"
or args[0].lower().strip("\r\n") == "ranged"
or args[0].lower().strip("\r\n") == "armor"
or args[0].lower().strip("\r\n") == "healing"
):
[
shop_items_list.append(f"[{item}]: {shoplist[item]['cost']}")
for item in shoplist
if args[0].lower().strip("\r\n") in shoplist[item]["type"].lower()
]
shop_items = " || ".join(shop_items_list)
shop_message = f"/w {username} The available items are as follows: {shop_items}"
elif "buy" in args[0].lower():
shopper = ret_char(username)
_, shopper_purse, _ = game_manager.get_user_exp(c, username)
if len(args) != 2:
shop_message = "I'm sorry, I didn't understand that, please try again."
else:
new_item = args[1].lower().strip("\r\n")
if new_item not in shoplist:
shop_message = "No item exists that with that name, please look at the (!)shop melee, (!)shop armor or (!)shop ranged list again."
return
crown_cost = shoplist[args[1].lower().strip("\r\n")]["cost"].split(" ")
if int(shopper_purse) >= int(crown_cost[0]):
# Item can be purchased
if (
shoplist[new_item.lower()]["type"] == "Melee"
or shoplist[new_item.lower()]["type"] == "Ranged"
):
shopper["weapon"] = args[1]
c.execute(
"update users set crowns = ? where uname = ?",
(int(shopper_purse) - int(crown_cost[0]), username),
)
c.execute(
"update users set gchar = ? where uname = ?",
(str(shopper), username),
)
conn.commit()
shop_message = shop_message = (
f"/w {username} You brandish your new {args[1]}. It fits your hands "
f"as though it was made for you."
)
elif shoplist[new_item.lower()]["type"] == "Armor":
shopper["armor"] = args[1]
c.execute(
"update users set crowns = ? where uname = ?",
(int(shopper_purse) - int(crown_cost[0]), username),
)
c.execute(
"update users set gchar = ? where uname = ?",
(str(shopper), username),
)
conn.commit()
shop_message = shop_message = (
f"/w {username} You don your new {args[1]}. The armor fits "
f"as though it was made for you."
)
elif shoplist[new_item.lower()]["type"] == "Healing":
# Get Current and Max wounds
(current_wounds, max_wounds) = c.execute(
"select CurrentWounds, MaxWounds from users where uname = ?",
(username,),
).fetchone()
# print(shoplist[new_item.lower()]['damage'])
# Add potions healing to current wounds up to Max Wounds.
if (
current_wounds
+ int(shoplist[new_item.lower()]["damage"].split(" ")[0])
>= max_wounds
):
current_wounds = max_wounds
else:
current_wounds += int(
shoplist[new_item.lower()]["damage"].split(" ")[0]
)
# Charge the purse
c.execute(
"update users set crowns = ? where uname = ?",
(int(shopper_purse) - int(crown_cost[0]), username),
)
c.execute(
"update users set gchar = ? where uname = ?",
(str(shopper), username),
)
c.execute(
"update users set CurrentWounds = ? where uname = ?",
(current_wounds, username),
)
conn.commit()
shop_message = f"/w {username} You quaff down the {args[1]}, you begin to feel much better. ({current_wounds}/{max_wounds}) "
else:
# Charge NSF Fee.
Send_message(
f"/w {username} You do not have enough Crowns to buy the {args[1]}. Your current purse is {shopper_purse}."
)
return
Send_message(shop_message)
# chatmessage = ''
def retire(uname):
if c.execute(
"select gchar from users where uname = ?", (username.lower(),)
).fetchone() != ("",):
# Is a character
gchar_dict_to_sql = c.execute(
"select gchar from users where uname = ?", (username.lower(),)
).fetchone()[0]
# converts the string to dictionary
gchar_dict = ast.literal_eval(gchar_dict_to_sql)
else:
whisper = f"/w {username} {username}, you do not currently have a character, create one with the !char command."
with open("wfrpgame/character_template.html", "r") as ct:
template = ct.readlines()
template = str(template).replace("$character", str(gchar_dict["name"]).title())
template = str(template).replace("$species", str(gchar_dict["race"]).title())
template = str(template).replace("$profession", str(gchar_dict["prof"]).title())
template = str(template).replace("$ws", str(gchar_dict["weapon_skill"]))
template = str(template).replace("$bs", str(gchar_dict["ballistic_skill"]))
template = str(template).replace("$s", str(gchar_dict["strength"]))
template = str(template).replace("$t", str(gchar_dict["toughness"]))
with open(f"wfrpgame/{uname}.html", "w") as rc:
rc.writelines(template)
pass
def level_up(username, stat):
gchar_dict = None
if stat.lower().replace("\r\n", "") == "ws":
stat = "weapon_skill"
elif stat.lower().replace("\r\n", "") == "bs":
stat = "ballistic_skill"
elif stat.lower().replace("\r\n", "") == "t":
stat = "toughness"
elif stat.lower().replace("\r\n", "") == "s":
stat = "strength"
elif stat.lower().replace("\r\n", "") == "wound":
stat = "wound"
else:
Send_message(
f"/w {username} {stat} is an unknown stat. You may only levelup WS, BS, S, T or Wound."
)
return
# Get users current XP
cxp = c.execute("select exp from users where uname = ?", (username,)).fetchone()[0]
if c.execute(
"select gchar from users where uname = ?", (username.lower(),)
).fetchone() != ("",):
# Is a character
gchar_dict_to_sql = c.execute(
"select gchar from users where uname = ?", (username.lower(),)
).fetchone()[0]
# converts the string to dictionary
gchar_dict = ast.literal_eval(gchar_dict_to_sql)
# Get the Wounds characteristc
char_wounds = c.execute(
"select MaxWounds from users where uname = ?", (username.lower(),)
).fetchone()[0]
else:
whisper = f"/w {username} {username}, you do not currently have a character, create one with the !char command."
if stat.lower() != "wound":
if cxp >= 100 and gchar_dict[stat] < 75:
# Test if the user has more than 100 xp and less that 75 is specific characteristic
cxp -= 100
gchar_dict[stat] += 5
c.execute(
"update users set exp = ?, gchar = ? where uname = ?",
(cxp, str(gchar_dict), username),
)
conn.commit()
whisper = f"/w {username} Your {stat} has been increased by 5 points to {gchar_dict[stat]}"
elif gchar_dict[stat] >= 75:
# If stat is already over 75.
whisper = f"/w {username} Your {stat} has is already maxed out."
elif cxp < 100:
# if Current xp is not sufficient.
whisper = (
f"/w {username} Sorry {username} you do not currently have enough experience to "
f"upgrade your character. Current EXP: {cxp}"
)
elif stat.lower() == "wound":
if cxp >= 100 and char_wounds < 20:
cxp -= 100
char_wounds += 1
c.execute(
"update users set exp = ?, MaxWounds = ? where uname = ?",
(cxp, str(char_wounds), username),
)
conn.commit()
whisper = f"/w {username} Your wounds have been increased by 1 point to {char_wounds}"
else:
whisper = f"/w {username} It looks like you either don't have enough experience or you're already capped out on wounds!"
else:
whisper = f"/w {username} Something strange happend, please alert Rhyle_. tell him 'def level_up hit else'."
# print(username, cxp, gchar_dict[stat] + 5)
Send_message(whisper)
# get connection a pointer for sqlite db
conn, c = loader.loading_seq()
# get connection info from db
streamr = c.execute("select * from streamer").fetchall()
streamr = list(streamr[0])
(
host,
nick,
port,
oauth,
readbuffer,
ClientID,
Token,
bcasterId,
moderatorId,
OAuthBearer,
) = streamr
TLD = [
".com",
".org",
".net",
".int",
".edu",
".gov",
".mil",
".arpa",
".top",
".loan",
".xyz",
".club",
".online",
".vip",
".win",
".shop",
".ltd",
".men",
".site",
".work",
".stream",
".bid",
".wang",
".app",
".review",
".space",
".ooo",
".website",
".live",
".tech",
".life",
".blog",
".download",
".link",
".today",
".guru",
".news",
".tokyo",
".london",
".nyc",
".berlin",
".amsterdam",
".hamburg",
".boston",
".paris",
".kiwi",
".vegas",
".moscow",
".miami",
".istanbul",
".scot",
".melbourne",
".sydney",
".quebec",
".brussels",
".capetown",
".rio",
".tv",
]
# Set the channel to join for testing purposes:
chan = "rhyle_"
# chan = 'commanderpulsar'
# Connecting to Twitch IRC by passing credentials and joining a certain channel
s = socket.socket()
s.connect((host, port))
s.send(bytes("PASS %s\r\n" % oauth, "UTF-8"))
s.send(bytes("NICK %s\r\n" % nick, "UTF-8"))
s.send(bytes("CAP REQ :twitch.tv/membership\r\n", "UTF-8"))
s.send(bytes("CAP REQ :twitch.tv/tags\r\n", "UTF-8"))
s.send(bytes("CAP REQ :twitch.tv/commands\r\n", "UTF-8"))
s.send(bytes("JOIN #" + chan + "\r\n", "UTF-8"))
Running = True
random_character = "None"
readbuffer = ""
MODT = False
init_mesage = ""
slow = "off"
Send_message(social_ad(), "")
bot_start = datetime.datetime.now().replace(microsecond=0)
pvp = {}
ad_iter = 0
autoShoutOut = ["rhyle_", "rhyle_bot"]
# Clear Currently playing file
# with open('songrequest\\current_song.txt', 'w') as cs:
# cs.write('')
# starttime = datetime.datetime.now()
while Running == True:
try:
readbuffer = s.recv(1024).decode("UTF-8")
except:
s.close()
sys.exit()
temp = str(readbuffer).split("\n")
readbuffer = temp.pop()
# TODO: Get user list
# TODO: Async
# TODO: API
for line in temp:
# print(line)
# Checks whether the message is PING because its a method of Twitch to check if you're afk
if "PING :" in line:
s.send(bytes("PONG\r\n", "UTF-8"))
# print(secondsDelta.seconds / 60)
# print((currentTime - starttime) / 60)
# if (((currentTime - starttime) / 60) >= 5):
# starttime = currentTime
if ad_iter == 0:
user, sm3 = game_manager.random_encounter(c, conn)
if sm3:
Send_message(f"/w {user} {sm3}")
# Send_message(sm1)
# Send_message(sm2)
# random_encounter()
ad_iter += 1
elif ad_iter == 1:
user, sm3 = choice(
[(social_ad(), ""), game_manager.random_encounter(c, conn)]
)
if sm3:
Send_message(f"/w {user} {sm3}")
ad_iter += 1
elif ad_iter == 2:
Send_message(social_ad(), "")
ad_iter = 0
else:
parts = line.split(":", 3)
#
# DEBUG INFO
#
# for attr in parts:
# print(attr)
# print("Line = " + line)
# print("Parts index 0 = " + parts[0])
# try:
# print("Parts index 1 = " + parts[1])
# except:
# print("No Parts index 1")
# try:
# print("Parts index 2 = " + parts[2])
# except:
# print("No parts index 2")
# try:
# print("Parts index 3 = " + parts[3])
# except:
# pass
# print("Parts = " + str(parts))
try:
if (
"ROOMSTATE" not in parts[0]
and "QUIT" not in parts[0]
and "JOIN" not in parts[0]
and "PART" not in parts[0]
and "PING" not in parts[0]
):
pass
except:
print("Expected Crash")
if (
"ROOMSTATE" not in parts[0]
and "QUIT" not in parts[0]
and "JOIN" not in parts[0]
and "PART" not in parts[0]
and "PING" not in parts[0]
):
message = None
try:
# Sets the message variable to the actual message sent
message = ": ".join(parts[2:])
if "http" in parts[3]:
message = ":".join(parts[3:])
else:
message = parts[3][: len(parts[3]) - 1]
except:
pass
# message = ""
# print(message)
# Sets the username variable to the actual username
init_message = "init_done"
usernamesplit = parts[0].split(";")
# print("Parts[1]: " + parts[1])
# for i in usernamesplit:
# print("username = " + i)
# TODO: Convert PARTS to a dictionary
# if (len(usernamesplit) > 3):
# # TODO There is a bug here when someone gets timed out the bot crashes. Fix it.
# if 'display-name' in str(usernamesplit[3]):
# username = usernamesplit[3].split('=')[1].lower()
# elif 'display-name' in str(usernamesplit[2]):
# username = usernamesplit[2].split('=')[1].lower()
# elif 'display-name' in usernamesplit[4]:
# username = usernamesplit[4].split('=')[1].lower()
# else:
# username = "rhyle_bot"
# else:
# username = ''
username = "rhyle_"
# username = usernamesplit[0]
chan_name = []
if "PRIVMSG" in parts[0]:
chan_name = (parts[1].split("#"))[1]
# Only works after twitch is done announcing stuff (MOTD = Message of the day)
if MODT:
# testing for the Ping:Pong crash
# print(message)
# if username == '':
# print('Ping:Pong')
userfetch = c.execute(
"select * from users where uname = ?", (username.lower(),)
).fetchall()
try:
user_status = userfetch[0][1]
except:
user_status = "user"
# print(user_status)
if "twitch.tv" not in username:
print(
f"{datetime.datetime.now()} {username} ({user_status}): {message}"
)
with open("chatlog.txt", "a") as log:
log.write(
f"{datetime.datetime.now()} {username} ({user_status}): {str(anyascii(message))}"
)
# if username != None:
#
# The bulk of the processing goes down here!
#
if message.lower() == "":
continue
# TODO: Setup some better handling / identification for link handling.
# Link detection and timeout
# if any(ext in message for ext in TLD):
# print("Line 457: " + str(message))
# # if any(text in 'www .com http' for text in message):
# # print(user_status)
# if username.lower() == nick.lower():
# pass
# elif user_status not in ['broadcaster', 'admins', 'global_mods', 'moderators', 'subs', 'fots', 'vips', 'staff']:
# pass
# # Send_message(username + " links are not currently allowed.")
# # Send_message("/timeout " + username + " 1")
# Command processing
# if username.lower() in commands.get_elevated_users(chan) and username not in autoShoutOut:
# shoutout = [
# f"Big shout out to @{username}! Give them some love here and go follow their channel so you can get updates when they go live! (https://www.twitch.tv/{username.lower()})",
# f"Go check out @{username} they were last streaming {myTwitch.get_raider_id(ClientID, oauth, username)}, check out their channel, if you like what you see toss them a follow. You never know, you may find your new favorite streamer. (https://www.twitch.tv/{username.lower()})",
# f"A wild {myTwitch.get_raider_id(ClientID, oauth, username)} has appeared, prepare for battle! @{username}, I choose you! (https://www.twitch.tv/{username.lower()})",
# f"According to @13thfaerie: 'potato' which I think means: go check out @{username}, last streaming: {myTwitch.get_raider_id(ClientID, oauth, username)}. (https://www.twitch.tv/{username.lower()})"]
# Send_message(choice(shoutout))
# autoShoutOut.append(username)
if message[0] == "!":
message = message.strip("\r")
# REFACTORING EVERYTHING AFTER THIS LINE OUT OF BOT_BODY!
#
# commands.commands(username, message)
if username != "":
# TODO: Mod, Broadcaster, FOTS, VIP Commands.
# print(username)
if (
username.lower() in get_elevated_users(chan)
and username.lower() != "rhyle_"
):
if message[0:7].lower() == "!create":
# Parse the command to be added/created
command, target, action = message.split(", ")
ex_com, command = command.split(" ")
command = "!" + command
c.execute(
"insert into commands values (:command, :target, :action)",
{
"command": command,
"target": target,
"action": action,
},
)
conn.commit()
Send_message(
"Command " + command + " has been added."
)
elif message in [
"!sketchy",
"!sketch",
"!puk",
"!mischief",
]:
Send_message(
"Looks like the streamer is about to get into something!"
)
soundcommands.playme("sketchy-shit.mp3")
elif (
message
in [
"!rip",
"!youdied",
"!youdead",
"!ded",
"!udead",
"!medic",
"!mandown",
]
and death_counter is True
):
death_message = [
f"Uh oh, looks like Rhyle_ died... again",
f"Looks like Rhyle_ has gone the way of the dodo.",
f"Rhyle_ has been eliminated by IOI-655321",
f"MEDIC!!!",
f"You have died, Returning to Bind point. Loading....",
f"You will not evade me %T!",
f"Rhyle_ began casting Ranger Gate.",
]
sounds = [
"hes-dead-jim.mp3",
"Price-is-right-losing-horn.mp3",
"run-bitch-ruun_part.mp3",
"super-mario-bros-ost-8-youre-dead.mp3",
"why-you-always-dying-destiny.mp3",
"wilhelmscream.mp3",
"gta-san-andreas-ah-shit-here-we-go-again_BWv0Gvc.mp3",
]
Send_message(choice(death_message))
soundcommands.playme(choice(sounds))
death_counter_character = 0
deathcounter.increment_death_count(
death_counter_character
)
deathcounter.update_eq_panels(
death_counter_character
)
elif message[0:7].lower() == "!update":
# Parse the command to be added/created
command, target, action = message.split(", ")
ex_com, command = command.split(" ")
command = "!" + command
c.execute(
"update commands set action = :action where ex_command = :command",
{
"command": command,
"target": target,
"action": action.lstrip(" "),
},
)
conn.commit()
Send_message(
"Command " + command + " has been updated."
)
elif message[0:7].lower() == "!remove":
# Parse the command to be removed
ex_com, command = message.split(" ")
command = "!" + command
c.execute(
"delete from commands where ex_command = ?",
(command,),
)
conn.commit()
Send_message(
"Command " + command + " has been removed."
)
elif message[0:4].lower() == "!mtc":
# no longer give credit to the other streamers.
parts = message.split(" ")
ex_com, strm1, strm2, strm3, strm4 = [
parts[i] if i < len(parts) else None
for i in range(5)
]
command = "!multi"
target = ""
if strm3 == None:
multi = strm1 + "/" + strm2
elif strm4 == None:
multi = strm1 + "/" + strm2 + "/" + strm3
else:
multi = (
strm1
+ "/"
+ strm2
+ "/"
+ strm3
+ "/"
+ strm4
)
action = (
"Access the multitwitch at http://multitwitch.tv/"
+ multi
+ " "
"or you can access kadgar at http://kadgar.net/live/"
+ multi
)
if (
c.execute(
"select * from commands where ex_command = '!multi'"
).fetchall()
!= []
):
c.execute(
"update commands set action = :action where ex_command = :command",
{"command": command, "action": action},
)
conn.commit()
else:
c.execute(
"insert into commands values (:command, :target, :action)",
{
"command": command,
"target": target,
"action": action,
},
)
conn.commit()
Send_message(action)
elif message.lower() == "!slow":
if slow == "off":
Send_message("Engaging Slow Chat Mode...")
print("Engaging Slow Chat Mode...")
s.send(
("PRIVMSG #" + chan + " :.slow\r\n").encode(
"UTF-8"
)
)
slow = "on"
continue
if slow == "on":
Send_message("Disengaging Slow Chat Mode...")
print("Disengaging Slow Chat Mode...")
s.send(
(
"PRIVMSG #" + chan + " :.slowoff\r\n"
).encode("UTF-8")
)
slow = "off"
continue
elif "!so " in message.lower():
ex_com, user = message.replace("\r", "").split(" ")
if "@" in user:
user = user.replace("@", "")
shoutout = [
f"Big shout out to {user}! Give them some love here and go follow their channel so you can get updates when they go live! (https://www.twitch.tv/{user.lower()})",
f"Go check out {user} they were last streaming {myTwitch.get_raider_id(ClientID, Token, user)}, check out their channel, if you like what you see toss them a follow. You never know, you may find your new favorite streamer. (https://www.twitch.tv/{user.lower()})",
f"A wild {myTwitch.get_raider_id(ClientID, Token, user)} has appeared, prepare for battle! {user}, I choose you! (https://www.twitch.tv/{user.lower()})",
f"According to @13thfaerie: 'potato' which I think means: go check out {user}, last streaming: {myTwitch.get_raider_id(ClientID, Token, user)}. (https://www.twitch.tv/{user.lower()})",
]
Send_message(choice(shoutout))
elif "!randomenc" in message.lower():
try:
ex_com, user = message.lower().split(" ")
user, sm3 = game_manager.random_encounter(
c, conn, user.strip("@")
)
if sm3:
Send_message(f"/w {user} {sm3}")
except:
user, sm3 = game_manager.random_encounter(
c, conn
)
if sm3:
Send_message(sm3)
continue
elif "!givecrowns" in message:
ex_com, viewer, amount = message.split(" ")
if "@" in viewer:
viewer = viewer.strip("@")
gc_user = int(
c.execute(
"select crowns from users where uname = ?",
(viewer.lower(),),
).fetchone()[0]
)
gc_user += int(amount)
c.execute(
"update users set crowns = ? where uname = ?",
(gc_user, viewer.lower()),
)
conn.commit()
Send_message(
f"{viewer} was awarded {amount} crowns."
)
elif "!givexp" in message.lower():
parts = message.split(" ", 3)
parts += "" * (3 - len(parts))
ex_com, viewer, amount = parts
if "@" in viewer:
viewer = viewer.strip("@")
print(viewer)
rew_user = int(
c.execute(
"select exp from users where uname = ?",
(viewer.lower(),),
).fetchone()[0]
)
rew_user += int(amount)
c.execute(
"update users set exp = ? where uname = ?",
(rew_user, viewer.lower()),
)
conn.commit()
Send_message(f"Added {amount} xp to {viewer}.")
elif "!rt" in message.lower():
Send_message(
f"Click this link to retweet https://twitter.com/intent/retweet?tweet_id={twitter.get_retweet()}"
)
elif "!mtc" in message.lower():
parts = message.split(" ")
ex_com, strm1, strm2, strm3, strm4 = [
parts[i] if i < len(parts) else None
for i in range(5)
]
command = "!multi"
target = ""
if strm3 == None:
multi = strm1 + "/" + strm2
elif strm4 == None:
multi = strm1 + "/" + strm2 + "/" + strm3
else:
multi = (
strm1
+ "/"
+ strm2
+ "/"
+ strm3
+ "/"
+ strm4
)
action = (
"Access the multitwitch at http://multitwitch.tv/"
+ multi
+ " "
"or you can access kadgar at http://kadgar.net/live/"
+ multi
)
if (
c.execute(
"select * from commands where ex_command = '!multi'"
).fetchall()
!= []
):
c.execute(
"update commands set action = :action where ex_command = :command",
{"command": command, "action": action},
)
conn.commit()
else:
c.execute(
"insert into commands values (:command, :target, :action)",