SHARE
TWEET

Untitled

a guest Jul 21st, 2017 137 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2. # 0x539
  3. # covfefe.py bot v1 (python3)
  4.  
  5. import os
  6. import random
  7. import socket
  8. import ssl
  9. import time
  10. import threading
  11.  
  12. # Connection
  13. server   = 'irc.binrev.net'
  14. port     = 6697
  15. use_ipv6 = False
  16. use_ssl  = True
  17. vhost    = None
  18. password = None
  19. channel  = '#soldierx'
  20. key      = None
  21.  
  22. # Identity
  23. nickname = 'covfefe'
  24. username = 'covfefe'
  25. realname = 'covfefe'
  26.  
  27. # Globals (DO NOT EDIT)
  28. random_file  = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'random.txt')
  29.  
  30. # Formatting Control Characters / Color Codes
  31. bold        = '\x02'
  32. italic      = '\x1D'
  33. underline   = '\x1F'
  34. reverse     = '\x16'
  35. reset       = '\x0f'
  36. white       = '00'
  37. black       = '01'
  38. blue        = '02'
  39. green       = '03'
  40. red         = '04'
  41. brown       = '05'
  42. purple      = '06'
  43. orange      = '07'
  44. yellow      = '08'
  45. light_green = '09'
  46. cyan        = '10'
  47. light_cyan  = '11'
  48. light_blue  = '12'
  49. pink        = '13'
  50. grey        = '14'
  51. light_grey  = '15'
  52.  
  53. def debug(msg):
  54.     print(f'{get_time()} | [~] - {msg}')
  55. def error(msg, reason=None):
  56.     if reason:
  57.         print(f'{get_time()} | [!] - {msg} ({reason})')
  58.     else:
  59.         print(f'{get_time()} | [!] - {msg}')
  60.  
  61. def get_time():
  62.     return time.strftime('%I:%M:%S')
  63.  
  64. class IRC(object):
  65.     server      = server
  66.     port        = port
  67.     use_ipv6    = use_ipv6
  68.     use_ssl     = use_ssl
  69.     vhost       = vhost
  70.     password    = password
  71.     channel     = channel
  72.     key         = key
  73.     username    = username
  74.     realname    = realname
  75.  
  76.     def __init__(self):
  77.         self.nickname  = nickname
  78.         self.connected = False
  79.         self.last_time = 0
  80.         self.sock      = None
  81.  
  82.     def action(self, chan, msg):
  83.         self.sendmsg(chan, f'\x01ACTION {msg}\x01')
  84.  
  85.     def color(self, msg, foreground, background=None):
  86.         if background:
  87.             return f'\x03{foreground},{background}{msg}{reset}'
  88.         else:
  89.             return f'\x03{foreground}{msg}{reset}'
  90.  
  91.     def connect(self):
  92.         try:
  93.             self.create_socket()
  94.             self.sock.connect((self.server, self.port))
  95.             if self.password:
  96.                 self.raw('PASS ' + self.password)
  97.             self.raw(f'USER {self.username} 0 * :{self.realname}')
  98.             self.nick(self.nickname)
  99.         except socket.error as ex:
  100.             error('Failed to connect to IRC server.', ex)
  101.             self.event_disconnect()
  102.         else:
  103.             self.listen()
  104.  
  105.     def create_socket(self):
  106.         if self.use_ipv6:
  107.             self.sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
  108.         else:
  109.             self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  110.  
  111.         if self.vhost:
  112.             self.sock.bind((self.vhost, 0))
  113.         if self.use_ssl:
  114.             self.sock = ssl.wrap_socket(self.sock)
  115.  
  116.     def event_connect(self):
  117.         self.connected = True
  118.         self.join(self.channel, self.key)
  119.         threading.Thread(target=self.loop).start()
  120.  
  121.     def event_disconnect(self):
  122.         self.connected = False
  123.         self.sock.close()
  124.         time.sleep(10)
  125.         self.connect()
  126.  
  127.     def event_join(self, nick, chan):
  128.         if nick.lower() == 'valhalla':
  129.             self.sendmsg(chan, nick)
  130.         self.notice(nick, 'You have 324 memos waiting. Please type * /server MemoServ read * to check your messages.')
  131.  
  132.     def event_kick(self, nick, chan, kicked):
  133.         if kicked == self.nickname and chan == self.channel:
  134.             time.sleep(3)
  135.             self.join(self.channel, self.key)
  136.  
  137.     def event_message(self, nick, chan, msg):
  138.         if random.choice((True,False,False,False)):
  139.             if 'http://' in msg or 'https://' in msg or 'www.' in msg:
  140.                 self.sendmsg(chan, underline + 'STUXNET DETECTED not clicking')
  141.             elif msg == 'insecure':
  142.                 self.sendmsg(chan, 'gangster 4 lyf')
  143.             elif 'tibiania' in msg:
  144.                 self.sendmsg(chan, 'is tibiania the nigger lover?')
  145.             elif 'conf' in msg:
  146.                 self.sendmsg(chan, 'PEDO CONF ALERT PEDO CONF ALERT PEDO CONF ALERT PEDO CONF ALERT')
  147.             elif 'ramsaso' in msg:
  148.                 self.sendmsg(chan, 'go watch your hentai porn')
  149.             elif 'tr0n' in msg:
  150.                 self.sendmsg(chan, 'tron? you mean SODOM HUSSEIN?')
  151.             elif msg == 'gangster':
  152.                 self.sendmsg(chan, 'MLT')
  153.             elif msg == 'gangster4lyf':
  154.                 self.sendmsg(chan, 'gangster4lyf')
  155.             elif 'fag' in msg:
  156.                 self.sendmsg(chan, 'you have smoked more sausage than hickory farms')
  157.             elif 'faggot' in msg:
  158.                 self.sendmsg(chan, 'i hate fags more than i hate war in this world')
  159.             elif 'lucky225' in msg:
  160.                 self.sendmsg(chan, 'fuck that media whore lucky noob noob five')
  161.             elif 'johnny' in msg:
  162.                 self.sendmsg(chan, 'YOU GOT THE JOHNNY HACKER LASER LIGHT SHOW')
  163.             elif 'swat' in msg:
  164.                 self.sendmsg(chan, 'the wicked wizard is UNSTOPPABLE')
  165.             elif 'crunch' in msg:
  166.                 self.sendmsg(chan, 'capn crunch is a known child molester. you looking for a massage')
  167.             elif 'draper' in msg:
  168.                 self.sendmsg(chan, 'i used to workout with the crunchman')
  169.             elif 'jeffk' in msg:
  170.                 self.sendmsg(chan, 'u faget clownboat i haxur unrale nginx kearnels')
  171.             elif 'phreakshow' in msg:
  172.                 self.sendmsg(chan, 'CONVICTED CHILD MOLESTER PEDOPHILE ALERT')
  173.             elif 'fag' in msg:
  174.                 self.sendmsg(chan, 'you have smoked more sausage than hickory farms')
  175.             elif '2600' in msg:
  176.                 self.sendmsg(chan, 'i love spending quiet time with Emmanuel from 2600')
  177.             elif 'sup' in msg:
  178.                 self.sendmsg(chan, '9 inches of limpdick')
  179.             elif 'fag' in msg:
  180.                 self.sendmsg(chan, 'you have smoked more sausage than hickory farms')
  181.             elif self.nickname in msg:
  182.                 self.action(chan, '8=================================================================D')
  183.             elif msg.lower() == 'lol':
  184.                 self.sendmsg(chan, 'kek')
  185.             elif msg == '%%':
  186.                 self.sendmsg(chan, '%%')
  187.             elif 'trump' in msg.lower():
  188.                 self.sendmsg(chan, self.color('MAKE AMERICA GREAT AGAIN', light_blue))
  189.             elif 'hacker' in msg.lower():
  190.                 if random.choice((True,False)):
  191.                     self.sendmsg(chan, 'tron has been hacking since you were in diapers')
  192.                 else:
  193.                     self.sendmsg(chan, 'go hack a meatphone or something')
  194.  
  195.     def event_nick_in_use(self):
  196.         self.nickname = self.nickname + '_'
  197.         self.nick(self.nickname)
  198.  
  199.     def event_part(self, nick, chan):
  200.         self.sendmsg(nick, 'bet dont wont come back pussy')
  201.         self.sendmsg(chan, self.color('TRIGGERED PART DETECTED', red, yellow))
  202.  
  203.     def event_quit(self, nick):
  204.         if time.time() - self.last_time > 15:
  205.             self.nick(nick)
  206.             self.nickname = nick
  207.             self.sendmsg(self.channel, 'GOT EM')
  208.             self.last_time = time.time()
  209.  
  210.     def handle_events(self, data):
  211.         args = data.split()
  212.         if args[0] == 'PING':
  213.             self.raw('PONG ' + args[1][1:])
  214.         elif args[1] == '001':
  215.             self.event_connect()
  216.         elif args[1] == '433':
  217.             self.event_nick_in_use()
  218.         elif args[1] in ('JOIN','KICK','PART','PRIVMSG','QUIT'):
  219.             nick  = args[0].split('!')[0][1:]
  220.             if nick != self.nickname:
  221.                 if args[1] == 'JOIN':
  222.                     chan = args[2][1:]
  223.                     self.event_join(nick, chan)
  224.                 elif args[1] == 'KICK':
  225.                     chan   = args[2]
  226.                     kicked = args[3]
  227.                     self.event_kick(nick, chan, kicked)
  228.                 elif args[1] == 'PART':
  229.                     chan = args[2]
  230.                     self.event_part(nick, chan)
  231.                 elif args[1] == 'PRIVMSG':
  232.                     chan = args[2]
  233.                     msg  = data.split(f'{args[0]} PRIVMSG {chan} :')[1]
  234.                     if chan != self.nickname:
  235.                         self.event_message(nick, chan, msg)
  236.                 elif args[1] == 'QUIT':
  237.                     self.event_quit(nick)
  238.  
  239.     def join(self, chan, key=None):
  240.         if key:
  241.             self.raw(f'JOIN {chan} {key}')
  242.         else:
  243.             self.raw('JOIN ' + chan)
  244.  
  245.     def listen(self):
  246.         while True:
  247.             try:
  248.                 data = self.sock.recv(1024).decode('utf-8')
  249.                 if data:
  250.                     for line in (line for line in data.split('\r\n') if line):
  251.                         debug(line)
  252.                         if len(line.split()) >= 2:
  253.                             if line.startswith('ERROR :Closing Link:'):
  254.                                 raise Exception('Connection has closed.')
  255.                             else
  256.                                 self.handle_events(line)
  257.                 else:
  258.                     error('No data recieved from server.')
  259.                     break
  260.             except (UnicodeDecodeError,UnicodeEncodeError):
  261.                 pass
  262.             except Exception as ex:
  263.                 error('Unexpected error occured.', ex)
  264.                 break
  265.         self.event_disconnect()
  266.  
  267.     def loop(self):
  268.         while self.connected:
  269.             try:
  270.                 time.sleep(60 * random_int(20,60))
  271.                 self.sendmsg(self.channel, random.choice(random_lines))
  272.             except Exception as ex:
  273.                 error('Error occured in the loop!', ex)
  274.                 break
  275.  
  276.     def nick(self, nick):
  277.         self.raw('NICK ' + nick)
  278.  
  279.     def notice(self, target, msg):
  280.         self.raw(f'NOTICE {target} :{msg}')
  281.  
  282.     def part(self, chan, msg=None):
  283.         if msg:
  284.             self.raw(f'PART {chan} {msg}')
  285.         else:
  286.             self.raw('PART ' + chan)
  287.  
  288.     def raw(self, msg):
  289.         self.sock.send(bytes(msg + '\r\n', 'utf-8'))
  290.  
  291.     def sendmsg(self, target, msg):
  292.         self.raw(f'PRIVMSG {target} :{msg}')
  293.  
  294. # Main
  295. if os.path.isfile(random_file):
  296.     random_lines = [line.rstrip() for line in open(random_file, mode='r', encoding='utf8', errors='replace').readlines() if line]
  297. else:
  298.     error_exit('Missing random file!')
  299. IRC().connect()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top