daily pastebin goal
32%
SHARE
TWEET

Untitled

a guest Dec 7th, 2017 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import socket
  2. from Tkinter import *
  3.  
  4. network = 'irc.iz-smart.net'
  5. port = 6667
  6. channel = '#espadon1'
  7.  
  8. irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  9. irc.connect((network,port))
  10. irc.settimeout(0.1)
  11. irc.send('NICK Blume\r\n')
  12. irc.send('USER Blume Blume Blume : Baconmans Client\r\n')
  13. irc.send('JOIN ' + channel + '\r\n')
  14. irc.send('PRIVMSG ' + channel + 'Hi\r\n')
  15. irc.send('WHO ' + channel + '\r\n')
  16.  
  17.  
  18. def PONG(income):
  19.     income = income.split(':')
  20.     if income[0] == 'PING ':
  21.         irc.send('PONG ' + income[1])
  22.         print 'Blume >> PONG ' + income[1]
  23.  
  24. def NICK(income):
  25.     income = income.split()
  26.     if income[1] == 'PRIVMSG':
  27.         income = income[0].split('!')
  28.         income = income[0].split(':')
  29.         return income[1]
  30.  
  31. def CLOSE(income):
  32.     if NICK(income) == 'Baconman':
  33.         income = income.split(':')
  34.         if len(income) >= 2:
  35.             print income[2]
  36.             if income[2] == 'off\r\n':
  37.                 irc.send('QUIT\r\n')
  38.  
  39. def COMMAND(income):
  40.     income = income.split()
  41.     if len(income) >= 2:
  42.         if income[1] == 'PRIVMSG':
  43.             return 'PRIVMSG'
  44.         if income[1] == 'JOIN':
  45.             return 'JOIN'
  46.         if income[1] == 'PART':
  47.             return 'PART'
  48.  
  49. def MESSAGE(income):
  50.     income = income.split(':', 2)
  51.     return income[2]
  52.  
  53. def SEND(event):
  54.     msg = INPUT.get('1.0', END)
  55.     INPUT.delete(1.0, END)
  56.     irc.send('PRIVMSG ' + channel + ' ' + msg)
  57.  
  58. text = ''
  59. root = Tk()
  60. IN = Text(root)
  61. IN.config(state = DISABLED)
  62. IN.pack()
  63. INPUT = Text(root)
  64. INPUT.bind('<Return>', SEND)
  65. INPUT.pack()
  66. Nicklist = Listbox(root)
  67. Nicklist.pack()
  68. while True:
  69.     root.update()
  70.     try:
  71.         text = text + irc.recv(4096)
  72.     except socket.error:
  73.         text = ''
  74.     if len(text) >= 3:
  75.         if text[len(text) - 1] == '\n' and text[len(text) - 2] == '\r':
  76.             lines = text.splitlines()
  77.             for line in lines:
  78.                 print COMMAND(line)
  79.                 if COMMAND(text) == 'PRIVMSG':
  80.                     line = NICK(text) + ' >> ' + MESSAGE(text) + '\r'
  81.                     IN.insert(END, line)
  82.             print repr(text)
  83.             PONG(text)
  84.             CLOSE(text)
  85.             text = ''
RAW Paste Data
Top