Guest User

Untitled

a guest
Aug 28th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.55 KB | None | 0 0
  1. import socket
  2. import easygui as g
  3. import sys
  4.  
  5. fnode = None
  6.  
  7. chanlist = []
  8. curchan = ''
  9.  
  10. def bot_init_send(nick, user, real, passwd):
  11. freenode = socket.socket()
  12. freenode.connect(('chat.freenode.net', 6667))
  13. passcmd = 'PASS ' + passwd + '\r\n'
  14. usercmd = 'USER ' + user + ' 8 ' + passwd + ' :' + real + '\r\n'
  15. nickcmd = 'NICK ' + nick + '\r\n'
  16. freenode.send(passcmd)
  17. freenode.send(usercmd)
  18. freenode.send(nickcmd)
  19. return freenode
  20.  
  21. def bot_init_recv():
  22. sock = socket.socket()
  23. sock.connect('127.0.0.1', 22)
  24.  
  25. def bot_cmd(sock, cmd):
  26. sock.send(cmd + '\r\n')
  27.  
  28. def bot_join(sock, chan, chanpass):
  29. bot_cmd(sock, 'JOIN ' + chan + ' ' + chanpass)
  30. if chanlist == []:
  31. curchan = chan
  32. chanlist.append(chan)
  33.  
  34.  
  35. def bot_chansend(sock, chan, dat):
  36. for i in range(0, len(chanlist)):
  37. if chanlist[i] == 'chan':
  38. break
  39. return
  40. command = 'PRIVMSG ' + chan + ' :' + dat
  41. bot_cmd(sock, command)
  42.  
  43. def bot_chat(sock, dat):
  44. bot_chansend(sock, curchan, dat)
  45.  
  46. def bot_register(sock, passw, email):
  47. bot_cmd(sock, 'PRIVMSG NickServ :register ' + passw + ' ' + email)
  48.  
  49. while True:
  50. global curchan
  51. choice = g.buttonbox('Please select an IRC bot option.', title = 'IRC Bot Options', choices = ('Join Freenode', 'Register Your Nick', 'Confirm Your Registration', 'Identify Your Nick', 'Join A Channel', 'Switch Your Channel', 'Chat In A Channel', 'Exit'))
  52. if choice == 'Join Freenode':
  53. n = g.enterbox('Enter a nickname: ')
  54. u = g.enterbox('Enter a username: ')
  55. r = g.enterbox('Enter a real name: ')
  56. p = g.enterbox('Enter a password: ')
  57. g.msgbox('Initializing connection to Freenode...')
  58. fnode = bot_init_send(n, u, r, p)
  59. g.msgbox('Connection initialized')
  60. if choice == 'Register Your Nick':
  61. rpass = g.enterbox('Please enter your registration password: ')
  62. rmail = g.enterbox('Please enter your registration email address: ')
  63. if fnode != None:
  64. bot_register(fnode, rpass, rmail)
  65. else:
  66. g.msgbox('Error. No connection to Freenode.')
  67. if choice == 'Exit':
  68. sys.exit()
  69. if choice == 'Join A Channel':
  70. yespass = g.buttonbox('Does this channel have a password?', title = 'Password?', choices = ('No', 'Yes'))
  71. if yespass == 'No':
  72. thechan = g.enterbox('Please enter the name of the channel to join: ')
  73. if fnode != None:
  74. bot_join(fnode, thechan, '')
  75. else:
  76. g.msgbox('Error. No connection to Freenode.')
  77. if yespass == 'Yes':
  78. thechan = g.enterbox('Please enter the name of the channel to join: ')
  79. thepass = g.enterbox('Please enter the password for the channel you previously typed: ')
  80. if fnode != None:
  81. bot_join(fnode, thechan, thepass)
  82. else:
  83. g.msgbox('Error. No connection to Freenode.')
  84. if choice == 'Switch Your Channel':
  85. newchan = g.choicebox('Please choose a channel you already joined to switch to: ', choices = chanlist)
  86. curchan = newchan
  87. if choice == 'Chat In A Channel':
  88. if chanlist != []:
  89. message = g.enterbox('Please enter the data you want to chat in your current channel: ')
  90. if fnode != None:
  91. bot_chat(fnode, message)
  92. else:
  93. g.msgbox('Error. No connection to Freenode.')
  94. else:
  95. g.msgbox('No channels joined. Please join a channel.')
Add Comment
Please, Sign In to add comment