Advertisement
MeKLiN2

Untitled

Mar 18th, 2022
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 93.09 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """ Tinybot by Nortxort (https://github.com/nortxort/tinybot-rtc) """
  3.  
  4. import logging
  5. import threading
  6. import random
  7. import pinylib
  8. import urllib, json
  9. import requests
  10.  
  11. from util import tracklist
  12. from page import privacy
  13. from apis import youtube, lastfm, other, locals_
  14. import check_user
  15. import time
  16.  
  17.  
  18.  
  19. __version__ = '2.0.3'
  20. log = logging.getLogger(__name__)
  21.  
  22.  
  23. class TinychatBot(pinylib.TinychatRTCClient):
  24. privacy_ = None
  25. timer_thread = None
  26. playlist = tracklist.PlayList()
  27. search_list = []
  28. is_search_list_yt_playlist = False
  29. bl_search_list = []
  30.  
  31. @property
  32. def config_path(self):
  33. """ Returns the path to the rooms configuration directory. """
  34. return pinylib.CONFIG.CONFIG_PATH + self.room_name + '/'
  35.  
  36. def user_check(self, user, account=False, guest=False, nick=False, lurker=False):
  37. """
  38. A wrapper for the CheckUser class.
  39.  
  40. :return: True, if the user was banned.
  41. :rtype: bool
  42. """
  43. if not self.is_client_mod:
  44. return False
  45.  
  46. judge = check_user.CheckUser(self, user, pinylib.CONFIG)
  47.  
  48. if account and user.account != '':
  49. log.debug('checking account: %s' % user.account)
  50. if not user.is_mod and judge.check_account():
  51. return True
  52.  
  53. api = pinylib.apis.tinychat.user_info(user.account)
  54. if api is not None:
  55. user.tinychat_id = api['tinychat_id']
  56. user.last_login = api['last_active']
  57.  
  58. if guest:
  59. log.debug('checking guest entrance: %s' % user.nick)
  60. if judge.guest_entry():
  61. return True
  62.  
  63. if nick and user.nick:
  64. log.debug('checking nick: %s' % user.nick)
  65. if not user.is_mod and judge.check_nick():
  66. return True
  67.  
  68. if lurker and user.is_lurker:
  69. log.debug('check lurker: %s' % user.nick)
  70. if judge.check_lurker():
  71. return True
  72.  
  73. return False
  74. #### 1l1l1l1l1l1l1l1l1l1l1l1l1l1l1l1l
  75. def on_joined(self, client_info):
  76. """
  77. Received when the client have joined the room successfully.
  78.  
  79. :param client_info: This contains info about the client, such as user role and so on.
  80. :type client_info: dict
  81. """
  82. log.info('client info: %s' % client_info)
  83. self.client_id = client_info['handle']
  84. self.is_client_mod = client_info['mod']
  85. self.is_client_owner = client_info['owner']
  86. client = self.users.add(client_info)
  87. client.user_level = 0
  88. self.console_write(pinylib.COLOR['bright_green'], 'Client joined the room: %s:%s' % (client.nick, client.id))
  89.  
  90. # do special operations.
  91. threading.Thread(target=self.options).start()
  92. #threading.Thread(target=self.clock).start()
  93. #self.send_chat_msg('SpamFairy is Online!\nVIP Status: %s' % pinylib.CONFIG.B_vip)
  94.  
  95.  
  96. test = None
  97. def on_join(self, join_info):
  98. """
  99. Received when a user joins the room.
  100.  
  101. :param join_info: This contains user information such as role, account and so on.
  102. :type join_info: dict
  103. """
  104. log.info('user join info: %s' % join_info)
  105. _user = self.users.add(join_info)
  106.  
  107. adminlist = open(self.config_path + pinylib.CONFIG.B_Admins).read().splitlines()
  108. #known =
  109. knownlist = open(self.config_path + pinylib.CONFIG.B_known).read().splitlines()
  110. #if self.active_user.account not in knownlist:
  111. #self.do_ban(self.active_user.nick)
  112. #self.send_chat_msg("Guest - %s not allowed." % self.active_user.account)
  113. if not _user.account in knownlist:
  114. #self.send_chat_msg('%s not known.' % _user.account )
  115. print('========== %s not known.' % _user.account)
  116.  
  117. if pinylib.CONFIG.B_CheckUser:
  118. self.send_chat_msg('%s not VIP - use !knownadd %s' % (_user.nick, _user.account))
  119.  
  120. if pinylib.CONFIG.B_vip:
  121. #self.do_bad_nick(self.active_user.nick)
  122. self.do_kick(_user.nick)
  123. self.send_chat_msg('VIP to %s Denied - use !knownadd %s' % (_user.nick, _user.account))
  124. print('========== VIP Denied - %s' % _user.account)
  125.  
  126. # If account is in known.txt print, sending to chat will get kicked for spam.
  127. if _user.account in knownlist:
  128. #self.send_chat_msg('%s is known.' % _user.account )
  129. print('========== %s is known.' % _user.account)
  130.  
  131. # If a nickname starts with guest- such as guest-0001
  132. if _user.nick.startswith('guest-'):
  133. #self.send_chat_msg("guest")
  134. self.do_ban(self.active_user.nick)
  135. self.send_chat_msg("Guest names not allowed.")
  136.  
  137.  
  138. if _user.account:
  139.  
  140.  
  141.  
  142. if _user.is_owner or _user.account in adminlist:
  143. _user.user_level = 1
  144. self.console_write(pinylib.COLOR['red'], 'Room Owner %s:%d:%s' % (_user.nick, _user.id, _user.account))
  145. if not _user.account in knownlist:
  146.  
  147. pinylib.file_handler.file_writer(self.config_path, pinylib.CONFIG.B_known, _user.account)
  148. self.send_chat_msg('Admin saved to whitelist: %s' % _user.account)
  149. #self.send_chat_msg('Room Owner %s has joined.' % _user.nick)
  150.  
  151. elif _user.is_mod:
  152.  
  153. _user.user_level = 3
  154. self.console_write(pinylib.COLOR['bright_red'], 'Moderator %s:%d:%s' % (_user.nick, _user.id, _user.account))
  155. if not _user.account in knownlist:
  156.  
  157. pinylib.file_handler.file_writer(self.config_path, pinylib.CONFIG.B_known, _user.account)
  158. self.send_chat_msg('Mod saved to whitelist: %s' % _user.account)
  159.  
  160.  
  161. else:
  162. self.console_write(pinylib.COLOR['bright_yellow'], '%s:%d has account: %s' % (_user.nick, _user.id, _user.account))
  163.  
  164.  
  165.  
  166. if not self.user_check(_user, account=True, guest=True, nick=True, lurker=True):
  167.  
  168.  
  169. if pinylib.CONFIG.B_GREET and self.is_client_mod:
  170.  
  171. if not _user.nick.startswith('guest-'):
  172.  
  173. if _user.account:
  174.  
  175. self.send_chat_msg('Welcome ' + _user.nick)
  176. else:
  177. #self.do_ban(_user.nick)
  178. #self.send_chat_msg(heart + 'Welcome to the room %s:%s' % (_user.nick, _user.id))
  179. self.send_chat_msg('Welcome ' + _user.nick)
  180. self.console_write(pinylib.COLOR['cyan'], '%s:%d joined the room.' % (_user.nick, _user.id))
  181.  
  182. def on_nick(self, uid, nick):
  183. """
  184. Received when a user changes nick name.
  185.  
  186. :param uid: The ID (handle) of the user.
  187. :type uid: int
  188. :param nick: The new nick name.
  189. :type nick: str
  190. """
  191. _user = self.users.search(uid)
  192. old_nick = _user.nick
  193. _user.nick = nick
  194.  
  195.  
  196. if uid != self.client_id:
  197. if not self.user_check(_user, nick=True):
  198. if pinylib.CONFIG.B_GREET and self.is_client_mod:
  199. if old_nick.startswith('guest-'):
  200. if _user.account:
  201. self.send_chat_msg('Welcome to the room %s:%s:%s' %
  202. (_user.nick, _user.id, _user.account))
  203. else:
  204. self.send_chat_msg('Welcome to the room %s:%s' % (_user.nick, _user.id))
  205.  
  206. self.console_write(pinylib.COLOR['bright_cyan'], '%s:%s Changed nick to: %s' % (old_nick, uid, nick))
  207.  
  208. def on_yut_play(self, yt_data):
  209. """
  210. Received when a youtube gets started or time searched.
  211.  
  212. This also gets received when the client starts a youtube, the information is
  213. however ignored in that case.
  214.  
  215. :param yt_data: The event information contains info such as the ID (handle) of the user
  216. starting/searching the youtube, the youtube ID, youtube time and so on.
  217. :type yt_data: dict
  218. """
  219. if self.playlist.has_active_track:
  220. self.cancel_timer()
  221.  
  222. track = youtube.video_details(yt_data['item']['id'], False)
  223.  
  224. if 'handle' in yt_data:
  225. if yt_data['handle'] != self.client_id:
  226. _user = self.users.search(yt_data['handle'])
  227.  
  228. if yt_data['item']['offset'] == 0:
  229. self.playlist.start(_user.nick, track)
  230. self.timer(track.time)
  231. self.console_write(pinylib.COLOR['bright_magenta'], '%s started youtube video (%s)' %
  232. (_user.nick, track.title))
  233.  
  234. elif yt_data['item']['offset'] > 0:
  235. offset = self.playlist.play(yt_data['item']['offset'])
  236. self.timer(offset)
  237. self.console_write(pinylib.COLOR['bright_magenta'], '%s searched the youtube video to: %s' %
  238. (_user.nick, int(round(yt_data['item']['offset']))))
  239. else:
  240. if yt_data['item']['offset'] > 0:
  241. self.playlist.start('started before joining.', track)
  242. offset = self.playlist.play(yt_data['item']['offset'])
  243. self.timer(offset)
  244.  
  245. def on_yut_pause(self, yt_data):
  246. """
  247. Received when a youtube gets paused or searched while paused.
  248.  
  249. This also gets received when the client pauses or searches while paused, the information is
  250. however ignored in that case.
  251.  
  252. :param yt_data: The event information contains info such as the ID (handle) of the user
  253. pausing/searching the youtube, the youtube ID, youtube time and so on.
  254. :type yt_data: dict
  255. """
  256. if self.playlist.has_active_track:
  257. self.cancel_timer()
  258.  
  259. self.playlist.pause()
  260.  
  261. if 'handle' in yt_data:
  262. if yt_data['handle'] != self.client_id:
  263. _user = self.users.search(yt_data['handle'])
  264. self.console_write(pinylib.COLOR['bright_magenta'], '%s paused the video at %s' %
  265. (_user.nick, int(round(yt_data['item']['offset']))))
  266. else:
  267. log.info('no handle for youtube pause: %s' % yt_data)
  268.  
  269.  
  270. def message_handler(self, msg):
  271. """
  272. A basic handler for chat messages.
  273.  
  274. Overrides message_handler in pinylib
  275. to allow commands.enied.')"""
  276. #msg = (msg)
  277. prefix = pinylib.CONFIG.B_PREFIX
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284. #d3m = unicode('Ḑ̴̛̖͔͚̞̯̝͊͒̊̐̒͂̍͌̊̿̔3̴̡͎̲̣̪͕̰͖͍̻̦̥̝̭͆̐̀͑̈́̐̅́̔̅͜M̴̡̼̗̰͊̈͐̚͠ 🌱 卐 ̶̨̟̦̪̲͌̐̏̑͌́̽̿̍̔͊̕̕͜͜Ḋ̶̡̛̦͉̐͌̊̓̓̈́͂̋̈́̔͘͘͝3̶̧̡͕̮͔̦̀̍̐̑̿͝M̴̞̲͈͙̞̫̀̊̈̄̔̅̅̈́̒͝ͅ🌱 卐 ̴͇̟͖̓̋͑̌̇͑̿͗̕͝͝D̶̼̙̈́̎̇̊̒̚͝͝3̷̨̨̘̬̯̦̥̮̳̞́̐̌̌̋̊̍M̷̨̤̊̔̽͊͐̉̍̓̈́̋̄̓̑̈́͘͜🌱 卐 ̷̛̻͕̼̟͉̭̋̒͗͝D̶͈̟̣̼͔̟̤̏͗̚͠ͅ3̴̛̙̠͖̾̃̈́̏̊̅͠M̶͉͎͕͓̗̂͆̓̊͊͑̏̓͐͋̄͘͝🌱 卐 ̴̢̧̛͎͔͉͚͔̯̿̒D̵̜͉̖͖̹͊͌̈͊̍̂̽̈̿̔̄͂͂͝3̴̧̭̳̤̗̞̺͆͆̒͠M̷̛͖͇̹͙̰̬̟̬͗̑̀̿̄͒̓̕͠ ̵͙́̇̇̍̌̓́͐̃̋͠͠🌱 卐D̴͉̺͋̑͑̄͊͜3̸̨̞͔̻̞͑M̷̛̛̝͗͑̿̈̏̀͆̿̆́͗̋̈́🌱 卐 ̴̡̜̭̦̟̜̗͎̬̞̝̖͎̬̀͗̓͌͌̾̂̈͝Ḑ̶͎̦̖͙̠̩̎̀̓̒͛ͅ3̸̞͍̘̫̮͙͚̘̿̊̀̂͒̓̄̎͝ͅM̵̢̢̟̮͓̹̦̥̗̈́̌͊̑̈́̀̋̈́͗̑̐̓̕̚̚ 🌱 卐', 'utf-8')
  285.  
  286. # Only check chat msg for ban string if we are mod.
  287. if self.is_client_mod and self.active_user.user_level > 4:
  288. threading.Thread(target=self.check_msg, args=(msg,)).start()
  289.  
  290.  
  291.  
  292. #░
  293.  
  294. if "\n" in msg:
  295. self.do_ban(self.active_user.nick)
  296. #self.do_bad_nick(self.active_user.nick)
  297. if len(msg) > 250:
  298. self.do_ban(self.active_user.nick)
  299. #self.do_bad_nick(self.active_user.nick)
  300. self.send_chat_msg("Spam Detected (%s)!" % len(msg))
  301.  
  302.  
  303. #if msg.startswith(unicode('⭕', 'utf-8')):
  304. #self.do_ban(self.active_user.nick)
  305. if msg.startswith(prefix):
  306.  
  307. parts = msg.split(' ')
  308. cmd = parts[0].lower().strip()
  309. cmd_arg = ' '.join(parts[1:]).strip()
  310.  
  311.  
  312. #admin/botowner
  313. if self.has_level(1):
  314. if self.is_client_owner:
  315.  
  316.  
  317.  
  318. if cmd == prefix + 'mod':
  319. threading.Thread(target=self.do_make_mod, args=(cmd_arg,)).start()
  320.  
  321.  
  322.  
  323. elif cmd == prefix + 'rmod':
  324. threading.Thread(target=self.do_remove_mod, args=(cmd_arg,)).start()
  325.  
  326. elif cmd == prefix + 'dir':
  327. threading.Thread(target=self.do_directory).start()
  328.  
  329. elif cmd == prefix + 'p2t':
  330. threading.Thread(target=self.do_push2talk).start()
  331.  
  332. elif cmd == prefix + 'crb':
  333. threading.Thread(target=self.do_clear_room_bans).start()
  334.  
  335. if cmd == prefix + 'kill':
  336. self.do_kill()
  337.  
  338. elif cmd == prefix + 'reboot':
  339. self.do_reboot()
  340.  
  341. #admin
  342. if self.has_level(2):
  343. if cmd == prefix + 'mi':
  344. self.do_media_info()
  345.  
  346.  
  347. elif cmd == prefix + 'spam':
  348. #self.send_chat_msg(tt)
  349. self.do_spam()
  350.  
  351. # elif cmd == prefix + "vip":
  352.  
  353. #self.do_vip()
  354.  
  355. elif cmd == prefix + 'crb':
  356. threading.Thread(target=self.do_clear_room_bans).start()
  357.  
  358. elif cmd == prefix + 'noguest':
  359. self.do_guests()
  360.  
  361. elif cmd == prefix + 'lurkers':
  362. self.do_lurkers()
  363.  
  364. elif cmd == prefix + 'guestnick':
  365. self.do_guest_nicks()
  366.  
  367. elif cmd == prefix + 'greet':
  368. self.do_greet()
  369.  
  370. elif cmd == prefix + 'kab':
  371. self.do_kick_as_ban()
  372.  
  373. elif cmd == prefix + 'rs':
  374. self.do_room_settings()
  375.  
  376. elif cmd == prefix + 'v':
  377. self.do_version()
  378.  
  379. elif cmd == prefix + 't':
  380. self.do_uptime()
  381.  
  382. elif cmd == prefix + 'nick':
  383. self.do_nick(cmd_arg)
  384.  
  385. #botmods
  386. if self.has_level(3):
  387.  
  388. if cmd == prefix + 'op':
  389. self.do_op_user(cmd_arg)
  390.  
  391. elif cmd == prefix + 'nick':
  392. self.do_nick(cmd_arg)
  393.  
  394. elif cmd == prefix + 'knownadd':
  395. pinylib.file_handler.file_writer(self.config_path, pinylib.CONFIG.B_known, cmd_arg)
  396. self.send_chat_msg('Saved to whitelist: %s' % cmd_arg)
  397.  
  398. elif cmd == prefix + 'knownremove':
  399.  
  400. pinylib.file_handler.remove_from_file(self.config_path, pinylib.CONFIG.B_known, cmd_arg)
  401. self.send_chat_msg('Removed from whitelist: %s' % cmd_arg)
  402.  
  403. elif cmd == prefix + "vip":
  404.  
  405. self.do_vip()
  406.  
  407. elif cmd == prefix + "checkuser":
  408.  
  409. self.do_vipcheck()
  410. #elif cmd == prefix + 'd3m':
  411.  
  412. #self.send_chat_msg(d3m)
  413.  
  414. elif cmd == prefix + 'deop':
  415. self.do_deop_user(cmd_arg)
  416.  
  417. elif cmd == prefix + 'pub':
  418. self.do_public_cmds()
  419.  
  420. elif cmd == prefix + 'kick':
  421. threading.Thread(target=self.do_kick, args=(cmd_arg,)).start()
  422.  
  423. elif cmd == prefix + 'ban':
  424. threading.Thread(target=self.do_ban, args=(cmd_arg,)).start()
  425.  
  426. elif cmd == prefix + 'bn':
  427. self.do_bad_nick(cmd_arg)
  428.  
  429. elif cmd == prefix + 'rmbn':
  430. self.do_remove_bad_nick(cmd_arg)
  431.  
  432. elif cmd == prefix + 'bs':
  433. self.do_bad_string(cmd_arg)
  434.  
  435. elif cmd == prefix + 'rmbs':
  436. self.do_remove_bad_string(cmd_arg)
  437.  
  438. elif cmd == prefix + 'ba':
  439. self.do_bad_account(cmd_arg)
  440.  
  441. elif cmd == prefix + 'rmba':
  442. self.do_remove_bad_account(cmd_arg)
  443.  
  444. elif cmd == prefix + 't':
  445. self.do_uptime()
  446.  
  447. elif cmd == prefix + 'list':
  448. #self.do_list_info(cmd_arg)
  449. self.send_chat_msg('Joke API Disabled.')
  450.  
  451. elif cmd == prefix + 'uinfo':
  452. self.do_user_info(cmd_arg)
  453.  
  454. elif cmd == prefix + 'cam':
  455. self.do_cam_approve(cmd_arg)
  456.  
  457. elif cmd == prefix + 'close':
  458. self.do_close_broadcast(cmd_arg)
  459.  
  460. elif cmd == prefix + 'sbl':
  461. self.do_banlist_search(cmd_arg)
  462.  
  463. elif cmd == prefix + 'fg':
  464. self.do_forgive(cmd_arg)
  465.  
  466. elif cmd == prefix + 'unban':
  467. self.do_unban(cmd_arg)
  468.  
  469. elif cmd == prefix + 'movie':
  470. #self.do_Movie(cmd_arg)
  471. threading.Thread(target=self.do_Movie, args=(cmd_arg,)).start()
  472. elif cmd == prefix + 'clear':
  473. self.do_clear()
  474.  
  475. elif cmd == prefix + "whiteknight":
  476. self.send_chat_msg('White Knight has been awarded to %s' % cmd_arg)
  477.  
  478.  
  479. #Moderators
  480. if self.has_level(4):
  481.  
  482. if cmd == prefix + 'help':
  483. self.do_help()
  484.  
  485. elif cmd == prefix + 'top':
  486. threading.Thread(target=self.do_lastfm_chart, args=(cmd_arg,)).start()
  487.  
  488. elif cmd == prefix + 'ran':
  489. threading.Thread(target=self.do_lastfm_random_tunes, args=(cmd_arg,)).start()
  490.  
  491. elif cmd == prefix + 'tag':
  492. threading.Thread(target=self.do_search_lastfm_by_tag, args=(cmd_arg,)).start()
  493.  
  494. elif cmd == prefix + 'pls':
  495. threading.Thread(target=self.do_youtube_playlist_search, args=(cmd_arg,)).start()
  496.  
  497. elif cmd == prefix + 'plp':
  498. threading.Thread(target=self.do_play_youtube_playlist, args=(cmd_arg,)).start()
  499.  
  500. elif cmd == prefix + 'ssl':
  501. self.do_show_search_list()
  502.  
  503. elif cmd == prefix + 'del':
  504. self.do_delete_playlist_item(cmd_arg)
  505.  
  506. elif cmd == prefix + 'rpl':
  507. self.do_media_replay()
  508.  
  509. elif cmd == prefix + 'mbpl':
  510. self.do_play_media()
  511.  
  512. elif cmd == prefix + 'mbpa':
  513. self.do_media_pause()
  514.  
  515. elif cmd == prefix + 'seek':
  516. self.do_seek_media(cmd_arg)
  517.  
  518. elif cmd == prefix + 'cm':
  519. self.do_close_media()
  520.  
  521. elif cmd == prefix + 'cpl':
  522. self.do_clear_playlist()
  523.  
  524. elif cmd == prefix + 'spl':
  525. self.do_playlist_info()
  526.  
  527. elif cmd == prefix + 'yts':
  528. threading.Thread(target=self.do_youtube_search, args=(cmd_arg,)).start()
  529.  
  530. elif cmd == prefix + 'pyts':
  531. self.do_play_youtube_search(cmd_arg)
  532.  
  533. elif cmd == prefix + 'jeopardy':
  534. threading.Thread(target=self.jeo).start()
  535.  
  536. elif cmd == prefix + 'word':
  537. threading.Thread(target=self.GetScramble).start()
  538.  
  539. elif cmd == prefix + 'hyde':
  540. self.do_Hyde()
  541.  
  542. elif cmd == prefix + 'commands':
  543. threading.Thread(target=self.do_commands).start()
  544.  
  545. elif cmd == prefix + 'ytadd':
  546.  
  547. pinylib.file_handler.file_writer(self.config_path, pinylib.CONFIG.B_Youtube_Play_List, cmd_arg)
  548. self.send_chat_msg('Saved to Youtube Log: %s' % cmd_arg)
  549.  
  550. elif cmd == prefix + 'ytban' :
  551.  
  552. pinylib.file_handler.file_writer(self.config_path, pinylib.CONFIG.B_Youtube_Ban_List, cmd_arg)
  553. self.send_chat_msg('Saved to Youtube Filter: %s' % cmd_arg)
  554.  
  555.  
  556. elif cmd == prefix + 'ytunban':
  557.  
  558. pinylib.file_handler.remove_from_file(self.config_path, pinylib.CONFIG.B_Youtube_Ban_List, cmd_arg)
  559. self.send_chat_msg('Removed from Youtube Filter: %s' % cmd_arg)
  560.  
  561. elif cmd == prefix + 'ytremove':
  562.  
  563. pinylib.file_handler.remove_from_file(self.config_path, pinylib.CONFIG.B_Youtube_Play_List, cmd_arg)
  564. self.send_chat_msg('Removed from Youtube Log: %s' % cmd_arg)
  565.  
  566. elif cmd == prefix + 'ytlog':
  567. lines = open(self.config_path + pinylib.CONFIG.B_Youtube_Play_List).read().splitlines()
  568. myline =random.choice(lines)
  569. #self.send_chat_msg(myline)
  570.  
  571. results = myline
  572. threading.Thread(target=self.do_play_youtube, args=(results,)).start()
  573. self.send_chat_msg("Random Song: %s" % results)
  574.  
  575.  
  576. ytbanlist = open(self.config_path + pinylib.CONFIG.B_Youtube_Ban_List).read().splitlines()
  577. if (pinylib.CONFIG.B_PUBLIC_CMD and self.has_level(5)) or self.active_user.user_level < 5:
  578.  
  579. # Tinychat API commands.
  580. if cmd == prefix + 'acspy':
  581. threading.Thread(target=self.do_account_spy, args=(cmd_arg,)).start()
  582.  
  583. # Other API commands.
  584. elif cmd == prefix + 'urb':
  585. threading.Thread(target=self.do_search_urban_dictionary, args=(cmd_arg,)).start()
  586.  
  587. elif cmd == prefix + 'wea':
  588. threading.Thread(target=self.do_weather_search, args=(cmd_arg,)).start()
  589.  
  590. elif cmd == prefix + 'ip':
  591. threading.Thread(target=self.do_whois_ip, args=(cmd_arg,)).start()
  592.  
  593. # Just for fun.
  594. elif cmd == prefix + 'cn':
  595. threading.Thread(target=self.do_chuck_noris).start()
  596.  
  597. # Just for fun.
  598. elif cmd == prefix + 'check':
  599. threading.Thread(target=self.do_check).start()
  600.  
  601.  
  602.  
  603. elif cmd == prefix + '8ball':
  604. self.do_8ball(cmd_arg)
  605.  
  606. elif cmd == prefix + 'scope':
  607. self.do_scope(cmd_arg)
  608.  
  609. elif cmd == prefix + 'fact':
  610. self.do_fact()
  611.  
  612. elif cmd == prefix + 'joke':
  613. #self.do_joke()
  614. self.send_chat_msg('Joke API Disabled.')
  615.  
  616. elif cmd == prefix + 'mood':
  617. self.do_mood()
  618.  
  619. elif cmd == prefix + 'roll':
  620. self.do_dice()
  621.  
  622. elif cmd == prefix + "cookie":
  623. self.do_fortune()
  624.  
  625. elif cmd == prefix + "ltc":
  626. self.do_ltc()
  627.  
  628. elif cmd == prefix + "btc":
  629. self.do_bitcoin()
  630.  
  631. elif cmd == prefix + "xmr":
  632. self.do_xmr()
  633.  
  634. elif cmd == prefix + "eth":
  635. self.do_eth()
  636.  
  637. elif cmd == prefix + "sia":
  638. self.do_sia()
  639.  
  640. elif cmd == prefix + "gank":
  641. self.do_gank()
  642.  
  643. elif cmd == prefix + "pot":
  644. self.do_pot()
  645.  
  646. elif cmd == prefix + "jokes":
  647. self.do_joke()
  648.  
  649. elif cmd == prefix + "line":
  650. self.do_line()
  651.  
  652. elif cmd == prefix + "advice":
  653. self.do_Advice()
  654.  
  655. elif cmd == prefix + "mom":
  656. self.do_mom()
  657.  
  658. elif cmd == prefix + "trump":
  659. self.do_Trump()
  660.  
  661. elif cmd == prefix + "geek":
  662. self.do_Geek()
  663.  
  664.  
  665. elif cmd == prefix + "tokes":
  666. threading.Thread(target=self.toketimer).start()
  667.  
  668. #Bender · Isolate
  669. elif cmd == prefix + 'yt':
  670.  
  671. threading.Thread(target=self.do_play_youtube, args=(cmd_arg,)).start()
  672.  
  673. elif cmd == prefix + 'rules':
  674.  
  675. self.send_chat_msg("https://pastebin.com/UPFcaqck")
  676.  
  677. elif cmd == prefix + 'q':
  678. self.do_playlist_status()
  679.  
  680. elif cmd == prefix + 'n':
  681. self.do_next_tune_in_playlist()
  682.  
  683. elif cmd == prefix + 'np':
  684. self.do_now_playing()
  685.  
  686. elif cmd == prefix + 'wp':
  687. self.do_who_plays()
  688.  
  689. elif cmd == prefix + 'skip':
  690. self.do_skip()
  691.  
  692. #if cmd == prefix + 'msgme':
  693. #self.do_pmme()
  694.  
  695. # Print command to console.
  696. self.console_write(pinylib.COLOR['yellow'], self.active_user.nick + ': ' + cmd + ' ' + cmd_arg)
  697. else:
  698. # Print chat message to console.
  699. self.console_write(pinylib.COLOR['green'], self.active_user.nick + ': ' + msg)
  700.  
  701.  
  702. self.active_user.last_msg = msg
  703.  
  704.  
  705. def do_vip(self):
  706. """ Toggles if public commands are public or not. """
  707. pinylib.CONFIG.B_vip = not pinylib.CONFIG.B_vip
  708. self.send_chat_msg('VIP Enabled: %s' % pinylib.CONFIG.B_vip)
  709.  
  710. def do_vipcheck(self):
  711. """ Toggles if public commands are public or not. """
  712. pinylib.CONFIG.B_CheckUser = not pinylib.CONFIG.B_CheckUser
  713. self.send_chat_msg('VIP Check Enabled: %s' % pinylib.CONFIG.B_vip)
  714.  
  715. def toketimer(self):
  716.  
  717. self.send_chat_msg('Tokes in 3 mins.')
  718. time.sleep(1 * 60)
  719. self.send_chat_msg('Tokes in 2 mins.')
  720. time.sleep(1 * 60)
  721. self.send_chat_msg('Tokes in 1 mins.')
  722. time.sleep(1 * 60)
  723. self.send_chat_msg('Tokes started.')
  724.  
  725.  
  726. def jeo(self):
  727. url = "http://jservice.io/api/random"
  728. out = requests.get(url).text
  729. resp_dict = json.loads(out)
  730. question = resp_dict[0]['question']
  731. answer = resp_dict[0]['answer']
  732.  
  733.  
  734. self.send_chat_msg('Jeopoardy Question: \n"' + question + '."')
  735.  
  736. time.sleep(20)
  737. self.send_chat_msg('Jeopardy Answer (what/who is/are):\n "' + answer + '."')
  738.  
  739. def GetScramble(self):
  740.  
  741. words = ["arugola",
  742. "assenters",
  743. "atlee",
  744. "balatas",
  745. "basophilic",
  746. "bastinading",
  747. "begotten",
  748. "blameful",
  749. "bloodthirstiest",
  750. "bribeworthy",
  751. "burnoose",
  752. "calcaneonavicular",
  753. "cautionry",
  754. "cesure",
  755. "chimed",
  756. "classes",
  757. "commemorating",
  758. "cuchia",
  759. "decemviral",
  760. "decrepitness",
  761. "deloul",
  762. "doweled",
  763. "emeute",
  764. "excipule",
  765. "fractionizing",
  766. "galvanoplastically",
  767. "ganglionated",
  768. "gastrothecal",
  769. "gestalter",
  770. "gonidiferous",
  771. "gusle",
  772. "hairweaver",
  773. "hajji",
  774. "handmaid",
  775. "helminthosporium",
  776. "homecrofting",
  777. "immeasurably",
  778. "impregnant",
  779. "impunible",
  780. "infusedly",
  781. "initialed",
  782. "kahar",
  783. "kokum",
  784. "lactify",
  785. "lifen",
  786. "localistic",
  787. "manchild",
  788. "marrowed",
  789. "mennuet",
  790. "metachromatism",
  791. "mezuzah",
  792. "mishmi",
  793. "mothball",
  794. "nonaudibility",
  795. "nonemendation",
  796. "nonmilitarily",
  797. "oecist",
  798. "olfactories",
  799. "oppugner",
  800. "outpoll",
  801. "overfertility",
  802. "participatively",
  803. "pastils",
  804. "petrol",
  805. "polydomous",
  806. "polygalaceous",
  807. "porocephalus",
  808. "prissiest",
  809. "prodigy",
  810. "prussianization",
  811. "quantitied",
  812. "rancheros",
  813. "reargues",
  814. "reliability",
  815. "renopulmonary",
  816. "shakiest",
  817. "showerier",
  818. "sinuous",
  819. "speckled",
  820. "speedaway",
  821. "strawflower",
  822. "subcontraoctave",
  823. "sula",
  824. "swims",
  825. "tenfoldness",
  826. "tetraketone",
  827. "thoracoacromial",
  828. "tidecoach",
  829. "toxicology",
  830. "trespassory",
  831. "trochoids",
  832. "turkology",
  833. "unalerted",
  834. "unbarren",
  835. "unbutchered",
  836. "unexpiring",
  837. "unmangled",
  838. "unspiritedly",
  839. "unteeming",
  840. "vaccinee"]
  841.  
  842. word = random.choice(words)
  843.  
  844.  
  845. self.send_chat_msg('Scrambled Word: \n"' + ''.join(random.sample(word, len(word))))
  846. time.sleep(20)
  847. self.send_chat_msg('Scrambled Word Answer:\n "' + word + '."')
  848. # Level 1 Command methods.
  849. def do_make_mod(self, account):
  850. """
  851. Make a tinychat account a room moderator.
  852.  
  853. :param account: The account to make a moderator.
  854. :type account: str
  855. """
  856. if self.is_client_owner:
  857. if len(account) is 0:
  858. self.send_chat_msg('Missing account name.')
  859. else:
  860. tc_user = self.privacy_.make_moderator(account)
  861. if tc_user is None:
  862. self.send_chat_msg('The account is invalid.')
  863. elif not tc_user:
  864. self.send_chat_msg('%s is already a moderator.' % account)
  865. elif tc_user:
  866. self.send_chat_msg('%s was made a room moderator.' % account)
  867.  
  868. def do_remove_mod(self, account):
  869. """
  870. Removes a tinychat account from the moderator list.
  871.  
  872. :param account: The account to remove from the moderator list.
  873. :type account: str
  874. """
  875. if self.is_client_owner:
  876. if len(account) is 0:
  877. self.send_chat_msg('Missing account name.')
  878. else:
  879. tc_user = self.privacy_.remove_moderator(account)
  880. if tc_user:
  881. self.send_chat_msg('%s is no longer a room moderator.' % account)
  882. elif not tc_user:
  883. self.send_chat_msg('%s is not a room moderator.' % account)
  884.  
  885. def do_directory(self):
  886. """ Toggles if the room should be shown on the directory. """
  887. if self.is_client_owner:
  888. if self.privacy_.show_on_directory():
  889. self.send_chat_msg('Room IS shown on the directory.')
  890. else:
  891. self.send_chat_msg('Room is NOT shown on the directory.')
  892.  
  893. def do_push2talk(self):
  894. """ Toggles if the room should be in push2talk mode. """
  895. if self.is_client_owner:
  896. if self.privacy_.set_push2talk():
  897. self.send_chat_msg('Push2Talk is enabled.')
  898. else:
  899. self.send_chat_msg('Push2Talk is disabled.')
  900.  
  901. def do_green_room(self):
  902. """ Toggles if the room should be in greenroom mode. """
  903. if self.is_client_owner:
  904. if self.privacy_.set_greenroom():
  905. self.send_chat_msg('Green room is enabled.')
  906. else:
  907. self.send_chat_msg('Green room is disabled.')
  908.  
  909. def do_clear_room_bans(self):
  910. """ Clear all room bans. """
  911. if self.is_client_owner:
  912. if self.privacy_.clear_bans():
  913. self.send_chat_msg('All room bans was cleared.')
  914.  
  915. def do_kill(self):
  916. """ Kills the bot. """
  917. self.disconnect()
  918.  
  919. def do_reboot(self):
  920. """ Reboots the bot. """
  921. self.reconnect()
  922.  
  923. # Level 2 Command Methods.
  924. def do_media_info(self):
  925. """ Show information about the currently playing youtube. """
  926. if self.is_client_mod and self.playlist.has_active_track:
  927. self.send_chat_msg(
  928. 'Playlist Tracks: ' + str(len(self.playlist.track_list)) + '\n' +
  929. 'Track Title: ' + self.playlist.track.title + '\n' +
  930. 'Track Index: ' + str(self.playlist.track_index) + '\n' +
  931. 'Elapsed Track Time: ' + self.format_time(self.playlist.elapsed) + '\n' +
  932. 'Remaining Track Time: ' + self.format_time(self.playlist.remaining)
  933. )
  934.  
  935. # Level 3 Command Methods.
  936. def do_op_user(self, user_name):
  937. """
  938. Lets the room owner, a mod or a bot controller make another user a bot controller.
  939.  
  940. :param user_name: The user to op.
  941. :type user_name: str
  942. """
  943. if self.is_client_mod:
  944. if len(user_name) is 0:
  945. self.send_chat_msg('Missing username.')
  946. else:
  947. _user = self.users.search_by_nick(user_name)
  948. if _user is not None:
  949. _user.user_level = 4
  950. self.send_chat_msg('%s is now a bot controller (L4)' % user_name)
  951. else:
  952. self.send_chat_msg('No user named: %s' % user_name)
  953.  
  954. def do_deop_user(self, user_name):
  955. """
  956. Lets the room owner, a mod or a bot controller remove a user from being a bot controller.
  957.  
  958. :param user_name: The user to deop.
  959. :type user_name: str
  960. """
  961. if self.is_client_mod:
  962. if len(user_name) is 0:
  963. self.send_chat_msg('Missing username.')
  964. else:
  965. _user = self.users.search_by_nick(user_name)
  966. if _user is not None:
  967. _user.user_level = 5
  968. self.send_chat_msg('%s is not a bot controller anymore (L5)' % user_name)
  969. else:
  970. self.send_chat_msg('No user named: %s' % user_name)
  971.  
  972. def do_guests(self):
  973. """ Toggles if guests are allowed to join the room or not. """
  974. pinylib.CONFIG.B_ALLOW_GUESTS = not pinylib.CONFIG.B_ALLOW_GUESTS
  975. self.send_chat_msg('Allow Guests: %s' % pinylib.CONFIG.B_ALLOW_GUESTS)
  976.  
  977.  
  978. def do_spam(self):
  979. """ Toggles if guests are allowed to join the room or not. """
  980. pinylib.config.B_AllowSpam = not pinylib.config.B_AllowSpam
  981. self.send_chat_msg('Allow Spam: %s' % pinylib.config.B_AllowSpam)
  982.  
  983. def do_lurkers(self):
  984. """ Toggles if lurkers are allowed or not. """
  985. pinylib.CONFIG.B_ALLOW_LURKERS = not pinylib.CONFIG.B_ALLOW_LURKERS
  986. self.send_chat_msg('Allowe Lurkers: %s' % pinylib.CONFIG.B_ALLOW_LURKERS)
  987.  
  988. def do_guest_nicks(self):
  989. """ Toggles if guest nicks are allowed or not. """
  990. pinylib.CONFIG.B_ALLOW_GUESTS_NICKS = not pinylib.CONFIG.B_ALLOW_GUESTS_NICKS
  991. self.send_chat_msg('Allow Guest Nicks: %s' % pinylib.CONFIG.B_ALLOW_GUESTS_NICKS)
  992.  
  993. def do_greet(self):
  994. """ Toggles if users should be greeted on entry. """
  995. pinylib.CONFIG.B_GREET = not pinylib.CONFIG.B_GREET
  996. self.send_chat_msg('Greet Users: %s' % pinylib.CONFIG.B_GREET)
  997.  
  998. def do_public_cmds(self):
  999. """ Toggles if public commands are public or not. """
  1000. pinylib.CONFIG.B_PUBLIC_CMD = not pinylib.CONFIG.B_PUBLIC_CMD
  1001. self.send_chat_msg('Public Commands Enabled: %s' % pinylib.CONFIG.B_PUBLIC_CMD)
  1002.  
  1003. def do_kick_as_ban(self):
  1004. """ Toggles if kick should be used instead of ban for auto bans . """
  1005. pinylib.CONFIG.B_USE_KICK_AS_AUTOBAN = not pinylib.CONFIG.B_USE_KICK_AS_AUTOBAN
  1006. self.send_chat_msg('Use Kick As Auto Ban: %s' % pinylib.CONFIG.B_USE_KICK_AS_AUTOBAN)
  1007.  
  1008. def do_room_settings(self):
  1009. """ Shows current room settings. """
  1010. if self.is_client_owner:
  1011. settings = self.privacy_.current_settings()
  1012. self.send_chat_msg(
  1013. 'Broadcast Password: ' + settings['broadcast_pass'] + '\n' +
  1014. 'Room Password: ' + settings['room_pass'] + '\n' +
  1015. 'Login Type: ' + settings['allow_guest'] + '\n' +
  1016. 'Directory: ' + settings['show_on_directory'] + '\n' +
  1017. 'Push2Talk: ' + settings['push2talk'] + '\n' +
  1018. 'Greenroom: ' + settings['greenroom']
  1019. )
  1020.  
  1021. def do_lastfm_chart(self, chart_items):
  1022. """
  1023. Create a playlist from the most played tracks on last.fm.
  1024.  
  1025. :param chart_items: The maximum amount of chart items.
  1026. :type chart_items: str | int
  1027. """
  1028. if self.is_client_mod:
  1029. if len(chart_items) == 0 or chart_items is None:
  1030. self.send_chat_msg('Please specify the max amount of tracks you want.')
  1031. else:
  1032. try:
  1033. chart_items = int(chart_items)
  1034. except ValueError:
  1035. self.send_chat_msg('Only numbers allowed.')
  1036. else:
  1037. if 0 < chart_items < 30:
  1038. self.send_chat_msg('Please wait while creating a playlist...')
  1039. _items = lastfm.chart(chart_items)
  1040. if _items is not None:
  1041. self.playlist.add_list(self.active_user.nick, _items)
  1042. self.send_chat_msg('Added ' + str(len(_items)) + ' tracks from last.fm chart.')
  1043. if not self.playlist.has_active_track:
  1044. track = self.playlist.next_track
  1045. self.send_yut_play(track.id, track.time, track.title)
  1046. self.timer(track.time)
  1047. else:
  1048. self.send_chat_msg('Failed to retrieve a result from last.fm.')
  1049. else:
  1050. self.send_chat_msg('No more than 30 tracks.')
  1051.  
  1052. def do_lastfm_random_tunes(self, max_tracks):
  1053. """
  1054. Creates a playlist from what other people are listening to on last.fm
  1055.  
  1056. :param max_tracks: The miximum amount of tracks.
  1057. :type max_tracks: str | int
  1058. """
  1059. if self.is_client_mod:
  1060. if len(max_tracks) == 0 or max_tracks is None:
  1061. self.send_chat_msg('Please specify the max amount of tunes you want.')
  1062. else:
  1063. try:
  1064. max_tracks = int(max_tracks)
  1065. except ValueError:
  1066. self.send_chat_msg('Only numbers allowed.')
  1067. else:
  1068. if 0 < max_tracks < 50:
  1069. self.send_chat_msg('Please wait while creating playlist...')
  1070. _items = lastfm.listening_now(max_tracks)
  1071. if _items is not None:
  1072. self.playlist.add_list(self.active_user.nick, _items)
  1073. self.send_chat_msg('Added ' + str(len(_items)) + ' tracks from last.fm')
  1074. if not self.playlist.has_active_track:
  1075. track = self.playlist.next_track
  1076. self.send_yut_play(track.id, track.time, track.title)
  1077. self.timer(track.time)
  1078. else:
  1079. self.send_chat_msg('Failed to retrieve a result from last.fm.')
  1080. else:
  1081. self.send_chat_msg('No more than 50 tracks.')
  1082.  
  1083. def do_search_lastfm_by_tag(self, search_str):
  1084. """
  1085. Search last.fm for tunes matching a tag.
  1086.  
  1087. :param search_str: The search tag to search for.
  1088. :type search_str: str
  1089. """
  1090. if self.is_client_mod:
  1091. if len(search_str) == 0 or search_str is None:
  1092. self.send_chat_msg('Missing search string.')
  1093. else:
  1094. self.send_chat_msg('Please wait while creating playlist..')
  1095. _items = lastfm.tag_search(search_str)
  1096. if _items is not None:
  1097. self.playlist.add_list(self.active_user.nick, _items)
  1098. self.send_chat_msg('Added ' + str(len(_items)) + ' tracks from last.fm')
  1099. if not self.playlist.has_active_track:
  1100. track = self.playlist.next_track
  1101. self.send_yut_play(track.id, track.time, track.title)
  1102. self.timer(track.time)
  1103. else:
  1104. self.send_chat_msg('Failed to retrieve a result from last.fm.')
  1105.  
  1106. def do_youtube_playlist_search(self, search_str):
  1107. """
  1108. Search youtube for a playlist.
  1109.  
  1110. :param search_str: The search term to search for.
  1111. :type search_str: str
  1112. """
  1113. if self.is_client_mod:
  1114. if len(search_str) == 0:
  1115. self.send_chat_msg('Missing search string.')
  1116. else:
  1117. self.search_list = youtube.playlist_search(search_str)
  1118. if len(self.search_list) > 0:
  1119. self.is_search_list_yt_playlist = True
  1120. _ = '\n'.join('(%s) %s' % (i, d['playlist_title']) for i, d in enumerate(self.search_list))
  1121. self.send_chat_msg(_)
  1122. else:
  1123. self.send_chat_msg('Failed to find playlist matching search term: %s' % search_str)
  1124.  
  1125. def do_play_youtube_playlist(self, int_choice):
  1126. """
  1127. Play a previous searched playlist.
  1128.  
  1129. :param int_choice: The index of the playlist.
  1130. :type int_choice: str | int
  1131. """
  1132. if self.is_client_mod:
  1133. if self.is_search_list_yt_playlist:
  1134. try:
  1135. int_choice = int(int_choice)
  1136. except ValueError:
  1137. self.send_chat_msg('Only numbers allowed.')
  1138. else:
  1139. if 0 <= int_choice <= len(self.search_list) - 1:
  1140. self.send_chat_msg('Please wait while creating playlist..')
  1141. tracks = youtube.playlist_videos(self.search_list[int_choice])
  1142. if len(tracks) > 0:
  1143. self.playlist.add_list(self.active_user.nick, tracks)
  1144. self.send_chat_msg('Added %s tracks from youtube playlist.' % len(tracks))
  1145. if not self.playlist.has_active_track:
  1146. track = self.playlist.next_track
  1147. self.send_yut_play(track.id, track.time, track.title)
  1148. self.timer(track.time)
  1149. else:
  1150. self.send_chat_msg('Failed to retrieve videos from youtube playlist.')
  1151. else:
  1152. self.send_chat_msg('Please make a choice between 0-%s' % str(len(self.search_list) - 1))
  1153. else:
  1154. self.send_chat_msg('The search list does not contain any youtube playlist id\'s.')
  1155.  
  1156. def do_show_search_list(self):
  1157. """ Show what the search list contains. """
  1158. if self.is_client_mod:
  1159. if len(self.search_list) == 0:
  1160. self.send_chat_msg('The search list is empty.')
  1161. elif self.is_search_list_yt_playlist:
  1162. _ = '\n'.join('(%s) - %s' % (i, d['playlist_title']) for i, d in enumerate(self.search_list))
  1163. self.send_chat_msg('Youtube Playlist\'s\n' + _)
  1164. else:
  1165. _ = '\n'.join('(%s) %s %s' % (i, d['video_title'], self.format_time(d['video_time']))
  1166. for i, d in enumerate(self.search_list))
  1167. self.send_chat_msg('Youtube Tracks\n' + _)
  1168.  
  1169. # Level 4 Command Methods.
  1170. def do_skip(self):
  1171. """ Skip to the next item in the playlist. """
  1172. if self.is_client_mod:
  1173. if self.playlist.is_last_track is None:
  1174. self.send_chat_msg('No tunes to skip. The playlist is empty.')
  1175. elif self.playlist.is_last_track:
  1176. self.send_chat_msg('This is the last track in the playlist.')
  1177. else:
  1178. self.cancel_timer()
  1179. next_track = self.playlist.next_track
  1180. self.send_yut_play(next_track.id, next_track.time, next_track.title)
  1181. self.timer(next_track.time)
  1182.  
  1183. def do_delete_playlist_item(self, to_delete): # TODO: Make sure this is working.
  1184. """
  1185. Delete items from the playlist.
  1186.  
  1187. :param to_delete: Item indexes to delete.
  1188. :type to_delete: str
  1189. """
  1190. if self.is_client_mod:
  1191. if len(self.playlist.track_list) == 0:
  1192. self.send_chat_msg('The playlist is empty.')
  1193. elif len(to_delete) == 0:
  1194. self.send_chat_msg('No indexes provided.')
  1195. else:
  1196. indexes = None
  1197. by_range = False
  1198.  
  1199. try:
  1200. if ':' in to_delete:
  1201. range_indexes = map(int, to_delete.split(':'))
  1202. temp_indexes = range(range_indexes[0], range_indexes[1] + 1)
  1203. if len(temp_indexes) > 1:
  1204. by_range = True
  1205. else:
  1206. temp_indexes = map(int, to_delete.split(','))
  1207. except ValueError as ve:
  1208. log.error('wrong format: %s' % ve)
  1209. else:
  1210. indexes = []
  1211. for i in temp_indexes:
  1212. if i < len(self.playlist.track_list) and i not in indexes:
  1213. indexes.append(i)
  1214.  
  1215. if indexes is not None and len(indexes) > 0:
  1216. result = self.playlist.delete(indexes, by_range)
  1217. if result is not None:
  1218. if by_range:
  1219. self.send_chat_msg('Deleted from index: %s to index: %s' %
  1220. (result['from'], result['to']))
  1221. elif result['deleted_indexes_len'] is 1:
  1222. self.send_chat_msg('Deleted %s' % result['track_title'])
  1223. else:
  1224. self.send_chat_msg('Deleted tracks at index: %s' %
  1225. ', '.join(result['deleted_indexes']))
  1226. else:
  1227. self.send_chat_msg('Nothing was deleted.')
  1228.  
  1229. def do_media_replay(self):
  1230. """ Replay the currently playing track. """
  1231. if self.is_client_mod:
  1232. if self.playlist.track is not None:
  1233. self.cancel_timer()
  1234. track = self.playlist.replay()
  1235. self.send_yut_play(track.id, track.time, track.title)
  1236. self.timer(track.time)
  1237.  
  1238. def do_play_media(self):
  1239. """ Play a track on pause . """
  1240. if self.is_client_mod:
  1241. if self.playlist.track is not None:
  1242. if self.playlist.has_active_track:
  1243. self.cancel_timer()
  1244. if self.playlist.is_paused:
  1245. self.playlist.play(self.playlist.elapsed)
  1246. self.send_yut_play(self.playlist.track.id, self.playlist.track.time,
  1247. self.playlist.track.title, self.playlist.elapsed) #
  1248. self.timer(self.playlist.remaining)
  1249.  
  1250. def do_media_pause(self):
  1251. """ Pause a track. """
  1252. if self.is_client_mod:
  1253. track = self.playlist.track
  1254. if track is not None:
  1255. if self.playlist.has_active_track:
  1256. self.cancel_timer()
  1257. self.playlist.pause()
  1258. self.send_yut_pause(track.id, track.time, self.playlist.elapsed)
  1259.  
  1260. def do_close_media(self):
  1261. """ Close a track playing. """
  1262. if self.is_client_mod:
  1263. if self.playlist.has_active_track:
  1264. self.cancel_timer()
  1265. self.playlist.stop()
  1266. self.send_yut_stop(self.playlist.track.id, self.playlist.track.time, self.playlist.elapsed)
  1267.  
  1268.  
  1269. def do_seek_media(self, time_point):
  1270. """
  1271. Time search a track.
  1272.  
  1273. :param time_point: The time point in which to search to.
  1274. :type time_point: str
  1275. """
  1276. if self.is_client_mod:
  1277. if ('h' in time_point) or ('m' in time_point) or ('s' in time_point):
  1278. offset = pinylib.string_util.convert_to_seconds(time_point)
  1279. if offset == 0:
  1280. self.send_chat_msg('Invalid seek time.')
  1281. else:
  1282. track = self.playlist.track
  1283. if track is not None:
  1284. if 0 < offset < track.time:
  1285. if self.playlist.has_active_track:
  1286. self.cancel_timer()
  1287. if self.playlist.is_paused:
  1288. self.playlist.pause(offset=offset) #
  1289. self.send_yut_pause(track.id, track.time, offset)
  1290. else:
  1291. self.playlist.play(offset)
  1292. self.send_yut_play(track.id, track.time, track.title, offset)
  1293. self.timer(self.playlist.remaining)
  1294.  
  1295. def do_clear_playlist(self):
  1296. """ Clear the playlist for items."""
  1297. if self.is_client_mod:
  1298. if len(self.playlist.track_list) > 0:
  1299. pl_length = str(len(self.playlist.track_list))
  1300. self.playlist.clear()
  1301. self.send_chat_msg('Deleted %s items in the playlist.' % pl_length)
  1302. else:
  1303. self.send_chat_msg('The playlist is empty, nothing to delete.')
  1304.  
  1305. def do_playlist_info(self): # TODO: this needs more work !
  1306. """ Shows the next tracks in the playlist. """
  1307. if self.is_client_mod:
  1308. if len(self.playlist.track_list) > 0:
  1309. tracks = self.playlist.get_tracks()
  1310. if len(tracks) > 0:
  1311. # If i is 0 then mark that as the next track
  1312. _ = '\n'.join('(%s) - %s %s' % (track[0], track[1].title, self.format_time(track[1].time))
  1313. for i, track in enumerate(tracks))
  1314. self.send_chat_msg(_)
  1315.  
  1316. def do_youtube_search(self, search_str):
  1317. """
  1318. Search youtube for a list of matching candidates.
  1319.  
  1320. :param search_str: The search term to search for.
  1321. :type search_str: str
  1322. """
  1323. if self.is_client_mod:
  1324. if len(search_str) == 0:
  1325. self.send_chat_msg('Missing search string.')
  1326. else:
  1327. self.search_list = youtube.search_list(search_str, results=5)
  1328. if len(self.search_list) > 0:
  1329. self.is_search_list_yt_playlist = False
  1330. _ = '\n'.join('(%s) %s %s' % (i, d['video_title'], self.format_time(d['video_time']))
  1331. for i, d in enumerate(self.search_list)) #
  1332. self.send_chat_msg(_)
  1333. else:
  1334. self.send_chat_msg('Could not find anything matching: %s' % search_str)
  1335.  
  1336. def do_play_youtube_search(self, int_choice):
  1337. """
  1338. Play a track from a previous youtube search list.
  1339.  
  1340. :param int_choice: The index of the track in the search.
  1341. :type int_choice: str | int
  1342. """
  1343. if self.is_client_mod:
  1344. if not self.is_search_list_yt_playlist:
  1345. if len(self.search_list) > 0:
  1346. try:
  1347. int_choice = int(int_choice)
  1348. except ValueError:
  1349. self.send_chat_msg('Only numbers allowed.')
  1350. else:
  1351. if 0 <= int_choice <= len(self.search_list) - 1:
  1352.  
  1353. if self.playlist.has_active_track:
  1354. track = self.playlist.add(self.active_user.nick, self.search_list[int_choice])
  1355. self.send_chat_msg('Added (%s) %s %s' %
  1356. (self.playlist.last_index,
  1357. track.title, self.format_time(track.time)))
  1358. else:
  1359. track = self.playlist.start(self.active_user.nick, self.search_list[int_choice])
  1360. self.send_yut_play(track.id, track.time, track.title)
  1361. self.timer(track.time)
  1362. else:
  1363. self.send_chat_msg('Please make a choice between 0-%s' % str(len(self.search_list) - 1))
  1364. else:
  1365. self.send_chat_msg('No youtube track id\'s in the search list.')
  1366. else:
  1367. self.send_chat_msg('The search list only contains youtube playlist id\'s.')
  1368.  
  1369. def do_clear(self):
  1370. """ Clears the chat box. """
  1371. self.send_chat_msg('_\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n'
  1372. '\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n_')
  1373.  
  1374.  
  1375. def do_nick(self, new_nick):
  1376. """
  1377. Set a new nick for the bot.
  1378.  
  1379. :param new_nick: The new nick name.
  1380. :type new_nick: str
  1381. """
  1382. if len(new_nick) is 0:
  1383. self.nickname = pinylib.string_util.create_random_string(5, 25)
  1384. self.set_nick()
  1385. else:
  1386. self.nickname = new_nick
  1387. self.set_nick()
  1388.  
  1389. def do_kick(self, user_name):
  1390. """
  1391. Kick a user out of the room.
  1392.  
  1393. :param user_name: The username to kick.
  1394. :type user_name: str
  1395. """
  1396. if self.is_client_mod:
  1397. if len(user_name) is 0:
  1398. self.send_chat_msg('Missing username.')
  1399. elif user_name == self.nickname:
  1400. self.send_chat_msg('Action not allowed.')
  1401. else:
  1402. if user_name.startswith('*'):
  1403. user_name = user_name.replace('*', '')
  1404. _users = self.users.search_containing(user_name)
  1405. if len(_users) > 0:
  1406. for i, user in enumerate(_users):
  1407. if user.nick != self.nickname and user.user_level > self.active_user.user_level:
  1408. if i <= pinylib.CONFIG.B_MAX_MATCH_BANS - 1:
  1409. self.send_kick_msg(user.id)
  1410. else:
  1411. _user = self.users.search_by_nick(user_name)
  1412. if _user is None:
  1413. self.send_chat_msg('No user named: %s' % user_name)
  1414. elif _user.user_level < self.active_user.user_level:
  1415. self.send_chat_msg('Not allowed.')
  1416. else:
  1417. self.send_kick_msg(_user.id)
  1418.  
  1419. def do_ban(self, user_name):
  1420. """
  1421. Ban a user from the room.
  1422.  
  1423. :param user_name: The username to ban.
  1424. :type user_name: str
  1425. """
  1426. if self.is_client_mod:
  1427. if len(user_name) is 0:
  1428. self.send_chat_msg('Missing username.')
  1429. elif user_name == self.nickname:
  1430. self.send_chat_msg('Action not allowed.')
  1431. else:
  1432. if user_name.startswith('*'):
  1433. user_name = user_name.replace('*', '')
  1434. _users = self.users.search_containing(user_name)
  1435. if len(_users) > 0:
  1436. for i, user in enumerate(_users):
  1437. if user.nick != self.nickname and user.user_level > self.active_user.user_level:
  1438. if i <= pinylib.CONFIG.B_MAX_MATCH_BANS - 1:
  1439. self.send_ban_msg(user.id)
  1440. else:
  1441. _user = self.users.search_by_nick(user_name)
  1442. if _user is None:
  1443. self.send_chat_msg('No user named: %s' % user_name)
  1444. elif _user.user_level < self.active_user.user_level:
  1445. self.send_chat_msg('Not allowed.')
  1446. else:
  1447. self.send_ban_msg(_user.id)
  1448.  
  1449. def do_bad_nick(self, bad_nick):
  1450. """
  1451. Adds a username to the nick bans file.
  1452.  
  1453. :param bad_nick: The bad nick to write to the nick bans file.
  1454. :type bad_nick: str
  1455. """
  1456. if self.is_client_mod:
  1457. if len(bad_nick) is 0:
  1458. self.send_chat_msg('Missing username.')
  1459. elif bad_nick in pinylib.CONFIG.B_NICK_BANS:
  1460. self.send_chat_msg('%s is already in list.' % bad_nick)
  1461. else:
  1462. pinylib.file_handler.file_writer(self.config_path,
  1463. pinylib.CONFIG.B_NICK_BANS_FILE_NAME, bad_nick)
  1464. self.send_chat_msg('%s was added to file.' % bad_nick)
  1465. self.load_list(nicks=True)
  1466.  
  1467. def do_remove_ytlog(self, name):
  1468. """
  1469. Removes nick from the nick bans file.
  1470.  
  1471. :param bad_nick: The bad nick to remove from the nick bans file.
  1472. :type bad_nick: str
  1473. """
  1474. if self.is_client_mod:
  1475. if len(name) is 0:
  1476. self.send_chat_msg('Missing link...')
  1477. else:
  1478. if name in pinylib.CONFIG.B_Youtube_Play_List:
  1479. rem = pinylib.file_handler.remove_from_file(self.config_path,
  1480. pinylib.CONFIG.B_Youtube_Play_List,
  1481. name)
  1482. if rem:
  1483. self.send_chat_msg('%s was removed.' % bad_nick)
  1484. self.load_list(links=True)
  1485.  
  1486. def do_remove_bad_nick(self, bad_nick):
  1487. """
  1488. Removes nick from the nick bans file.
  1489.  
  1490. :param bad_nick: The bad nick to remove from the nick bans file.
  1491. :type bad_nick: str
  1492. """
  1493. if self.is_client_mod:
  1494. if len(bad_nick) is 0:
  1495. self.send_chat_msg('Missing username')
  1496. else:
  1497. if bad_nick in pinylib.CONFIG.B_NICK_BANS:
  1498. rem = pinylib.file_handler.remove_from_file(self.config_path,
  1499. pinylib.CONFIG.B_NICK_BANS_FILE_NAME,
  1500. bad_nick)
  1501. if rem:
  1502. self.send_chat_msg('%s was removed.' % bad_nick)
  1503. self.load_list(nicks=True)
  1504.  
  1505. def do_bad_string(self, bad_string):
  1506. """
  1507. Adds a string to the string bans file.
  1508.  
  1509. :param bad_string: The bad string to add to the string bans file.
  1510. :type bad_string: str
  1511. """
  1512. if self.is_client_mod:
  1513. if len(bad_string) is 0:
  1514. self.send_chat_msg('Ban string can\'t be blank.')
  1515. elif len(bad_string) < 1:
  1516. self.send_chat_msg('Ban string to short: ' + str(len(bad_string)))
  1517. elif bad_string in pinylib.CONFIG.B_STRING_BANS:
  1518. self.send_chat_msg('%s is already in list.' % bad_string)
  1519. else:
  1520. pinylib.file_handler.file_writer(self.config_path,
  1521. pinylib.CONFIG.B_STRING_BANS_FILE_NAME, bad_string)
  1522. self.send_chat_msg('%s was added to file.' % bad_string)
  1523. self.load_list(strings=True)
  1524.  
  1525. def do_remove_bad_string(self, bad_string):
  1526. """
  1527. Removes a string from the string bans file.
  1528.  
  1529. :param bad_string: The bad string to remove from the string bans file.
  1530. :type bad_string: str
  1531. """
  1532. if self.is_client_mod:
  1533. if len(bad_string) is 0:
  1534. self.send_chat_msg('Missing word string.')
  1535. else:
  1536. if bad_string in pinylib.CONFIG.B_STRING_BANS:
  1537. rem = pinylib.file_handler.remove_from_file(self.config_path,
  1538. pinylib.CONFIG.B_STRING_BANS_FILE_NAME,
  1539. bad_string)
  1540. if rem:
  1541. self.send_chat_msg('%s was removed.' % bad_string)
  1542. self.load_list(strings=True)
  1543.  
  1544. def do_bad_account(self, bad_account_name):
  1545. """
  1546. Adds an account name to the account bans file.
  1547.  
  1548. :param bad_account_name: The bad account name to add to the account bans file.
  1549. :type bad_account_name: str
  1550. """
  1551. if self.is_client_mod:
  1552. if len(bad_account_name) is 0:
  1553. self.send_chat_msg('Account can\'t be blank.')
  1554. elif len(bad_account_name) < 1:
  1555. self.send_chat_msg('Account to short: ' + str(len(bad_account_name)))
  1556. elif bad_account_name in pinylib.CONFIG.B_ACCOUNT_BANS:
  1557. self.send_chat_msg('%s is already in list.' % bad_account_name)
  1558. else:
  1559. pinylib.file_handler.file_writer(self.config_path,
  1560. pinylib.CONFIG.B_ACCOUNT_BANS_FILE_NAME,
  1561. bad_account_name)
  1562. self.send_chat_msg('%s was added to file.' % bad_account_name)
  1563. self.load_list(accounts=True)
  1564.  
  1565. def do_remove_bad_account(self, bad_account):
  1566. """
  1567. Removes an account from the account bans file.
  1568.  
  1569. :param bad_account: The badd account name to remove from account bans file.
  1570. :type bad_account: str
  1571. """
  1572. if self.is_client_mod:
  1573. if len(bad_account) is 0:
  1574. self.send_chat_msg('Missing account.')
  1575. else:
  1576. if bad_account in pinylib.CONFIG.B_ACCOUNT_BANS:
  1577. rem = pinylib.file_handler.remove_from_file(self.config_path,
  1578. pinylib.CONFIG.B_ACCOUNT_BANS_FILE_NAME,
  1579. bad_account)
  1580. if rem:
  1581. self.send_chat_msg('%s was removed.' % bad_account)
  1582. self.load_list(accounts=True)
  1583.  
  1584. def do_list_info(self, list_type):
  1585. """
  1586. Shows info of different lists/files.
  1587.  
  1588. :param list_type: The type of list to find info for.
  1589. :type list_type: str
  1590. """
  1591. if self.is_client_mod:
  1592. if len(list_type) is 0:
  1593. self.send_chat_msg('Missing list type.')
  1594. else:
  1595. if list_type.lower() == 'bn':
  1596. if len(pinylib.CONFIG.B_NICK_BANS) is 0:
  1597. self.send_chat_msg('No items in this list.')
  1598. else:
  1599. self.send_chat_msg('%s nicks bans in list.' % len(pinylib.CONFIG.B_NICK_BANS))
  1600.  
  1601. elif list_type.lower() == 'bs':
  1602. if len(pinylib.CONFIG.B_STRING_BANS) is 0:
  1603. self.send_chat_msg('No items in this list.')
  1604. else:
  1605. self.send_chat_msg('%s string bans in list.' % pinylib.CONFIG.B_STRING_BANS)
  1606.  
  1607. elif list_type.lower() == 'ba':
  1608. if len(pinylib.CONFIG.B_ACCOUNT_BANS) is 0:
  1609. self.send_chat_msg('No items in this list.')
  1610. else:
  1611. self.send_chat_msg('%s account bans in list.' % pinylib.CONFIG.B_ACCOUNT_BANS)
  1612.  
  1613. elif list_type.lower() == 'bl':
  1614. if len(self.users.banned_users) == 0:
  1615. self.send_chat_msg('The banlist is empty.')
  1616. else:
  1617. _ban_list = '\n'.join('(%s) %s:%s [%s]' %
  1618. (i, banned_user.nick, banned_user.account, banned_user.ban_id)
  1619. for i, banned_user in enumerate(self.users.banned_users))
  1620. if len(_ban_list) > 150: # maybe have a B_MAX_MSG_LENGTH in config
  1621. # use string_util.chunk_string
  1622. pass
  1623. else:
  1624. self.send_chat_msg(_ban_list)
  1625.  
  1626. elif list_type.lower() == 'mods':
  1627. if self.is_client_owner:
  1628. if len(self.privacy_.room_moderators) is 0:
  1629. self.send_chat_msg('There is currently no moderators for this room.')
  1630. elif len(self.privacy_.room_moderators) is not 0:
  1631. mods = ', '.join(self.privacy_.room_moderators)
  1632. self.send_chat_msg('Moderators: ' + mods)
  1633.  
  1634. def do_user_info(self, user_name):
  1635. """
  1636. Shows user object info for a given user name.
  1637.  
  1638. :param user_name: The user name of the user to show the info for.
  1639. :type user_name: str
  1640. """
  1641. if self.is_client_mod:
  1642. if len(user_name) is 0:
  1643. self.send_chat_msg('Missing username.')
  1644. else:
  1645. _user = self.users.search_by_nick(user_name)
  1646. if _user is None:
  1647. self.send_chat_msg('No user named: %s' % user_name)
  1648. else:
  1649. if _user.account and _user.tinychat_id is None:
  1650. user_info = pinylib.apis.tinychat.user_info(_user.account)
  1651. if user_info is not None:
  1652. _user.tinychat_id = user_info['tinychat_id']
  1653. _user.last_login = user_info['last_active']
  1654. online_time = (pinylib.time.time() - _user.join_time)
  1655.  
  1656. info = [
  1657. 'User Level: ' + str(_user.user_level),
  1658. 'Online Time: ' + self.format_time(online_time),
  1659. 'Last Message: ' + str(_user.last_msg)
  1660. ]
  1661. if _user.tinychat_id is not None:
  1662. info.append('Account: ' + str(_user.account))
  1663. info.append('Tinychat ID: ' + str(_user.tinychat_id))
  1664. info.append('Last Login: ' + _user.last_login)
  1665.  
  1666. self.send_chat_msg('\n'.join(info))
  1667.  
  1668. def do_cam_approve(self, user_name):
  1669. """
  1670. Allow a user to broadcast in a green room enabled room.
  1671.  
  1672. :param user_name: The name of the user allowed to broadcast.
  1673. :type user_name: str
  1674. """
  1675. if self.is_green_room and self.is_client_mod:
  1676. if len(user_name) == 0 and self.active_user.is_waiting:
  1677. self.send_cam_approve_msg(self.active_user.id)
  1678. elif len(user_name) > 0:
  1679. _user = self.users.search_by_nick(user_name)
  1680. if _user is not None and _user.is_waiting:
  1681. self.send_cam_approve_msg(_user.id)
  1682. else:
  1683. self.send_chat_msg('No user named: %s' % user_name)
  1684.  
  1685. def do_close_broadcast(self, user_name):
  1686. """
  1687. Close a users broadcast.
  1688.  
  1689. :param user_name: The name of the user to close.
  1690. :type user_name: str
  1691. """
  1692. if self.is_client_mod:
  1693. if len(user_name) == 0:
  1694. self.send_chat_msg('Missing user name.')
  1695. else:
  1696. _user = self.users.search_by_nick(user_name)
  1697. if _user is not None and _user.is_broadcasting:
  1698. self.send_close_user_msg(_user.id)
  1699. else:
  1700. self.send_chat_msg('No user named: %s' % user_name)
  1701.  
  1702. def do_banlist_search(self, user_name):
  1703. """
  1704. Search the banlist for matches.
  1705.  
  1706. NOTE: This method/command was meant to be a private message command,
  1707. but it seems like the private messages is broken, so for now
  1708. it will be a room command.
  1709.  
  1710. :param user_name: The user name or partial username to search for.
  1711. :type user_name: str
  1712. """
  1713. if self.is_client_mod:
  1714. if len(user_name) == 0:
  1715. self.send_chat_msg('Missing user name to search for.')
  1716. else:
  1717. self.bl_search_list = self.users.search_banlist_containing(user_name)
  1718. if len(self.bl_search_list) == 0:
  1719. self.send_chat_msg('No banlist matches.')
  1720. else:
  1721. _ban_list_info = '\n'.join('(%s) %s:%s [%s]' % (i, user.nick, user.account, user.ban_id)
  1722. for i, user in enumerate(self.bl_search_list))
  1723. # maybe user string_util.chunk_string here
  1724. self.send_chat_msg(_ban_list_info)
  1725.  
  1726. def do_forgive(self, user_index):
  1727. """
  1728. Forgive a user from the ban list search.
  1729.  
  1730. NOTE: This method/command was meant to be a private message command,
  1731. but it seems like the private messages is broken, so for now
  1732. it will be a room command.
  1733.  
  1734. :param user_index: The index in the ban list search.
  1735. :type user_index: str | int
  1736. """
  1737. if self.is_client_mod:
  1738. try:
  1739. user_index = int(user_index)
  1740. except ValueError:
  1741. self.send_chat_msg('Only numbers allowed (%s)' % user_index)
  1742. else:
  1743. if len(self.bl_search_list) > 0:
  1744. if user_index <= len(self.bl_search_list) - 1:
  1745. self.send_unban_msg(self.bl_search_list[user_index].ban_id)
  1746. else:
  1747. if len(self.bl_search_list) > 1:
  1748. self.send_chat_msg(
  1749. 'Please make a choice between 0-%s' % len(self.bl_search_list))
  1750. else:
  1751. self.send_chat_msg('The ban search is empty.')
  1752.  
  1753. # self.bl_search_list[:] = []
  1754.  
  1755. def do_unban(self, user_name):
  1756. """
  1757. Un-ban the last banned user or a user by user name.
  1758.  
  1759. NOTE: experimental. In case the user name match more than one
  1760. user in the banlist, then the last banned user will be unbanned.
  1761.  
  1762. :param user_name: The exact user name to unban.
  1763. :type user_name: str
  1764. """
  1765. if self.is_client_mod:
  1766. if len(user_name.strip()) == 0:
  1767. self.send_chat_msg('Missing user name.')
  1768. elif user_name == '/': # shortcut to the last banned user.
  1769. last_banned_user = self.users.last_banned
  1770. if last_banned_user is not None:
  1771. self.send_unban_msg(last_banned_user.ban_id)
  1772. else:
  1773. self.send_chat_msg('Failed to find the last banned user.')
  1774. else:
  1775. banned_user = self.users.search_banlist_by_nick(user_name)
  1776. if banned_user is not None:
  1777. self.send_unban_msg(banned_user.ban_id)
  1778. else:
  1779. self.send_chat_msg('No user named: %s in the banlist.' % user_name)
  1780.  
  1781. # Public (Level 5) Command Methods.
  1782. def do_playlist_status(self):
  1783. """ Shows the playlist queue. """
  1784. if self.is_client_mod:
  1785. if len(self.playlist.track_list) == 0:
  1786. self.send_chat_msg('The playlist is empty.')
  1787. else:
  1788. queue = self.playlist.queue
  1789. if queue is not None:
  1790. self.send_chat_msg('%s items in the playlist, %s still in queue.' %
  1791. (queue[0], queue[1]))
  1792.  
  1793. def do_next_tune_in_playlist(self):
  1794. """ Shows the next track in the playlist. """
  1795. if self.is_client_mod:
  1796. if self.playlist.is_last_track is None:
  1797. self.send_chat_msg('The playlist is empty.')
  1798. elif self.playlist.is_last_track:
  1799. self.send_chat_msg('This is the last track.')
  1800. else:
  1801. pos, next_track = self.playlist.next_track_info()
  1802. if next_track is not None:
  1803. self.send_chat_msg('(%s) %s %s' %
  1804. (pos, next_track.title, self.format_time(next_track.time)))
  1805.  
  1806. def do_now_playing(self):
  1807. """ Shows what track is currently playing. """
  1808. if self.is_client_mod:
  1809. if self.playlist.has_active_track:
  1810. track = self.playlist.track
  1811. if len(self.playlist.track_list) > 0:
  1812. self.send_private_msg(self.active_user.id,
  1813. '(%s) %s %s' % (self.playlist.current_index, track.title,
  1814. self.format_time(track.time)))
  1815. else:
  1816. self.send_private_msg(self.active_user.id, '%s %s' %
  1817. (track.title, self.format_time(track.time)))
  1818. else:
  1819. self.send_private_msg(self.active_user.id, 'No track playing.')
  1820.  
  1821. def do_who_plays(self):
  1822. """ Show who requested the currently playing track. """
  1823. if self.is_client_mod:
  1824. if self.playlist.has_active_track:
  1825. track = self.playlist.track
  1826. ago = self.format_time(int(pinylib.time.time() - track.rq_time))
  1827. self.send_chat_msg('%s requested this track %s ago.' % (track.owner, ago))
  1828. else:
  1829. self.send_chat_msg('No track playing.')
  1830.  
  1831. def do_version(self):
  1832. """ Show version info. """
  1833. self.send_private_msg(self.active_user.id, 'tinybot %s pinylib %s' %
  1834. (__version__, pinylib.__version__))
  1835.  
  1836. def do_help(self):
  1837. """ Posts a link to github readme/wiki or other page about the bot commands. """
  1838. self.send_private_msg(self.active_user.id,
  1839. 'Help: https://github.com/nortxort/tinybot-rtc/wiki/commands')
  1840. def join_message():
  1841. self.send_private_msg(self.active_user.id,
  1842. 'This is an automatted message to fix a PM bug.')
  1843. def do_uptime(self):
  1844. """ Shows the bots uptime. """
  1845. self.send_chat_msg('Bot-Uptime: ' + self.format_time(self.get_runtime()))
  1846.  
  1847. def do_pmme(self):
  1848. """ Opens a PM session with the bot. """
  1849. self.send_private_msg(self.active_user.id, 'How can i help you %s?' % self.active_user.nick)
  1850.  
  1851. def do_play_youtube(self, search_str):
  1852. """
  1853. Plays a youtube video matching the search term.
  1854.  
  1855. :param search_str: The search term.
  1856. :type search_str: str
  1857. """
  1858.  
  1859. log.info('user: %s:%s is searching youtube: %s' % (self.active_user.nick, self.active_user.id, search_str))
  1860. if self.is_client_mod:
  1861. if len(search_str) is 0:
  1862. self.send_chat_msg('Please specify youtube title, id or link.')
  1863.  
  1864.  
  1865. else:
  1866. _youtube = youtube.search(search_str)
  1867.  
  1868.  
  1869. if _youtube is None:
  1870. log.warning('youtube request returned: %s' % _youtube)
  1871. self.send_chat_msg('Could not find video: ' + search_str)
  1872.  
  1873. else:
  1874. log.info('youtube found: %s' % _youtube)
  1875. if self.playlist.has_active_track:
  1876. track = self.playlist.add(self.active_user.nick, _youtube)
  1877. self.send_chat_msg('(%s) %s %s' %
  1878. (self.playlist.last_index, track.title, self.format_time(track.time)))
  1879. else:
  1880. track = self.playlist.start(self.active_user.nick, _youtube)
  1881. self.send_yut_play(track.id, track.time, track.title)
  1882. self.timer(track.time)
  1883.  
  1884. # == Tinychat API Command Methods. ==
  1885. def do_account_spy(self, account):
  1886. """
  1887. Shows info about a tinychat account.
  1888.  
  1889. :param account: tinychat account.
  1890. :type account: str
  1891. """
  1892. if self.is_client_mod:
  1893. if len(account) is 0:
  1894. self.send_chat_msg('Missing username to search for.')
  1895. else:
  1896. tc_usr = pinylib.apis.tinychat.user_info(account)
  1897. if tc_usr is None:
  1898. self.send_chat_msg('Could not find tinychat info for: %s' % account)
  1899. else:
  1900. self.send_chat_msg('ID: %s, \nLast Login: %s' %
  1901. (tc_usr['tinychat_id'], tc_usr['last_active']))
  1902.  
  1903. # == Other API Command Methods. ==
  1904. def do_search_urban_dictionary(self, search_str):
  1905. """
  1906. Shows urbandictionary definition of search string.
  1907.  
  1908. :param search_str: The search string to look up a definition for.
  1909. :type search_str: str
  1910. """
  1911. if self.is_client_mod:
  1912. if len(search_str) is 0:
  1913. self.send_chat_msg('Please specify something to look up.')
  1914. else:
  1915. urban = other.urbandictionary_search(search_str)
  1916. if urban is None:
  1917. self.send_chat_msg('Could not find a definition for: %s' % search_str)
  1918. else:
  1919. if len(urban) > 70:
  1920. chunks = pinylib.string_util.chunk_string(urban, 70)
  1921. for i in range(0, 2):
  1922. self.send_chat_msg(chunks[i])
  1923. else:
  1924. self.send_chat_msg(urban)
  1925.  
  1926. def do_weather_search(self, search_str):
  1927. """
  1928. Shows weather info for a given search string.
  1929.  
  1930. :param search_str: The search string to find weather data for.
  1931. :type search_str: str
  1932. """
  1933. if len(search_str) is 0:
  1934. self.send_chat_msg('Please specify a city to search for.')
  1935. else:
  1936. weather = other.weather_search(search_str)
  1937. if weather is None:
  1938. self.send_chat_msg('Could not find weather data for: %s' % search_str)
  1939. else:
  1940. self.send_chat_msg(weather)
  1941.  
  1942. def do_whois_ip(self, ip_str):
  1943. """
  1944. Shows whois info for a given ip address or domain.
  1945.  
  1946. :param ip_str: The ip address or domain to find info for.
  1947. :type ip_str: str
  1948. """
  1949. if len(ip_str) is 0:
  1950. self.send_chat_msg('Please provide an IP address or domain.')
  1951. else:
  1952. whois = other.whois(ip_str)
  1953. if whois is None:
  1954. self.send_chat_msg('No info found for: %s' % ip_str)
  1955. else:
  1956. self.send_chat_msg(whois)
  1957.  
  1958. # == Just For Fun Command Methods. ==
  1959. def do_chuck_noris(self):
  1960. """ Shows a chuck norris joke/quote. """
  1961. chuck = other.chuck_norris()
  1962. if chuck is not None:
  1963. self.send_chat_msg(chuck)
  1964.  
  1965. # == Just For Fun Command Methods. ==
  1966. def do_check(self):
  1967. self.send_chat_msg('Status: Online! - Bot-Uptime: ' + self.format_time(self.get_runtime()))
  1968.  
  1969. def do_commands(self):
  1970. self.send_chat_msg('Public commands are located @ https://pastebin.com/CyKfR27Z')
  1971.  
  1972. def do_mood(self):
  1973.  
  1974. self.send_chat_msg(locals_.get_mood())
  1975.  
  1976. def do_Movie(self, title):
  1977.  
  1978. self.send_chat_msg(locals_.getMovie(title))
  1979.  
  1980.  
  1981. def do_Hyde(self):
  1982.  
  1983. self.send_chat_msg(locals_.getHyde())
  1984.  
  1985.  
  1986.  
  1987. def do_8ball(self, question):
  1988. """
  1989. Shows magic eight ball answer to a yes/no question.
  1990.  
  1991. :param question: The yes/no question.
  1992. :type question: str
  1993. """
  1994. if len(question) is 0:
  1995. self.send_chat_msg('Question.')
  1996. else:
  1997. self.send_chat_msg('8Ball says: %s' % locals_.eight_ball())
  1998.  
  1999. def do_scope(self, month):
  2000. """
  2001. Shows magic eight ball answer to a yes/no question.
  2002.  
  2003. :param question: The yes/no question.
  2004. :type question: str
  2005. """
  2006. if len(month) is 0:
  2007. self.send_chat_msg('Sign required..')
  2008. else:
  2009. self.send_chat_msg('Scope says: %s' % locals_.getScope(month))
  2010.  
  2011. def do_number(self, number):
  2012. """
  2013. Shows magic eight ball answer to a yes/no question.
  2014.  
  2015. :param question: The yes/no question.
  2016. :type question: str
  2017. """
  2018. if len(number) is 0:
  2019. self.send_chat_msg('Number required..')
  2020. else:
  2021. self.send_chat_msg('Number says: %s' % locals_.getNumber(number))
  2022.  
  2023. def do_fact(self):
  2024.  
  2025.  
  2026. self.send_chat_msg('Fact is: %s' % locals_.get_Animal())
  2027.  
  2028. def do_joke(self):
  2029.  
  2030.  
  2031. self.send_chat_msg('Fact is: %s' % locals_.getJokes())
  2032.  
  2033. def do_line(self):
  2034.  
  2035. self.send_chat_msg(locals_.getOneliner())
  2036.  
  2037. def do_mom(self):
  2038.  
  2039.  
  2040. self.send_chat_msg('Api is down')
  2041.  
  2042. def do_Advice(self):
  2043.  
  2044.  
  2045. self.send_chat_msg('Advice is: %s' % locals_.advice())
  2046. #self.send_chat_msg('Disabled by x0r till further notice')
  2047.  
  2048. def do_Geek(self):
  2049.  
  2050.  
  2051. self.send_chat_msg(locals_.getGeek())
  2052. #self.send_chat_msg('Disabled by x0r till further notice')
  2053.  
  2054. def do_bitcoin(self):
  2055.  
  2056.  
  2057. self.send_chat_msg('Cryptowatch says: %s' % locals_.getbitcoin())
  2058.  
  2059. def do_eth(self):
  2060.  
  2061. self.send_chat_msg('Cryptowatch says: %s' % locals_.geteth())
  2062.  
  2063. def do_xmr(self):
  2064.  
  2065. self.send_chat_msg('Cryptowatch says: %s' % locals_.getxmr())
  2066.  
  2067. def do_ltc(self):
  2068.  
  2069. self.send_chat_msg('Cryptowatch says: %s' % locals_.getlitecoins())
  2070.  
  2071. def do_pot(self):
  2072.  
  2073. self.send_chat_msg('Cryptowatch says: %s' % locals_.getpot())
  2074.  
  2075. def do_sia(self):
  2076.  
  2077. self.send_chat_msg('Cryptowatch says: %s' % locals_.getsia())
  2078.  
  2079. def do_gank(self):
  2080.  
  2081. self.send_chat_msg('Gods gift to women and mankind.')
  2082.  
  2083. def do_jokes(self):
  2084.  
  2085. self.send_chat_msg('Joker says: %s' % locals_.get_joke())
  2086.  
  2087. def do_dice(self):
  2088. """ roll the dice. """
  2089. self.send_chat_msg('The dice rolled: %s' % locals_.roll_dice())
  2090.  
  2091. def do_flip_coin(self):
  2092. """ Flip a coin. """
  2093. self.send_chat_msg('The coin was: %s' % locals_.flip_coin())
  2094.  
  2095. def do_fortune(self):
  2096. """ Flip a coin. """
  2097. self.send_chat_msg('The fortune was: %s' % locals_.fortune())
  2098.  
  2099. def do_Trump(self):
  2100. """ Flip a coin. """
  2101. self.send_chat_msg('Trump says: %s' % locals_.getTrump())
  2102.  
  2103. def private_message_handler(self, private_msg):
  2104. """
  2105. Private message handler.
  2106.  
  2107. Overrides private_message_handler in pinylib
  2108. to enable private commands.
  2109.  
  2110. :param private_msg: The private message.
  2111. :type private_msg: str
  2112. """
  2113.  
  2114. prefix = pinylib.CONFIG.B_PREFIX
  2115. # Split the message in to parts.
  2116. pm_parts = private_msg.split(' ')
  2117. # parts[0] is the command..
  2118. pm_cmd = pm_parts[0].lower().strip()
  2119. # The rest is a command argument.
  2120. pm_arg = ' '.join(pm_parts[1:]).strip()
  2121.  
  2122. #Bots operating owner
  2123. if self.has_level(1):
  2124. if self.is_client_owner:
  2125. pass
  2126.  
  2127. #if pm_cmd == prefix + 'key':
  2128. # self.do_key(pm_arg)
  2129.  
  2130. elif pm_cmd == prefix + 'clrbn':
  2131. self.do_clear_bad_nicks()
  2132.  
  2133. elif pm_cmd == prefix + 'clrbs':
  2134. self.do_clear_bad_strings()
  2135.  
  2136. elif pm_cmd == prefix + 'clrban':
  2137. self.do_clear_bad_accounts()
  2138.  
  2139.  
  2140.  
  2141. # Public commands.
  2142. if self.has_level(5):
  2143. if pm_cmd == prefix + 'opme1':
  2144. self.do_opme(pm_arg)
  2145.  
  2146. # Print to console.
  2147. #msg = str(private_msg).replace(pinylib.CONFIG.B_KEY, '***KEY***'). \
  2148. # replace(pinylib.CONFIG.B_SUPER_KEY, '***SUPER KEY***')
  2149.  
  2150. #self.console_write(pinylib.COLOR['white'], 'Private message from %s: %s' % (self.active_user.nick, msg))
  2151.  
  2152. def do_key(self, new_key):
  2153. """
  2154. Shows or sets a new secret bot controller key.
  2155.  
  2156. :param new_key: The new secret key.
  2157. :type new_key: str
  2158. """
  2159. if len(new_key) == 0:
  2160. self.send_private_msg(self.active_user.id, 'The current secret key is: %s' % pinylib.CONFIG.B_KEY)
  2161. elif len(new_key) < 6:
  2162. self.send_private_msg(self.active_user.id, 'The key is to short, it must be atleast 6 characters long.'
  2163. 'It is %s long.' % len(new_key))
  2164. elif len(new_key) >= 6:
  2165. # reset current bot controllers.
  2166. for user in self.users.all:
  2167. if self.users.all[user].user_level is 2 or self.users.all[user].user_level is 4:
  2168. self.users.all[user].user_level = 5
  2169.  
  2170. pinylib.CONFIG.B_KEY = new_key
  2171. self.send_private_msg(self.active_user.id, 'The key was changed to: %s' % new_key)
  2172.  
  2173. def do_clear_bad_nicks(self):
  2174. """ Clear the nick bans file. """
  2175. pinylib.CONFIG.B_NICK_BANS[:] = []
  2176. pinylib.file_handler.delete_file_content(self.config_path, pinylib.CONFIG.B_NICK_BANS_FILE_NAME)
  2177.  
  2178. def do_clear_bad_strings(self):
  2179. """ Clear the string bans file. """
  2180. pinylib.CONFIG.B_STRING_BANS[:] = []
  2181. pinylib.file_handler.delete_file_content(self.config_path, pinylib.CONFIG.B_STRING_BANS_FILE_NAME)
  2182.  
  2183. def do_clear_bad_accounts(self):
  2184. """ Clear the account bans file. """
  2185. pinylib.CONFIG.B_ACCOUNT_BANS[:] = []
  2186. pinylib.file_handler.delete_file_content(self.config_path, pinylib.CONFIG.B_ACCOUNT_BANS_FILE_NAME)
  2187.  
  2188. def do_opme(self, key):
  2189. """
  2190. Make a user a bot controller if the correct key is provided.
  2191.  
  2192. :param key: The secret bot controller key.
  2193. :type key: str
  2194. """
  2195. if len(key) == 0:
  2196. self.send_private_msg(self.active_user.id, 'Missing key.')
  2197. elif key == pinylib.CONFIG.B_SUPER_KEY:
  2198. if self.is_client_owner:
  2199. self.active_user.user_level = 1
  2200. self.send_private_msg(self.active_user.id, 'You are now a super mod.')
  2201. else:
  2202. self.send_private_msg(self.active_user.id, 'The client is not using the owner account.')
  2203. elif key == pinylib.CONFIG.B_KEY:
  2204. if self.is_client_mod:
  2205. self.active_user.user_level = 2
  2206. self.send_private_msg(self.active_user.id, 'You are now a bot controller.')
  2207. else:
  2208. self.send_private_msg(self.active_user.id, 'The client is not moderator.')
  2209. else:
  2210. self.send_private_msg(self.active_user.id, 'Wrong key.')
  2211.  
  2212. # Timer Related.
  2213. def timer_event(self):
  2214. """ This gets called when the timer has reached the time. """
  2215. if len(self.playlist.track_list) > 0:
  2216. if self.playlist.is_last_track:
  2217. if self.is_connected:
  2218. self.send_chat_msg('Resetting playlist.')
  2219. self.playlist.clear()
  2220. else:
  2221. track = self.playlist.next_track
  2222. if track is not None and self.is_connected:
  2223. self.send_yut_play(track.id, track.time, track.title)
  2224. self.timer(track.time)
  2225.  
  2226. def timer(self, event_time):
  2227. """
  2228. Track event timer.
  2229.  
  2230. This will cause an event to occur once the time is done.
  2231.  
  2232. :param event_time: The time in seconds for when an event should occur.
  2233. :type event_time: int | float
  2234. """
  2235. self.timer_thread = threading.Timer(event_time, self.timer_event)
  2236. self.timer_thread.start()
  2237.  
  2238. def cancel_timer(self):
  2239. """ Cancel the track timer. """
  2240. if self.timer_thread is not None:
  2241. if self.timer_thread.is_alive():
  2242. self.timer_thread.cancel()
  2243. self.timer_thread = None
  2244. return True
  2245. return False
  2246. return False
  2247.  
  2248. # Helper Methods.
  2249. def options(self):
  2250. """ Load/set special options. """
  2251. log.info('options: is_client_owner: %s, is_client_mod: %s' % (self.is_client_owner, self.is_client_mod))
  2252. if self.is_client_owner:
  2253. self.get_privacy_settings()
  2254. if self.is_client_mod:
  2255. self.send_banlist_msg()
  2256. self.load_list(nicks=True, accounts=True, strings=True, links=True)
  2257.  
  2258. def get_privacy_settings(self):
  2259. """ Parse the privacy settings page. """
  2260. log.info('Parsing %s\'s privacy page.' % self.account)
  2261. self.privacy_ = privacy.Privacy(proxy=None)
  2262. self.privacy_.parse_privacy_settings()
  2263.  
  2264. def load_list(self, nicks=False, accounts=False, strings=False, links=False):
  2265. """
  2266. Loads different list to memory.
  2267.  
  2268. :param nicks: bool, True load nick bans file.
  2269. :param accounts: bool, True load account bans file.
  2270. :param strings: bool, True load ban strings file.
  2271. """
  2272. if nicks:
  2273. pinylib.CONFIG.B_NICK_BANS = pinylib.file_handler.file_reader(self.config_path,
  2274. pinylib.CONFIG.B_NICK_BANS_FILE_NAME)
  2275. if accounts:
  2276. pinylib.CONFIG.B_ACCOUNT_BANS = pinylib.file_handler.file_reader(self.config_path,
  2277. pinylib.CONFIG.B_ACCOUNT_BANS_FILE_NAME)
  2278. if strings:
  2279. pinylib.CONFIG.B_STRING_BANS = pinylib.file_handler.file_reader(self.config_path,
  2280. pinylib.CONFIG.B_STRING_BANS_FILE_NAME)
  2281. if links:
  2282. pinylib.CONFIG.B_STRING_BANS = pinylib.file_handler.file_reader(self.config_path,
  2283. pinylib.CONFIG.B_Youtube_Play_List)
  2284. #pinylib.CONFIG.B_Youtube_Play_List
  2285. def has_level(self, level):
  2286. """
  2287. Checks the active user for correct user level.
  2288.  
  2289. :param level: The level to check the active user against.
  2290. :type level: int
  2291. :return: True if the user has correct level, else False
  2292. :rtype: bool
  2293. """
  2294. if self.active_user.user_level == 6:
  2295. return False
  2296. elif self.active_user.user_level <= level:
  2297. return True
  2298. return False
  2299.  
  2300. @staticmethod
  2301. def format_time(time_stamp, is_milli=False):
  2302. """
  2303. Converts a time stamp as seconds or milliseconds to (day(s)) hours minutes seconds.
  2304.  
  2305. :param time_stamp: Seconds or milliseconds to convert.
  2306. :param is_milli: The time stamp to format is in milliseconds.
  2307. :return: A string in the format (days) hh:mm:ss
  2308. :rtype: str
  2309. """
  2310. if is_milli:
  2311. m, s = divmod(time_stamp / 1000, 60)
  2312. else:
  2313. m, s = divmod(time_stamp, 60)
  2314. h, m = divmod(m, 60)
  2315. d, h = divmod(h, 24)
  2316.  
  2317. if d == 0 and h == 0:
  2318. human_time = '%02d:%02d' % (m, s)
  2319. elif d == 0:
  2320. human_time = '%d:%02d:%02d' % (h, m, s)
  2321. else:
  2322. human_time = '%d Day(s) %d:%02d:%02d' % (d, h, m, s)
  2323. return human_time
  2324.  
  2325. def check_msg(self, msg):
  2326. """
  2327. Checks the chat message for ban string.
  2328.  
  2329. :param msg: The chat message.
  2330. :type msg: str
  2331. """
  2332. should_be_banned = False
  2333. chat_words = msg.split(' ')
  2334. for bad in pinylib.CONFIG.B_STRING_BANS:
  2335. if bad.startswith('*'):
  2336. _ = bad.replace('*', '')
  2337. if _ in msg:
  2338. should_be_banned = True
  2339. elif bad in chat_words:
  2340. should_be_banned = True
  2341. if should_be_banned:
  2342. if pinylib.CONFIG.B_USE_KICK_AS_AUTOBAN:
  2343. self.send_kick_msg(self.active_user.id)
  2344. else:
  2345. self.send_ban_msg(self.active_user.id)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement