Advertisement
Guest User

Gross Tsbot

a guest
Jun 7th, 2018
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 13.05 KB | None | 0 0
  1. import telnetlib
  2. import socket
  3. from datetime import datetime
  4. from datetime import timedelta
  5. from socket import error as socket_error
  6. import os
  7. import time as tm
  8. import _thread
  9. import subprocess
  10. from random import randint
  11. from scapy.all import *
  12.  
  13. # Login creds
  14. HOST = "localhost"
  15. user = "serveradmin"
  16. password = "HIDING"
  17. apikey="HIDING"
  18.    
  19. # misc
  20. banmsg = "automated"
  21. user_to_ban = "Juicetin" #Default User
  22. temp_current_banner = "https://i.imgur.com/37Ju1fC.png"
  23. yt_thread_active = 0
  24. wheel_used = {'':datetime.now()}
  25.  
  26. tn = telnetlib.Telnet(HOST, 10011)
  27. tnclient = telnetlib.Telnet("localhost", 25639)
  28.  
  29. ## main method ##
  30. def main():
  31.     # Initial telnet config for server and client
  32.     tn = telnetlib.Telnet(HOST, 10011)
  33.     tnclient = telnetlib.Telnet("localhost", 25639)
  34.    
  35.     # Login to serverquery
  36.     login_string = "login %s %s\n" % (user, password)
  37.     tn.write(bytes(login_string, encoding="ascii"))
  38.     tn.read_until(b"msg=ok",2)
  39.        
  40.     # Server handler initialization
  41.     tn.write(b"use 1\n")
  42.     tn.read_until(b"msg=ok",2)
  43.    
  44.     # Clientquery apikey authorization
  45.     clientauth = "auth apikey=%s\n" % (apikey)
  46.     tnclient.write(bytes(clientauth, encoding="ascii"))
  47.     tnclient.read_until(b"msg=ok",2)
  48.  
  49.     # client notify for pokes
  50.     tnclient.write(b"clientnotifyregister schandlerid=0 event=notifyclientpoke\n")
  51.     tnclient.read_until(b"msg=ok",2)
  52.  
  53.     # Find bot clid
  54.     tn.write(b"clientfind pattern=juicero\n")
  55.     tn.read_until(b"=",2)
  56.     juicero = tn.read_until(b" ",2)
  57.     juicero = juicero.decode("utf-8").strip(" ")
  58.  
  59.     # Move bot to juice box (cid=6)
  60.     movecmd="clientmove cid=6 clid=%s\n" % (juicero)
  61.     tnclient.write(bytes(movecmd,encoding="ascii"))
  62.    
  63.     connect()
  64.  
  65.     # Runs a help command every minute to ensure telnet connection stays alive
  66.     #_thread.start_new_thread(keep_alive, (60, ) )        
  67.    
  68.     # Create empty youtube link queue
  69.     yt_link_queue = []
  70.     global yt_thread_active
  71.     yt_thread_active = 0
  72.  
  73.     global wheel_used
  74.     del wheel_used['']
  75.  
  76.     while 1:
  77.         #sniff(prn=arp_display, filter="arp",store=0,count=0)
  78.  
  79.         # Remove empty strings from queue
  80.         if '' in yt_link_queue:
  81.             for i in range(len(yt_link_queue) - 1, -1, -1):
  82.                 if yt_link_queue[i] == '':
  83.                     del yt_link_queue[i]
  84.            
  85.  
  86.         try:
  87.             if tnclient.read_until(b"notifyclientpoke",2) == b"notifyclientpoke"  or (yt_link_queue and yt_thread_active == 0):
  88.                 print("Got poked!\n")
  89.                 tnclient.read_until(b"invokername=",2)
  90.                 msg_from = tnclient.read_until(b" ",2)
  91.                 print(msg_from)
  92.                 tnclient.read_until(b"msg=",2)
  93.                 message = tnclient.read_until(b"\n",2)
  94.                 print(message)
  95.  
  96.                 print(yt_thread_active)
  97.                 print(yt_link_queue)
  98.                 # Strip the message of the newline and the \s given in the original format
  99.                 message = message.decode("utf-8").strip("\\s").strip("\n")
  100.                 msg_from = msg_from.decode("utf-8").strip("\\s").strip("\n")
  101.                 msg_from = msg_from[:-1]
  102.                 print(message)
  103.                 print(msg_from)
  104.                 msg_from_cmd = "clientfind pattern=%s\n" % (msg_from)
  105.                 tn.write(bytes(msg_from_cmd, encoding="ascii"))
  106.                 tn.read_until(b"=",2)
  107.                 msg_from_clid = tn.read_until(b" ", 2).decode("utf-8").strip(" ")
  108.                 tn.read_until(b"msg=ok",2)
  109.                
  110.                 """"""" # # # # Poke Message Management # # # # """""""
  111.                 if message[:6] == "!wheel":
  112.                     print("GOT WHEELED")
  113.                     time = datetime.now()
  114.                     print(time)
  115.                     """(time - wheel_used[msg_from]).total_seconds() >= 3600 or"""
  116.                     if True:
  117.                         user_to_ban = message[8:]
  118.                         print("Commencing wheel")
  119.                         wheel(user_to_ban)
  120.                     else:
  121.                         print("NOT COMMENCING WHEEL")
  122.                         pokecmd = "clientpoke clid=%d msg=%s" % (msg_from_clid, str(time-wheel_used[msg_from]))
  123.                         print(pokecmd)
  124.                         tnclient.write(bytes(pokecmd, encoding="ascii"))
  125.                         tnclient.read_until("msg=ok",2)
  126.                     wheel_used[msg_from] = time
  127.                 elif message[:3] == "!yt" or (yt_link_queue and yt_thread_active == 0):
  128.                     yt_link = message[5:]
  129.                     yt_link_queue.append(yt_link)
  130.                     print(yt_link_queue)
  131.                     if yt_thread_active == 0 and yt_link_queue:
  132.                         yt_thread_active = 1
  133.                         _thread.start_new_thread(ytaudio, (yt_link_queue[0], msg_from, ) )
  134.                         print("Finished audio and playing next in queue")
  135.                         yt_link_queue.pop(0)
  136.         except KeyboardInterrupt:
  137.             print("Quitting...")
  138.             exit()
  139.         except socket_error as serr:
  140.            #os.system("/home/jscd/ts_startscript.sh")
  141.            exit()
  142.         except EOFError:
  143.             print("EOF Error")
  144.             os.system("python3 /home/jscd/ban_user.py")
  145.             exit()    
  146.         except Exception as e:
  147.             try:
  148.                 print(e)
  149.                 #print("Disconneced...\nReconnecting...\n")
  150.                 connect()
  151.                 #print("Reconnected!\n")
  152.             except Exception as e2:
  153.                 print(e2)
  154.                 print("Dead...")
  155.                 exit()
  156.  
  157. def keep_alive(time):
  158.     i = 0
  159.     while 1:
  160.         print("Is alive")
  161.         tm.sleep(time)            
  162.         tn.write(b"help\n")
  163.         tn.read_until(b"msg=ok",2)
  164.         tnclient.write(b"help\n")
  165.         tnclient.read_until(b"msg=ok",2)
  166.         i = i + 1
  167.  
  168. def arp_display(pkt):
  169.     if pkt[ARP].op == 1:
  170.         if pkt[ARP].hwsrc == 'b4:7c:9c:44:9f:e9': #Your button MAC - parcel
  171.             print("POOF")
  172.  
  173. ## play audio from youtube link ##
  174. def ytaudio(yt_link, msg_from):
  175.     global yt_thread_active
  176.     print("Playing %s..." % (yt_link))
  177.    
  178.     # Find bot clid
  179.     tn.write(b"clientfind pattern=juicero\n")
  180.     tn.read_until(b"clid=",2)
  181.     juicero = tn.read_until(b" ",2)
  182.     juicero = juicero.decode("utf-8").strip(" ")
  183.    
  184.     #msg_from = msg_from.decode("utf-8").strip(" ")
  185.  
  186.     # Get current channel to return to
  187.     tnclient.write(b"clientlist\n")
  188.     original_channel_id = -100
  189.     other_channel_id = -100
  190.     while original_channel_id == -100 or other_channel_id == -100:
  191.         tnclient.read_until(b"cid=",2)
  192.         channel_id = tnclient.read_until(b" ",2).decode("utf-8").strip(" ")
  193.         tnclient.read_until(b"client_nickname=",2)
  194.         nick = tnclient.read_until(b" ",2).decode("utf-8").strip(" ")
  195.         if nick == "juicero":
  196.             original_channel_id = channel_id
  197.         elif nick == msg_from:
  198.             other_channel_id = channel_id
  199.     tnclient.read_until(b"msg=ok",2)
  200.  
  201.     # Download youtube audio
  202.     os.system("youtube-dl --extract-audio -o audio.wav --audio-format wav %s" % (yt_link))
  203.  
  204.     # Move client to 'Slay the Gay Away' Channel    
  205.     movecmd = "clientmove cid=%s clid=%s\n" % (other_channel_id,juicero)
  206.     print(movecmd)
  207.     tnclient.write(bytes(movecmd,encoding="ascii"))
  208.    
  209.     # Play audio
  210.     os.system("vlc-wrapper -I dbus --play-and-exit audio.wav")
  211.     print("Finished playing audio")
  212.  
  213.     # Remove audio file    
  214.     os.system("rm audio.wav")
  215.  
  216.     # Move client back
  217.     movecmd = "clientmove cid=%s clid=%s\n" % (original_channel_id, juicero)
  218.     tnclient.write(bytes(movecmd,encoding="ascii"))
  219.     yt_thread_active = 0
  220.  
  221.  
  222.  
  223. ## connect to telnet for server/client query ##!yt
  224. def connect():  
  225.     #tnclient.read_until(b"=1", 2)
  226.    
  227.     login_string = "login %s %s\n" % (user, password)
  228.     tn.write(bytes(login_string, encoding="ascii"))
  229.     tn.read_until(b"msg=ok",2)
  230.        
  231.     tn.write(b"use 1\n")
  232.     tn.read_until(b"msg=ok",2)
  233.     clientauth = "auth apikey=%s\n" % (apikey)
  234.     tnclient.write(bytes(clientauth, encoding="ascii"))
  235.     tnclient.read_until(b"msg=ok",2)
  236.  
  237.     tnclient.write(b"clientnotifyregister schandlerid=0 event=notifyclientpoke\n")
  238.     tnclient.read_until(b"msg=ok",2)
  239.  
  240. ## get random time for use with wheel ##
  241. def get_time():
  242.     #   Possible options:
  243.     #   1 hour      - 3%    http://i.imgur.com/5v8w5Tl.gif
  244.     #   15 minutes  - 3%    http://i.imgur.com/QLJxDah.gif
  245.     #   10 minutes  - 5%    http://i.imgur.com/HtZP64g.gif
  246.     #   5 minutes   - 10%   http://i.imgur.com/eki5Y1i.gif
  247.     #   2 minutes   - 30%   http://i.imgur.com/EqkXFnX.gif
  248.     #   45 seconds  - 30%   http://i.imgur.com/TQG01JR.gif
  249.     #   30 seconds  - 10%   http://i.imgur.com/4gfjLGA.gif
  250.     #   15 seconds  - 5%    http://i.imgur.com/JxZWgtN.gif
  251.     #   5 seconds   - 3%    http://i.imgur.com/ll4i5fb.gif
  252.     #   1 second    - 1%    http://i.imgur.com/Uu875et.gif
  253.     #
  254.     #   Here is the fucking bell curve: http://imgur.com/ZZouAlR
  255.                    
  256.     n = randint(1,100)
  257.  
  258.     if n <= 3:          # hour
  259.         time = 3600
  260.     elif n <= 6:        # 15 mins
  261.         time = 900
  262.     elif n <= 11:       # etc...
  263.         time = 600
  264.     elif n <= 21:
  265.         time = 300
  266.     elif n <= 51:
  267.         time = 120
  268.     elif n <= 81:
  269.         time = 45
  270.     elif n <= 91:
  271.         time = 30
  272.     elif n <= 96:
  273.         time = 15
  274.     elif n <= 99:
  275.         time = 5
  276.     elif n <= 100:
  277.         time = 1
  278.     return time
  279.  
  280. ## get link for wheel method ##
  281. def get_link(time):
  282.     if time == 3600:          # hour
  283.         link = "http://i.imgur.com/5v8w5Tl.gif"
  284.     elif time == 900:        # 15 mins
  285.         link = "http://i.imgur.com/QLJxDah.gif"
  286.     elif time == 600:       # etc...
  287.         link = "http://i.imgur.com/HtZP64g.gif"
  288.     elif time == 300:
  289.         link = "http://i.imgur.com/eki5Y1i.gif"
  290.     elif time == 120:
  291.         link = "http://i.imgur.com/EqkXFnX.gif"
  292.     elif time == 45:
  293.         link = "http://i.imgur.com/TQG01JR.gif"
  294.     elif time == 30:
  295.         link = "http://i.imgur.com/4gfjLGA.gif"
  296.     elif time == 15:
  297.         link = "http://i.imgur.com/JxZWgtN.gif"
  298.     elif time == 5:
  299.         link = "http://i.imgur.com/ll4i5fb.gif"
  300.     elif time == 1:
  301.         link = "http://i.imgur.com/Uu875et.gif"
  302.     return link
  303.  
  304. ##  wheel of ban method ##
  305. def wheel(user_to_ban):
  306.     print("Wheeling")
  307.     # Get ban time and link to banner gif
  308.     time = get_time()
  309.     link = get_link(time)
  310.  
  311.     # Change banner to wheel gif (link)
  312.     change_pic = "serveredit virtualserver_hostbanner_gfx_url=%s\n" % (link)
  313.     tn.write(bytes(change_pic, encoding="ascii"))
  314.     tn.read_until(b"msg=ok",2)
  315.    
  316.     # Find the clid of user to ban
  317.     client_find = "clientfind pattern=%s\n" % (user_to_ban)
  318.     print(client_find)
  319.     tn.write(bytes(client_find, encoding="ascii"))
  320.     print(tn.read_until(b"clid=",2))
  321.     client = tn.read_until(b" ",2)
  322.     client = client.decode("utf-8").strip(" ")
  323.     print(client)
  324.     print(tn.read_until(b"msg=ok",2))
  325.    
  326.     # Find clid of juicero... again
  327.     tn.write(b"clientfind pattern=juicero\n")
  328.     tn.read_until(b"=",2)
  329.     juicero = tn.read_until(b" ",2)
  330.     juicero = juicero.decode("utf-8").strip(" ")
  331.     print("%s: %s  juicero: %s\n" % (user_to_ban, client, juicero))
  332.                    
  333.     # Find the channels of juicero and user to ban
  334.     tnclient.write(b"clientlist\n")
  335.     original_channel_id = -100
  336.     banned_channel_id = -100
  337.     while original_channel_id == -100 or banned_channel_id == -100:
  338.         tnclient.read_until(b"cid=",2)
  339.         channel_id = tnclient.read_until(b" ",2).decode("utf-8").strip(" ")
  340.         tnclient.read_until(b"client_nickname=",2)
  341.         nick = tnclient.read_until(b" ",2).decode("utf-8").strip(" ")
  342.         if nick == "juicero":
  343.             original_channel_id = channel_id
  344.             print("%s   %s\n" % (nick,channel_id))
  345.         elif nick == user_to_ban:
  346.             print("%s   %s\n" % (nick, channel_id))
  347.             banned_channel_id = channel_id
  348.     print("banned:%s original:%s\n" %  (banned_channel_id, original_channel_id))
  349.     tnclient.read_until(b"msg=ok",2)
  350.     movecmd = "clientmove cid=%s clid=%s\n" % (banned_channel_id, juicero)
  351.     print(movecmd)
  352.     tnclient.write(bytes(movecmd,encoding="ascii"))
  353.  
  354.     # Play audio
  355.     os.system("vlc-wrapper -I dbus --play-and-exit /home/jscd/wheel_fx/winner.wav")
  356.  
  357.     # Ban user
  358.     ban_cmd = "banclient clid=%s time=%s banreason=%s\n" % (client, time, banmsg)
  359.     print(ban_cmd)
  360.     tn.read_until(b"msg=ok",2)
  361.     tn.write(bytes(ban_cmd, encoding="ascii"))
  362.  
  363.     # Change banner back
  364.     tm.sleep(2)
  365.     change_pic = "serveredit virtualserver_hostbanner_gfx_url=%s\n" % (temp_current_banner)
  366.     tn.write(bytes(change_pic, encoding="ascii"))
  367.     tn.read_until(b"msg=ok",2)
  368.  
  369.     # Move juicero back to original channel
  370.     movecmd = "clientmove cid=%s clid=%s\n" % (original_channel_id, juicero)
  371.     tnclient.write(bytes(movecmd,encoding="ascii"))
  372.  
  373.  
  374. if __name__=='__main__':
  375.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement