Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- import easygui as g
- import sys
- fnode = None
- chanlist = []
- curchan = ''
- def bot_init_send(nick, user, real, passwd):
- freenode = socket.socket()
- freenode.connect(('chat.freenode.net', 6667))
- passcmd = 'PASS ' + passwd + '\r\n'
- usercmd = 'USER ' + user + ' 8 ' + passwd + ' :' + real + '\r\n'
- nickcmd = 'NICK ' + nick + '\r\n'
- freenode.send(passcmd)
- freenode.send(usercmd)
- freenode.send(nickcmd)
- return freenode
- def bot_init_recv():
- sock = socket.socket()
- sock.connect('127.0.0.1', 22)
- def bot_cmd(sock, cmd):
- sock.send(cmd + '\r\n')
- def bot_join(sock, chan, chanpass):
- bot_cmd(sock, 'JOIN ' + chan + ' ' + chanpass)
- if chanlist == []:
- curchan = chan
- chanlist.append(chan)
- def bot_chansend(sock, chan, dat):
- for i in range(0, len(chanlist)):
- if chanlist[i] == 'chan':
- break
- return
- command = 'PRIVMSG ' + chan + ' :' + dat
- bot_cmd(sock, command)
- def bot_chat(sock, dat):
- bot_chansend(sock, curchan, dat)
- def bot_register(sock, passw, email):
- bot_cmd(sock, 'PRIVMSG NickServ :register ' + passw + ' ' + email)
- while True:
- global curchan
- 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'))
- if choice == 'Join Freenode':
- n = g.enterbox('Enter a nickname: ')
- u = g.enterbox('Enter a username: ')
- r = g.enterbox('Enter a real name: ')
- p = g.enterbox('Enter a password: ')
- g.msgbox('Initializing connection to Freenode...')
- fnode = bot_init_send(n, u, r, p)
- g.msgbox('Connection initialized')
- if choice == 'Register Your Nick':
- rpass = g.enterbox('Please enter your registration password: ')
- rmail = g.enterbox('Please enter your registration email address: ')
- if fnode != None:
- bot_register(fnode, rpass, rmail)
- else:
- g.msgbox('Error. No connection to Freenode.')
- if choice == 'Exit':
- sys.exit()
- if choice == 'Join A Channel':
- yespass = g.buttonbox('Does this channel have a password?', title = 'Password?', choices = ('No', 'Yes'))
- if yespass == 'No':
- thechan = g.enterbox('Please enter the name of the channel to join: ')
- if fnode != None:
- bot_join(fnode, thechan, '')
- else:
- g.msgbox('Error. No connection to Freenode.')
- if yespass == 'Yes':
- thechan = g.enterbox('Please enter the name of the channel to join: ')
- thepass = g.enterbox('Please enter the password for the channel you previously typed: ')
- if fnode != None:
- bot_join(fnode, thechan, thepass)
- else:
- g.msgbox('Error. No connection to Freenode.')
- if choice == 'Switch Your Channel':
- newchan = g.choicebox('Please choose a channel you already joined to switch to: ', choices = chanlist)
- curchan = newchan
- if choice == 'Chat In A Channel':
- if chanlist != []:
- message = g.enterbox('Please enter the data you want to chat in your current channel: ')
- if fnode != None:
- bot_chat(fnode, message)
- else:
- g.msgbox('Error. No connection to Freenode.')
- else:
- g.msgbox('No channels joined. Please join a channel.')
Add Comment
Please, Sign In to add comment