__module_name__ = "xAutoSnail" __module_version__ = "0.1" __module_description__ = "AutoOp/Voice users in xchat" import xchat, os, re def readList(): if os.path.exists(config): f = open(config) lines = f.readlines() f.close() global channels for line in lines: try: chan,mode,reg = line.strip().split(':',2) except: continue if not chan in channels.keys(): channels[chan] = {'@':'None', '+':'None'} channels[chan][mode] = re.compile(reg) else: print ' %s: User list not found.' channels = {} def addUser(word, word_eol, userdata): if len(word) != 3: print ' USAGE: "/addauto mode nick" mode: @ or +, nick: must be in chan' return _nick = word[2].lower().strip() _mode = word[1].lower().strip() if not (_mode == '+' or _mode == '@'): return cc = xchat.get_context() _host = findUser(cc, _nick).host _chan = cc.get_info('channel') if _host == None: return _host = '.*?'+_host.lower().strip().replace('~','') temp = {} if os.path.exists(config): f = open(config,'r') lines = f.readlines() f.close() for line in lines: try: chan,mode,reg = line.strip().split(':',2) except: continue if not chan in temp.keys(): temp[chan] = {'@':'None', '+':'None'} temp[chan][mode] = reg if not _chan in temp.keys(): temp[_chan] = {'@':'None', '+':'None'} if not temp[_chan][_mode].count(_host): if temp[_chan][_mode] != '': temp[_chan][_mode] += '|' temp[_chan][_mode] += _host f = open(config,'w') for i in temp.keys(): for j in temp[i].keys(): f.write('%s:%s:%s\n'%(i,j,temp[i][j])) # print i,j,temp[i][j] f.close() readList() return (xchat.EAT_ALL) def onJoin(word, word_eol, userdata): chan = word[2].replace(':','') if not chan in channels.keys(): return nick, host = word[0].lower().split('!',1) nick = nick.replace(':','') cc = xchat.find_context(channel=chan) if channels[chan]['@'].match(host): cc.command('MODE +o %s' % (nick)) elif channels[chan]['+'].match(host): # print chan,nick,host cc.command('MODE +v %s' % (nick)) return (xchat.EAT_NONE) def findUser(cc, nick): for i in cc.get_list('users'): if i.nick.lower() == nick: return (i) print ' Nick %s not found!' % (nick) return (None) channels = {} config = xchat.get_info('xchatdir')+'/xAutoSnail.users' readList() #print channels print ' %s: Loaded v%s'%(__module_name__, __module_version__) xchat.hook_server('JOIN', onJoin) xchat.hook_command('ADDAUTO', addUser)