-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtinybot.py
3531 lines (2940 loc) · 148 KB
/
tinybot.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
# -*- coding: utf-8 -*-
""" Tinybot by Nortxort (https://github.com/nortxort/tinybot-rtc) """
""" Modified by Smokey """
import time
import logging
import threading
import os
import pinylib
from page import privacy
from util import tracklist
from apis import youtube, other, locals_
import random
from random import randint
import pickledb
__version__ = '2.1'
log = logging.getLogger(__name__)
joind_time = 0
joind_count = 0
bad_nick = 0
autoban_time = 0
autoban_count = 0
newnick = 0
ban_time = 0
spam = 0
spammer = 0
lastmsgs = []
sword = 0
flower = 0
answer_A = ["A", "a"]
answer_B = ["B", "b"]
answer_C = ["C", "c"]
yes = ["Y", "y", "yes"]
no = ["N", "n", "no"]
# Random password words
_KEYWORDS = ["fob", "fobcity", "terima", "halal", "haram", "roses", ]
class TinychatBot(pinylib.TinychatRTCClient):
privacy_ = None
timer_thread = None
playlist = tracklist.PlayList()
search_list = []
is_search_list_yt_playlist = False
announce = 0
announceCheck = 0
tokers = []
toke_start = 0
toke_end = 0
toke_mode = False
toker = None
fishers = []
fish_start = 0
fish_end = 0
fish_mode = False
fisher = None
catch = []
hunters = []
hunt_start = 0
hunt_end = 0
hunt_mode = False
hunter = None
hunted = []
@property
def config_path(self):
""" Returns the path to the rooms configuration directory. """
return pinylib.CONFIG.CONFIG_PATH + self.room_name + '/'
global lockdown
global userdb
global db
lockdown = False
userdb = pinylib.CONFIG.CONFIG_PATH + pinylib.CONFIG.ROOM + '/' + 'user.db'
db = pickledb.load(userdb, False)
def isWord(self, word):
VOWELS = "aeiou"
PHONES = ['sh', 'ch', 'ph', 'sz', 'cz', 'sch', 'rz', 'dz']
prevVowel = False
if word:
consecutiveVowels = 0
consecutiveConsonents = 0
for idx, letter in enumerate(word.lower()):
vowel = True if letter in VOWELS else False
if idx:
prev = word[idx - 1]
if prev in VOWELS:
prevVowel = True
if not vowel and letter == 'y' and not prevVowel:
vowel = True
if prevVowel != vowel:
consecutiveVowels = 0
consecutiveConsonents = 0
if vowel:
consecutiveVowels += 1
else:
consecutiveConsonents += 1
if consecutiveVowels >= 3 or consecutiveConsonents > 3:
return False
if consecutiveConsonents == 3:
subStr = word[idx - 2:idx + 1]
if any(phone in subStr for phone in PHONES):
consecutiveConsonents -= 1
continue
return False
return True
def on_joined(self, client_info):
"""
Received when the client have joined the room successfully.
:param client_info: This contains info about the client, such as user role and so on.
:type client_info: dict
"""
log.info('client info: %s' % client_info)
self.client_id = client_info['handle']
self.is_client_mod = client_info['mod']
self.is_client_owner = client_info['owner']
client = self.users.add(client_info)
client.user_level = 3
self.console_write(pinylib.COLOR[
'bright_green'], '[Bot] connected as %s:%s' % (client.nick, client.id))
threading.Thread(target=self.options).start()
if not os.path.exists(userdb):
db = pickledb.load(userdb, False)
db.dcreate('users')
db.dcreate('badwords')
db.dcreate('badnicks')
db.dcreate('gamers')
db.dcreate('fishing_poles')
db.dcreate('weapons')
db.dump()
self.console_write(pinylib.COLOR['bright_green'], '[DB] Created')
else:
db = pickledb.load(userdb, False)
self.console_write(pinylib.COLOR['bright_green'], '[DB] Loaded')
def on_join(self, join_info):
"""
Received when a user joins the room.
:param join_info: This contains user information such as role, account and so on.
:type join_info: dict
"""
global joind_time
global joind_count
global autoban_time
global lockdown
global bad_nick
global db
time_join = time.time()
log.info('user join info: %s' % join_info)
_user = self.users.add(join_info)
if self.nick_check(_user.nick):
if pinylib.CONFIG.B_USE_KICK_AS_AUTOBAN:
self.send_kick_msg(_user.id)
else:
self.send_ban_msg(_user.id)
self.console_write(pinylib.COLOR['cyan'], '[Security] Banned: Nick %s' % (_user.nick))
if _user.account:
if _user.is_owner:
_user.user_level = 1 # account owner
self.console_write(pinylib.COLOR['red'], '[User] Room Owner %s:%d:%s' %
(_user.nick, _user.id, _user.account))
elif _user.is_mod:
_user.user_level = 3 # mod
self.console_write(pinylib.COLOR['bright_red'], '[User] Moderator %s:%d:%s' %
(_user.nick, _user.id, _user.account))
if db.dexists('users', _user.account):
_level = self.user_check(_user.account)
if _level == 4 and not _user.is_mod:
_user.user_level = _level # chatmod
if _level == 5 and not _user.is_mod:
_user.user_level = _level # whitelist
if _level == 2: # overwrite mod to chatadmin
_user.user_level = _level
self.console_write(pinylib.COLOR['bright_red'], '[User] Found, level(%s) %s:%d:%s' % (_user.user_level, _user.nick, _user.id, _user.account))
else:
if not _user.user_level:
_user.user_level = 6 # account not verified
self.console_write(pinylib.COLOR['bright_red'], '[User] Not verified %s:%d:%s' % (
_user.nick, _user.id, _user.account))
if self.user_check(_user.account) == 9 and self.is_client_mod:
if pinylib.CONFIG.B_USE_KICK_AS_AUTOBAN:
self.send_kick_msg(_user.id)
else:
self.send_ban_msg(_user.id)
self.console_write(
pinylib.COLOR['cyan'], '[Security] Banned: Account %s' % (_user.account))
else:
tc_info = pinylib.apis.tinychat.user_info(_user.account)
if tc_info is not None:
_user.tinychat_id = tc_info['tinychat_id']
_user.last_login = tc_info['last_active']
else:
_user.user_level = 7 # guest
self.console_write(
pinylib.COLOR['bright_red'], '[User] Guest %s:%d' % (_user.nick, _user.id))
if lockdown and autoban_time != 0:
if time_join - 240 > autoban_time:
if lockdown == 1:
soft = 1
self.do_lockdown(soft)
autoban_time = 0
bad_nick = 0
self.console_write(
pinylib.COLOR['cyan'], '[Security] Lockdown Mode Reset')
else:
maxtime = 7
maxjoins = 8
if joind_time == 0:
joind_time = time.time()
joind_count += 1
elif time_join - joind_time > maxtime:
joind_count = 0
joind_time = 0
bad_nick = 0
elif joind_count > maxjoins:
soft = 0
self.do_lockdown(soft)
autoban_time = time_join
self.console_write(
pinylib.COLOR['cyan'], '[Security] Lockdown started')
else:
joind_count += 1
if not self.isWord(_user.nick):
bad_nick += 1
if bad_nick > 3:
time.sleep(1.0)
self.send_ban_msg(_user.id)
self.console_write(pinylib.COLOR[
'cyan'], '[Security] Randomized Nick Banned: Nicks %s' % (_user.nick))
if not pinylib.CONFIG.B_ALLOW_GUESTS:
if _user.user_level == 7:
self.send_ban_msg(_user.id)
self.console_write(pinylib.COLOR[
'cyan'], '[Security] %s was banned on no guest mode' % (_user.nick))
self.console_write(pinylib.COLOR['cyan'], '[User] %s:%d joined the room. (%s)' % (
_user.nick, _user.id, joind_count))
threading.Thread(target=self.welcome, args=(_user.id,)).start()
def welcome(self, uid):
time.sleep(1)
_user = self.users.search(uid)
_level = self.user_check(_user.account)
if _user is not None:
if pinylib.CONFIG.B_ALLOW_GUESTS:
if pinylib.CONFIG.B_GREET and _user is not None:
if not _user.nick.startswith('guest-'):
if _user.account == 'smokeyllama':
pass
self.send_chat_msg(' Yo its %s (%s)! he\'s dope.' % (_user.nick, _user.account))
elif _user.user_level < 3:
pass
self.send_chat_msg(' ❢👑𝙊𝙒𝙉𝙀𝙍👑❢ \n ---👋𝙒𝙚𝙡𝙘𝙤𝙢𝙚 𝘽𝙖𝙘𝙠 𝙃𝙤𝙢𝙚')
elif _user.user_level < 4:
pass
self.send_chat_msg(' 👑𝙈𝙤𝙙❢ \n 👋𝙒𝙚𝙡𝙘𝙤𝙢𝙚 𝘽𝙖𝙘𝙠 𝙩𝙤 𝙩𝙝𝙚 𝓒𝓸𝓯𝓯𝓮𝓮𝓟𝓸𝓽❢ \n 🧟♂️ %s (%s) ' % (_user.nick, _user.account))
elif _level == 5 or _level == 4:
pass
self.send_chat_msg(' ✔️ 𝙑𝙚𝙧𝙞𝙛𝙞𝙚𝙙 \n 👋𝙒𝙚𝙡𝙘𝙤𝙢𝙚 𝘽𝙖𝙘𝙠 𝙩𝙤 𝙩𝙝𝙚 𝓒𝓸𝓯𝓯𝓮𝓮𝓟𝓸𝓽❢ \n 🧟♂️ %s (%s)' % (_user.nick, _user.account))
elif _user.user_level == 5:
pass
self.send_chat_msg(' 👋𝙒𝙚𝙡𝙘𝙤𝙢𝙚 𝙩𝙤 𝙩𝙝𝙚 𝓒𝓸𝓯𝓯𝓮𝓮𝓟𝓸𝓽❢ \n 🧟♂️ %s (%s)' % (_user.nick, _user.account))
elif _user.user_level == 6:
#self.send_private_msg(_user.id, 'Welcome to %s - ask to have your account verified.' % (self.room_name))
self.send_chat_msg('👋𝙒𝙚𝙡𝙘𝙤𝙢𝙚 𝙩𝙤 𝓒𝓸𝓯𝓯𝓮𝓮𝓟𝓸𝓽❢ \n 🧟♂️ %s (%s) \n 😀𝙀𝙣𝙟𝙤𝙮❢' % (_user.nick, _user.account))
elif _user.user_level == 7:
#self.send_private_msg(_user.id, 'Welcome to %s - we suggest making an account, personal info trolling or sexual harassment will not be tolerated.' % (self.room_name))
self.send_chat_msg('👋𝙒𝙚𝙡𝙘𝙤𝙢𝙚 𝙩𝙤 𝓒𝓸𝓯𝓯𝓮𝓮𝓟𝓸𝓽❢ \n 🧟♂️ %s. 😒𝙃𝙢𝙢𝙢, 𝙄𝙩 𝙎𝙚𝙚𝙢𝙨 𝙔𝙤𝙪𝙧𝙚 𝙉𝙤𝙩 𝙎𝙞𝙜𝙣𝙚𝙙 𝙄𝙣.' % (_user.nick))
def on_quit(self, uid):
time.sleep(1)
_user = self.users.search(uid)
if _user is not None:
if pinylib.CONFIG.B_ALLOW_GUESTS:
if pinylib.CONFIG.B_FAREWELL and _user is not None:
if not _user.nick.startswith('guest-'):
if _user.user_level < 4:
pass
self.send_chat_msg(' 👑𝙈𝙤𝙙❢ \n 👋 %s (%s) left the room' % (_user.nick, _user.account))
elif _user.user_level == 5:
self.send_chat_msg('👋 %s (%s) left the room!' % (_user.nick, _user.account))
def on_pending_moderation(self, pending):
_user = self.users.search(pending['handle'])
if _user is not None:
if self.user_check(_user.account) == 5 or self.user_check(_user.account) == 4:
self.send_cam_approve_msg(_user.id)
else:
_user.is_waiting = True
self.send_chat_msg(
'%s is waiting in the greenroom.' % (_user.nick))
def do_lockdown(self, soft):
global password
global lockdown
if self.is_client_owner:
if soft:
password = None
else:
password = self.do_create_password()
if not self.privacy_.set_guest_mode():
self.privacy_.set_room_password(password)
lockdown = True
if soft:
self.send_chat_msg('Lockdown - no guests allowed.')
else:
self.send_chat_msg(
'Lockdown - tmp password is: %s' % (password))
else:
password = None
self.privacy_.set_room_password(password)
lockdown = False
self.send_chat_msg(
'%s is open to the public again.' % (self.room_name))
else:
if not pinylib.CONFIG.B_ALLOW_GUESTS:
lockdown = False
self.do_guests()
self.send_chat_msg(
'%s is open to the public again.' % (self.room_name))
else:
self.do_guests()
self.send_chat_msg('Lockdown - no guests allowed.')
def on_nick(self, uid, nick):
"""
Received when a user changes nick name.
:param uid: The ID (handle) of the user.
:type uid: int
:param nick: The new nick name.
:type nick: str
"""
_user = self.users.search(uid)
old_nick = _user.nick
_user.nick = nick
if uid != self.client_id:
if self.nick_check(_user.nick):
if pinylib.CONFIG.B_USE_KICK_AS_AUTOBAN:
self.send_kick_msg(uid)
else:
self.send_ban_msg(uid)
self.console_write(pinylib.COLOR['bright_cyan'], '[User] %s:%s Changed nick to: %s' %
(old_nick, uid, nick))
def on_yut_play(self, yt_data):
"""
Received when a youtube gets started or time searched.
This also gets received when the client starts a youtube, the information is
however ignored in that case.
:param yt_data: The event information contains info such as the ID (handle) of the user
starting/searching the youtube, the youtube ID, youtube time and so on.
:type yt_data: dict
"""
user_nick = 'n/a'
if 'handle' in yt_data:
if yt_data['handle'] != self.client_id:
_user = self.users.search(yt_data['handle'])
user_nick = _user.nick
if self.playlist.has_active_track:
self.cancel_timer()
if yt_data['item']['offset'] == 0:
_youtube = youtube.video_details(yt_data['item']['id'], False)
self.playlist.start(user_nick, _youtube)
self.timer(self.playlist.track.time)
self.console_write(pinylib.COLOR['bright_magenta'], '[Media] %s started youtube video (%s)' %
(user_nick, yt_data['item']['id']))
elif yt_data['item']['offset'] > 0:
if user_nick == 'n/a':
_youtube = youtube.video_details(yt_data['item']['id'], False)
self.playlist.start(user_nick, _youtube)
offset = self.playlist.play(yt_data['item']['offset'])
self.timer(offset)
else:
offset = self.playlist.play(yt_data['item']['offset'])
self.timer(offset)
self.console_write(pinylib.COLOR['bright_magenta'], '[Media] %s searched the youtube video to: %s' %
(user_nick, int(round(yt_data['item']['offset']))))
def on_yut_pause(self, yt_data):
"""
Received when a youtube gets paused or searched while paused.
This also gets received when the client pauses or searches while paused, the information is
however ignored in that case.
:param yt_data: The event information contains info such as the ID (handle) of the user
pausing/searching the youtube, the youtube ID, youtube time and so on.
:type yt_data: dict
"""
if 'handle' in yt_data:
if yt_data['handle'] != self.client_id:
_user = self.users.search(yt_data['handle'])
if self.playlist.has_active_track:
self.cancel_timer()
self.playlist.pause()
self.console_write(pinylib.COLOR['bright_magenta'], '[Media] %s paused the video at %s' %
(_user.nick, int(round(yt_data['item']['offset']))))
def message_handler(self, msg):
"""
A basic handler for chat messages.
Overrides message_handler in pinylib
to allow commands.
:param msg: The chat message.
:type msg: str
User Levels
7 : Not Signed In
5 : Signed In
3 : MOD
Script Levels
0 : All
5 : Verified/On File
"""
prefix = pinylib.CONFIG.B_PREFIX
if msg.startswith(prefix):
parts = msg.split(' ')
cmd = parts[0].lower().strip()
cmd_arg = ' '.join(parts[1:]).strip()
_user = self.users.search_by_nick(self.active_user.nick)
_level = self.user_check(_user.account)
if _user.user_level < 4:
if cmd == prefix + 'chatmod':
self.do_chatmod(cmd_arg)
elif cmd == prefix + 'rmchatmod':
self.do_remove_chatmod(cmd_arg)
elif cmd == prefix + 'demod':
self.do_deop_user(cmd_arg)
elif cmd == prefix + 'noguest':
self.do_guests()
elif cmd == prefix + 'lockdown':
self.do_lockdown(1)
elif cmd == prefix + 'lockup':
self.do_lockdown(0)
if _user.user_level == 2:
if cmd == prefix + 'chatadmin':
self.do_chatadmin(cmd_arg)
if self.is_client_owner:
if cmd == prefix + 'p2t':
threading.Thread(target=self.do_push2talk).start()
elif cmd == prefix + 'greet':
self.do_greet()
elif cmd == prefix == 'kb':
self.do_kick_as_ban()
elif cmd == prefix + 'reboot':
self.do_reboot()
elif cmd == prefix + 'dir':
threading.Thread(target=self.do_directory).start()
elif cmd == prefix + 'addmod':
threading.Thread(target=self.do_make_mod,
args=(cmd_arg,)).start()
elif cmd == prefix + 'removemod':
threading.Thread(
target=self.do_remove_mod, args=(cmd_arg,)).start()
if _user.user_level < 5 or _level == 4:
if cmd == prefix + 'mod':
self.do_op_user(cmd_arg)
elif cmd == prefix + 'who':
self.do_user_info(cmd_arg)
if cmd == prefix + 'rmvgamer':
self.do_remove_gamer(cmd_arg)
elif cmd == prefix + 'bruh':
self.do_verified(cmd_arg)
elif cmd == prefix + 'rmv':
self.do_remove_verified(cmd_arg)
elif cmd == prefix + 'clr':
self.do_clear()
elif cmd == prefix + 'forgive':
threading.Thread(target=self.do_forgive,
args=(cmd_arg,)).start()
elif cmd == prefix + 'kick':
threading.Thread(target=self.do_kick,
args=(cmd_arg,)).start()
elif cmd == prefix + 'ban':
threading.Thread(target=self.do_ban,
args=(cmd_arg,)).start()
elif cmd == prefix + 'uinfo':
self.do_user_info(cmd_arg)
elif cmd == prefix + 'cam':
self.do_cam_approve(cmd_arg)
elif cmd == prefix + 'close':
self.do_close_broadcast(cmd_arg)
elif cmd == prefix + 'badn':
self.do_bad_nick(cmd_arg)
elif cmd == prefix + 'rmbadn':
self.do_remove_bad_nick(cmd_arg)
elif cmd == prefix + 'banw':
self.do_bad_string(cmd_arg)
elif cmd == prefix + 'rmw':
self.do_remove_bad_string(cmd_arg)
elif cmd == prefix + 'bada':
self.do_bad_account(cmd_arg)
elif cmd == prefix + 'rmbada':
self.do_remove_bad_account(cmd_arg)
if _user.user_level < 5 or _level == 5 or _level == 4:
if cmd == prefix + 'fish':
self.do_fish()
elif cmd == prefix + 'hunt':
self.do_hunt()
elif cmd == prefix + 'store':
self.open_shop()
elif cmd == prefix + 'shop':
self.open_shop()
elif cmd == prefix + 'pole_shop':
self.open_shop_poles()
elif cmd == prefix + 'pole':
self.buy_pole(cmd_arg)
elif cmd == prefix + 'pole_stats':
self.pole_stats()
elif cmd == prefix + 'sword_shop':
self.open_shop_swords()
elif cmd == prefix + 'sword':
self.buy_sword(cmd_arg)
elif cmd == prefix + 'sword_stats':
self.sword_stats()
elif cmd == prefix + 'bow_shop':
self.open_shop_bows()
elif cmd == prefix + 'bow':
self.buy_bow(cmd_arg)
elif cmd == prefix + 'bow_stats':
self.bow_stats()
elif cmd == prefix + 'bet':
self.do_bet(cmd_arg, cmd_arg)
elif cmd == prefix + 'advtime':
self.do_advtime()
elif cmd == prefix + 'scriptlvl':
self.do_script_level()
elif cmd == prefix + 'lvl':
self.do_level()
elif cmd == prefix + 'skip':
self.do_skip()
elif cmd == prefix + 'media':
self.do_media_info()
elif cmd == prefix + 'yt':
threading.Thread(target=self.do_play_youtube,
args=(cmd_arg,)).start()
elif cmd == prefix + 'stan':
threading.Thread(target=self.do_play_youtube,
args=('AHukwv_VX9A',)).start()
self.do_stan()
elif cmd == prefix + 'yts':
threading.Thread(target=self.do_youtube_search,
args=(cmd_arg,)).start()
elif cmd == prefix + 'del':
self.do_delete_playlist_item(cmd_arg)
elif cmd == prefix + 'replay':
self.do_media_replay()
elif cmd == prefix + 'play':
self.do_play_media()
elif cmd == prefix + 'pause':
self.do_media_pause()
elif cmd == prefix + 'seek':
self.do_seek_media(cmd_arg)
elif cmd == prefix + 'stop':
self.do_close_media()
elif cmd == prefix + 'reset':
self.do_clear_playlist()
elif cmd == prefix + 'next':
self.do_next_tune_in_playlist()
elif cmd == prefix + 'playlist':
self.do_playlist_info()
elif cmd == prefix + 'pyts':
self.do_play_youtube_search(cmd_arg)
elif cmd == prefix + 'pls':
threading.Thread(target=self.do_youtube_playlist_search,
args=(cmd_arg,)).start()
elif cmd == prefix + 'plp':
threading.Thread(target=self.do_play_youtube_playlist,
args=(cmd_arg,)).start()
elif cmd == prefix + 'ssl':
self.do_show_search_list()
if _user.user_level < 6:
if cmd == prefix + 'help':
self.do_help()
elif cmd == prefix + 'whatsong':
self.do_now_playing()
elif cmd == prefix + 'status':
self.do_playlist_status()
elif cmd == prefix + 'now':
self.do_now_playing()
elif cmd == prefix + 'whoplayed':
self.do_who_plays()
elif cmd == prefix + 'urb':
threading.Thread(
target=self.do_search_urban_dictionary, args=(cmd_arg,)).start()
elif cmd == prefix + 'porn':
threading.Thread(
target=self.do_porn_search, args=(cmd_arg,)).start()
elif cmd == prefix + 'wea':
threading.Thread(
target=self.do_weather_search, args=(cmd_arg,)).start()
elif cmd == prefix + 'chuck':
threading.Thread(target=self.do_chuck_noris).start()
elif cmd == prefix + '8ball':
self.do_8ball(cmd_arg)
elif cmd == prefix + 'roll':
self.do_dice()
elif cmd == prefix + 'flip':
self.do_flip_coin()
elif cmd == prefix + 'tokes':
self.tokesession(cmd_arg)
elif cmd == prefix + 'cheers':
self.tokesession(cmd_arg)
elif cmd == prefix + 'join':
self.tokesession(cmd_arg)
self.console_write(
pinylib.COLOR['yellow'], self.active_user.nick + ': ' + cmd + ' ' + cmd_arg)
else:
self.console_write(
pinylib.COLOR['green'], self.active_user.nick + ': ' + msg)
if self.active_user.user_level > 4:
threading.Thread(target=self.check_msg, args=(msg,)).start()
self.active_user.last_msg = msg
def do_make_mod(self, account):
"""
Make a tinychat account a room moderator.
:param account: The account to make a moderator.
:type account: str
"""
if self.is_client_owner:
if len(account) is 0:
self.send_chat_msg('Missing account name.')
else:
tc_user = self.privacy_.make_moderator(account)
if tc_user is None:
self.send_chat_msg('The account is invalid.')
elif not tc_user:
self.send_chat_msg('%s is already a moderator.' % account)
elif tc_user:
self.send_chat_msg(
'%s was made a room moderator.' % account)
def do_remove_mod(self, account):
"""
Removes a tinychat account from the moderator list.
:param account: The account to remove from the moderator list.
:type account: str
"""
if self.is_client_owner:
if len(account) is 0:
self.send_chat_msg('Missing account name.')
else:
tc_user = self.privacy_.remove_moderator(account)
if tc_user:
self.send_chat_msg(
'%s is no longer a room moderator.' % account)
elif not tc_user:
self.send_chat_msg('%s is not a room moderator.' % account)
def do_directory(self):
""" Toggles if the room should be shown on the directory. """
if self.is_client_owner:
if self.privacy_.show_on_directory():
self.send_chat_msg('Room IS shown on the directory.')
else:
self.send_chat_msg('Room is NOT shown on the directory.')
def do_push2talk(self):
""" Toggles if the room should be in push2talk mode. """
if self.is_client_owner:
if self.privacy_.set_push2talk():
self.send_chat_msg('Push2Talk is enabled.')
else:
self.send_chat_msg('Push2Talk is disabled.')
def do_green_room(self):
""" Toggles if the room should be in greenroom mode. """
if self.is_client_owner:
if self.privacy_.set_greenroom():
self.send_chat_msg('Green room is enabled.')
else:
self.send_chat_msg('Green room is disabled.')
def do_clear_room_bans_two(self):
""" Clear all room bans. """
if self.is_client_owner:
if self.privacy_.clear_bans():
self.send_chat_msg('All room bans were cleared.')
def do_kill(self):
""" Kills the bot. """
self.disconnect()
def do_reboot(self):
""" Reboots the bot. """
self.reconnect()
def do_media_info(self):
""" Show information about the currently playing youtube. """
if self.is_client_mod and self.playlist.has_active_track:
self.send_chat_msg(
'Playlist Tracks: ' + str(len(self.playlist.track_list)) + '\n' +
'Track Title: ' + self.playlist.track.title + '\n' +
'Track Index: ' + str(self.playlist.track_index) + '\n' +
'Elapsed Track Time: ' + self.format_time(self.playlist.elapsed) + '\n' +
'Remaining Track Time: ' +
self.format_time(self.playlist.remaining)
)
def do_op_user(self, user_name):
if self.is_client_mod:
if len(user_name) is 0:
self.send_chat_msg('Account can\'t be blank.')
elif len(user_name) < 3:
self.send_chat_msg('Account too short: ' +
str(len(user_name)))
elif self.user_check(user_name) == 4:
self.send_chat_msg('%s already has the power of BRUH.' % user_name)
else:
db = pickledb.load(userdb, False)
user = {'level': 4, 'by': self.active_user.account,
'created': time.time()}
db.dadd('users', (user_name, user))
db.dump()
self.console_write(pinylib.COLOR['cyan'], '[User] New account %s, BRUH\'d by %s' % (
user_name, self.active_user.account))
self.send_chat_msg('%s has gained BRUH powers!' % user_name)
def do_deop_user(self, user_name):
"""
Lets the room owner, a mod or a bot controller remove a user from being a bot controller.
:param user_name: The user to deop.
:type user_name: str
"""
if self.is_client_mod:
if len(user_name) is 0:
self.send_chat_msg('Account can\'t be blank.')
elif len(user_name) < 3:
self.send_chat_msg('Account too short: ' +
str(len(user_name)))
elif self.user_check(user_name) == 5:
self.send_chat_msg('%s does not have BRUH powers.' % user_name)
else:
db = pickledb.load(userdb, False)
user = {'level': 5, 'by': self.active_user.account,
'created': time.time()}
db.dadd('users', (user_name, user))
db.dump()
self.console_write(pinylib.COLOR['cyan'], '[User] New account %s, de-BRUH\'d by %s' % (
user_name, self.active_user.account))
self.send_chat_msg('%s lost all BRUH powers.' % user_name)
def do_guests(self):
""" Toggles if guests are allowed to join the room or not. """
pinylib.CONFIG.B_ALLOW_GUESTS = not pinylib.CONFIG.B_ALLOW_GUESTS
self.send_chat_msg('Allow Guests: %s' % pinylib.CONFIG.B_ALLOW_GUESTS)
def do_greet(self):
""" Toggles if users should be greeted on entry. """
pinylib.CONFIG.B_GREET = not pinylib.CONFIG.B_GREET
self.send_chat_msg('Greet Users: %s' % pinylib.CONFIG.B_GREET)
def do_kick_as_ban(self):
""" Toggles if kick should be used instead of ban for auto bans . """
pinylib.CONFIG.B_USE_KICK_AS_AUTOBAN = not pinylib.CONFIG.B_USE_KICK_AS_AUTOBAN
self.send_chat_msg('Use Kick As Auto Ban: %s' %
pinylib.CONFIG.B_USE_KICK_AS_AUTOBAN)
def do_youtube_playlist_search(self, search_str):
"""
Search youtube for a playlist.
:param search_str: The search term to search for.
:type search_str: str
"""
if self.is_client_mod:
if len(search_str) == 0:
self.send_chat_msg('Missing search string.')
else:
self.search_list = youtube.playlist_search(search_str)
if len(self.search_list) > 0:
self.is_search_list_yt_playlist = True
_ = '\n'.join('(%s) %s' % (
i, d['playlist_title']) for i, d in enumerate(self.search_list))
self.send_chat_msg(_)
else:
self.send_chat_msg(
'Failed to find playlist matching search term: %s' % search_str)
def do_play_youtube_playlist(self, int_choice):
"""
Play a previous searched playlist.
:param int_choice: The index of the playlist.
:type int_choice: str | int
"""
if self.is_client_mod:
if self.is_search_list_yt_playlist:
try:
int_choice = int(int_choice)
except ValueError:
self.send_chat_msg('Only numbers allowed.')
else:
if 0 <= int_choice <= len(self.search_list) - 1:
self.send_chat_msg(
'Please wait while creating playlist..')
tracks = youtube.playlist_videos(
self.search_list[int_choice])
if len(tracks) > 0:
self.playlist.add_list(
self.active_user.nick, tracks)
self.send_chat_msg(
'🎶 Added %s tracks from youtube playlist.' % len(tracks))
if not self.playlist.has_active_track:
track = self.playlist.next_track
self.send_yut_play(
track.id, track.time, track.title)
self.timer(track.time)
else:
self.send_chat_msg(
'Failed to retrieve videos from youtube playlist.')
else:
self.send_chat_msg(
'Please make a choice between 0-%s' % str(len(self.search_list) - 1))
else:
self.send_chat_msg(
'The search list does not contain any youtube playlist id\'s.')
def do_show_search_list(self):
""" Show what the search list contains. """
if self.is_client_mod:
if len(self.search_list) == 0:
self.send_chat_msg('The search list is empty.')
elif self.is_search_list_yt_playlist:
_ = '\n'.join('(%s) - %s' % (i, d['playlist_title'])
for i, d in enumerate(self.search_list))
self.send_chat_msg('Youtube Playlist\'s\n' + _)
else:
_ = '\n'.join('(%s) %s %s' % (i, d['video_title'], self.format_time(d['video_time']))
for i, d in enumerate(self.search_list))
self.send_chat_msg('🎶 Youtube Tracks\n' + _)
def do_skip(self):
""" Skip to the next item in the playlist. """
if self.is_client_mod:
if self.playlist.is_last_track is None:
self.send_chat_msg('No tune next. The playlist is empty. !stop to clear current track.')
elif self.playlist.is_last_track:
self.send_chat_msg('This is the last track in the playlist.')
else:
self.cancel_timer()
next_track = self.playlist.next_track
self.send_yut_play(
next_track.id, next_track.time, next_track.title)
self.timer(next_track.time)
# TODO: Make sure this is working.
def do_delete_playlist_item(self, to_delete):
"""
Delete items from the playlist.
:param to_delete: Item indexes to delete.
:type to_delete: str
"""
if self.is_client_mod:
if len(self.playlist.track_list) == 0:
self.send_chat_msg('The playlist is empty.')
elif len(to_delete) == 0:
self.send_chat_msg('No indexes provided.')
else:
indexes = None
by_range = False
try:
if ':' in to_delete:
range_indexes = map(int, to_delete.split(':'))
temp_indexes = range(