Advertisement
pantteri

Again a oneliner python IRC bot

Jul 25th, 2013
1,704
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.21 KB | None | 0 0
  1. [vars().update({'set':vars().update,'_import':__import__}),set({'socket':_import('socket'),'itertools':_import('itertools'),'sys':_import('sys'),'re':_import('re'),'select':_import('select').select,'time':_import('time'),'urllib2':_import('urllib2'),'getpass':_import('getpass')}),set({'_print':lambda c,y=0:[[logfile.write(x),y or sys.stdout.write(x)]for x in[time.strftime('[%F %T] ')+c+'\n']],'argv':sys.argv,'logfile':open('onebot.log','a+',0)}),len(sys.argv)>1and[set({'server':tuple((sys.argv[1]+':6667').split(':')[:2]),'nick':len(argv)>2and argv[2]or'onebot','realname':len(argv)>3and argv[3]or'Python oneliner IRC bot by Felix Bade','channels':{},'admins':[],'password':getpass.getpass('Admin password: '),'geturl':lambda m:[set({'url':(['']+[x.group(0)for x in[re.search('[^ ]*[a-z]*\.[a-z][a-z]*[^ ]*',c)for c in m] if x])[-1]}),set({'url':'://'in url and url or url and'http://'+url})]})]or[sys.stdout.write('Usage: python %s <host>[:<port>] [<nick>] [<real_name>]\n'%sys.argv[0]),exit(-1)],set({'removechannel':lambda c:set({'channels':{x:channels[x] for x in channels if x!=c}}),'connect':lambda:[_print('Connecting...'),set({'connection':socket.create_connection(server)}),set({'send':lambda x:[_print('<- '+x,1),connection.send(x+'\r\n')],'cfile':connection.makefile()}),set({'reply':lambda x:[send('PRIVMSG '+replyto+' :'+line)for line in x.split('\n')],'replynotice':lambda x:[send('NOTICE '+replyto+' :'+line)for line in x.split('\n')]}),_print('Using nick: '+nick),send('USER '+nick+' 0 * :'+realname+'\r\nNICK '+nick)]}),connect(),[select([cfile],[],[],300)[0]and[set({'data':cfile.readline()[:-2]}),set({'ircdata':re.match('^(:(([^ @!]*)(!([^@]*))?(@([^ ]*))?) )?([^ ]*)(.*?)( :(.*))?$',data).group}),set({'user':ircdata(3),'command':ircdata(8),'args':ircdata(9).split()+[ircdata(11)]}),_print('-> '+data,1),command=='PING'and send('PONG '+args[0]),command=='001'and[_print('Connected!'),send('\r\n'.join(['JOIN '+x for x in channels]))],command=='433'and[set({'nick':nick+'_'}),_print('Changing nick to '+nick),send('NICK '+nick)],command=='NICK'and user in admins and[admins.remove(user),admins.append(args[0])],command=='INVITE'and[_print(user+' invited to '+args[1]),send('JOIN '+args[1])],command=='KICK'and[_print(user+' kicked from '+args[0]+' ('+args[2]+')'),removechannel(args[0])],command=='JOIN'and user==nick and[_print('Joined '+args[0]),channels.update({args[0]:[]})],command=='PART'and user==nick and[_print('Left '+args[0]),removechannel(args[0])],command=='QUIT'and user==nick and _print('Quit ('+args[0]+')'),command=='KILL'and _print('Killed by '+user+' '+re.search('\(.*\)',args[1]).group(0)),command=='ERROR'and _print('Error ('+args[0]+')'),command=='PRIVMSG'and[set({'usercmd':args[1][0]=='@'and args[1][1:].split(' ',1)+['']or[0,0],'ctcp':args[1][0]=='\001'and args[1].strip('\001').split(' ',1)or[0,0],'replyto':args[0]==nick and user or[args[0],channels[args[0]].append(args[1]),len(channels[args[0]])>10and channels[args[0]].pop(0)][0]}),usercmd[0]=='calc'and[_print('Attempting to calculate '+repr(usercmd[1])),reply((lambda g:g[1][2:-1]if g[2]==' ""'else[_print('Error in calculation'),'\x035error'][1])([x.split(':')[1]for x in urllib2.urlopen('http://www.google.com/ig/calculator?hl=en&q='+urllib2.quote(usercmd[1])).read()[1:-1].split(',')])),_print('Done.')],usercmd[0]=='short'and[geturl(args[0]!=nick and channels[args[0]]or[args[1]]),_print('Shortening URL: '+repr(url)),url and reply((lambda a:a[:a.find('<')])((lambda a:'">http://dy.fi/'in a and a[a.find('">http://dy.fi/')+2:]or'')(urllib2.urlopen('http://dy.fi/?c=redir_add&bml=1&url='+urllib2.quote(url)).read())))],usercmd[0]=='auth'and[usercmd[1]==password and[reply('Success!'),_print(user+' is now admin'),admins.append(user)]or[reply('Incorrect password.'),_print('Failed admin attemt by '+user)]],usercmd[0]=='admins'and reply(admins and', '.join(admins)or'No admins.'),usercmd[0]=='password'and[sys.stdout.write(password+'\r'),sys.stdout.flush(),reply('Password printed to stdout')],usercmd[0]=='quote'and user in admins and send(usercmd[1]),usercmd[0]=='lambda'and user in admins and reply(str(eval(usercmd[1]))),ctcp[0]=='PING'and replynotice(args[1]),ctcp[0]=='VERSION'and replynotice('\001VERSION Onebot v_0.n by Felix\001')]]and data or connect()for iteration in itertools.count()]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement