From 875ecf2b155da94a3d3643d48dbee9c53848e741 Mon Sep 17 00:00:00 2001 From: Juhani Haverinen Date: Mon, 8 Jul 2013 20:37:00 +0300 Subject: [PATCH] Made the list of trusted nicks loadable from file --- .gitignore | 2 ++ botcmd.py | 42 ++++++++++++++++++++++++++++-------------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index a5414f3..a737147 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ msgs.txt +trusted.txt +*.pyc diff --git a/botcmd.py b/botcmd.py index 04c4acb..2680f05 100644 --- a/botcmd.py +++ b/botcmd.py @@ -1,15 +1,11 @@ import eliza import threading -concmd=['/q','/debg'] +concmd=['/q','/lt'] doctor=eliza.eliza() -trusted=['nortti','nortti_','shikhin','shikhin_','shikhin__','sortiecat','martinFTW','graphitemaster','XgF','sprocklem'] -opchans=['#osdev-offtopic'] -oprights={} -for i in trusted: - oprights[i]=opchans -autoops={} +trusted=[] +trustedlock=threading.Lock() msgs={} msglock=threading.Lock() authcmds={} @@ -27,14 +23,30 @@ for line in f: f.close() msglock.release() +def loadtrusted(): + trustedlock.acquire() + trusted=[] + f=open('trusted.txt','r') + for line in f: + while len(line)>0 and line[-1]=='\n': line=line[:-1] + if len(line)>0: + trusted.append(line) + f.close() + trustedlock.release() + +loadtrusted() + def addauthcmd(nick,cmd): authcmdlock.acquire() - if nick not in trusted: - return - if nick not in authcmds: - authcmds[nick]=[] - authcmds[nick].append(cmd) + trustedlock.acquire() + if nick in trusted: + if nick not in authcmds: + authcmds[nick]=[] + authcmds[nick].append(cmd) + trustedlock.release() authcmdlock.release() + + def parse((line,irc)): line=line.split(' ') nick=line[0].split('!')[0][1:] @@ -89,14 +101,14 @@ def parse((line,irc)): irc.send('PRIVMSG %s :%s: %s'%(chan,nick,doctor.respond(' '.join(line[4:])))) elif line[1]=='NOTICE' and line[0].split('!')[0]==':NickServ' and line[4]=='ACC': authcmdlock.acquire() + trustedlock.acquire() if line[3][1:] in trusted and line[3][1:] in authcmds and line[5]=='3': for i in authcmds.pop(line[3][1:]): irc.send(i) else: authcmds.pop(line[3][1:]) + trustedlock.release() authcmdlock.release() - elif line[1]=='JOIN' and nick in autoops and chan in autoops[nick]: - irc.send('PRIVMSG NickServ :ACC '+nick) elif line[1]=='482': irc.send('PRIVMSG %s :Not op'%line[3]) @@ -114,6 +126,8 @@ def execcmd(cmdline): f.write('%s\t%s\t%s\n'%(receiver,sender,msg)) f.close() msglock.release() + if cmdline[0]=='/lt': + loadtrusted() def help(cmd): if cmd=='':