def channel_modes(nick,host,chan,arg): auth = getauth(nick) hostmask = nick+"!"+host flag = getflag(chan,auth) hostflag = gethostflag(chan,hostmask) if flag == "n" or flag == "o" or hostflag == "o": _chandb.execute("update info set modes='%s' where channel='%s'" % (arg,chan)) put("MODE %s %s" % (chan,arg))
def invite(nick, host, chan, arg): auth = getauth(nick) flag = getflag(chan, auth) hostmask = nick + "!" + host hostflag = gethostflag(chan, hostmask) if flag == "n" or flag == "o" or hostflag == "o": for user in arg.split(): put("INVITE %s %s" % (user, chan))
def channel_topic(nick,host,chan,arg): auth = getauth(nick) hostmask = nick+"!"+host flag = getflag(chan,auth) hostflag = gethostflag(chan,hostmask) if flag == "n" or flag == "o" or hostflag == "o": _chandb.execute("update info set topic='%s' where channel='%s'" % (arg,chan)) put("TOPIC %s :%s" % (chan,arg))
def invite(nick,host,chan,arg): auth = getauth(nick) flag = getflag(chan,auth) hostmask = nick+"!"+host hostflag = gethostflag(chan,hostmask) if flag == "n" or flag == "o" or hostflag == "o": for user in arg.split(): put("INVITE %s %s" % (user,chan))
def exempt(nick, host, chan, arg): auth = getauth(nick) flag = getflag(chan, auth) hostmask = nick + "!" + host hostflag = gethostflag(chan, hostmask) if flag == "n" or flag == "o" or hostflag == "o": if len(arg.split()) > 0: target = arg.split()[0][1:] scut = arg.split()[0][0] if wmatch(target, "*!*@*"): if scut == "+": entry = False for data in _chandb.execute( "select exempt from exempts where channel='%s' and exempt='%s'" % (chan, target)): entry = True if entry is False: _chandb.execute( "insert into exempts values ('%s','%s')" % (chan, target)) put("NOTICE %s :[%s] %s has been added to the exemptlist" % (nick, chan, target)) whochan(chan) else: put("NOTICE %s :[%s] %s is already on the exemptlist" % (nick, chan, target)) elif scut == "-": entry = False for data in _chandb.execute( "select exempt from exempts where channel='%s' and exempt='%s'" % (chan, target)): entry = True if entry is True: _chandb.execute( "delete from exempts where channel='%s' and exempt='%s'" % (chan, target)) put("NOTICE %s :[%s] %s has been removed from the exemptlist" % (nick, chan, target)) put("MODE %s -b %s" % (chan, target)) else: put("NOTICE %s :[%s] %s is not on the exemptlist" % (nick, chan, target)) else: irc_send(nick, "$exempt +/-*!*example@*.example.com") else: irc_send(nick, "$exempt +/-*!*example@*.example.com") else: for data in _chandb.execute( "select exempt from exempts where channel='%s'" % chan): irc_send(nick, "[%s] %s" % (chan, str(data[0])))
def channel_modes(nick, host, chan, arg): auth = getauth(nick) hostmask = nick + "!" + host flag = getflag(chan, auth) hostflag = gethostflag(chan, hostmask) if flag == "n" or flag == "o" or hostflag == "o": _chandb.execute("update info set modes='%s' where channel='%s'" % (arg, chan)) put("MODE %s %s" % (chan, arg))
def channel_drop(nick,uhost,arg): password = arg.split()[0] channel = arg.split()[1] if password == c.get("ADMIN", "password"): _chandb.execute("delete from list where channel='%s'" % channel) put("PART %s" % channel) put("NOTICE %s :%s has been removed from the database" % (nick,channel)) _chandb.execute("delete from channel where channel='%s'" % channel) _chandb.execute("delete from info where channel='%s'" % channel)
def channel_topic(nick, host, chan, arg): auth = getauth(nick) hostmask = nick + "!" + host flag = getflag(chan, auth) hostflag = gethostflag(chan, hostmask) if flag == "n" or flag == "o" or hostflag == "o": _chandb.execute("update info set topic='%s' where channel='%s'" % (arg, chan)) put("TOPIC %s :%s" % (chan, arg))
def channel_register(nick,uhost,arg): password = arg.split()[0] channel = arg.split()[1] if password == c.get("ADMIN", "password"): _chandb.execute("insert into list values ('%s')" % channel) put("JOIN %s" % channel) put("NOTICE %s :%s has been added to the database ... You got owner flags" % (nick,channel)) _chandb.execute("insert into channel values ('%s','%s','n')" % (channel,getauth(nick))) _chandb.execute("insert into info values ('%s','','')" % channel)
def channel_drop(nick, uhost, arg): password = arg.split()[0] channel = arg.split()[1] if password == c.get("ADMIN", "password"): _chandb.execute("delete from list where channel='%s'" % channel) put("PART %s" % channel) put("NOTICE %s :%s has been removed from the database" % (nick, channel)) _chandb.execute("delete from channel where channel='%s'" % channel) _chandb.execute("delete from info where channel='%s'" % channel)
def on_nickchange(nick, uhost, newnick): for data in _cache.execute("select name from botnick"): if nick == str(data[0]): _cache.execute("update botnick set name='%s'" % newnick) if nick.lower() == _botnick.lower(): _cache.execute("update botnick set name='%s'" % _botnick) put("NICK %s" % _botnick) _userdb.execute("delete from auth where nick='%s'" % nick) whois(newnick)
def channel_register(nick, uhost, arg): password = arg.split()[0] channel = arg.split()[1] if password == c.get("ADMIN", "password"): _chandb.execute("insert into list values ('%s')" % channel) put("JOIN %s" % channel) put("NOTICE %s :%s has been added to the database ... You got owner flags" % (nick, channel)) _chandb.execute("insert into channel values ('%s','%s','n')" % (channel, getauth(nick))) _chandb.execute("insert into info values ('%s','','')" % channel)
def on_nickchange(nick,uhost,newnick): for data in _cache.execute("select name from botnick"): if nick == str(data[0]): _cache.execute("update botnick set name='%s'" % newnick) if nick.lower() == _botnick.lower(): _cache.execute("update botnick set name='%s'" % _botnick) put("NICK %s" % _botnick) _userdb.execute("delete from auth where nick='%s'" % nick) whois(newnick)
def kick(nick,host,chan,arg): auth = getauth(nick) flag = getflag(chan,auth) hostmask = nick+"!"+host hostflag = gethostflag(chan,hostmask) if flag == "n" or flag == "o" or hostflag == "o": if len(arg.split()) != 0: target = arg.split()[0] reason = "Requested." if len(arg.split()) != 1: reason = ' '.join(arg.split()[1:]) put("KICK %s %s :%s" % (chan,target,reason))
def kick(nick, host, chan, arg): auth = getauth(nick) flag = getflag(chan, auth) hostmask = nick + "!" + host hostflag = gethostflag(chan, hostmask) if flag == "n" or flag == "o" or hostflag == "o": if len(arg.split()) != 0: target = arg.split()[0] reason = "Requested." if len(arg.split()) != 1: reason = ' '.join(arg.split()[1:]) put("KICK %s %s :%s" % (chan, target, reason))
def exempt(nick,host,chan,arg): auth = getauth(nick) flag = getflag(chan,auth) hostmask = nick+"!"+host hostflag = gethostflag(chan,hostmask) if flag == "n" or flag == "o" or hostflag == "o": if len(arg.split()) > 0: target = arg.split()[0][1:] scut = arg.split()[0][0] if wmatch(target, "*!*@*"): if scut == "+": entry = False for data in _chandb.execute("select exempt from exempts where channel='%s' and exempt='%s'" % (chan,target)): entry = True if entry is False: _chandb.execute("insert into exempts values ('%s','%s')" % (chan,target)) put("NOTICE %s :[%s] %s has been added to the exemptlist" % (nick,chan,target)) whochan(chan) else: put("NOTICE %s :[%s] %s is already on the exemptlist" % (nick,chan,target)) elif scut == "-": entry = False for data in _chandb.execute("select exempt from exempts where channel='%s' and exempt='%s'" % (chan,target)): entry = True if entry is True: _chandb.execute("delete from exempts where channel='%s' and exempt='%s'" % (chan,target)) put("NOTICE %s :[%s] %s has been removed from the exemptlist" % (nick,chan,target)) put("MODE %s -b %s" % (chan,target)) else: put("NOTICE %s :[%s] %s is not on the exemptlist" % (nick,chan,target)) else: irc_send(nick,"$exempt +/-*!*example@*.example.com") else: irc_send(nick,"$exempt +/-*!*example@*.example.com") else: for data in _chandb.execute("select exempt from exempts where channel='%s'" % chan): irc_send(nick,"[%s] %s" % (chan,str(data[0])))
def irc_bans(text): chan = text.split()[3] host = text.split()[7]+"!"+text.split()[4]+"@"+text.split()[5] for data in _chandb.execute("select ban from bans where channel='%s'" % chan): if wmatch(host.lower(), str(data[0]).lower()): entry = False for data1 in _chandb.execute("select exempt from exempts where channel='%s'" % chan): if wmatch(host.lower(), str(data1[0]).lower()): entry = True for botnick in _cache.execute("select name from botnick"): if str(text.split()[7]).lower() == str(text.split()[2]).lower(): entry = True if entry == False: put("MODE %s +b %s" % (chan,data[0])) put("KICK %s %s :Banned." % (chan,text.split()[7]))
def irc_bans(text): chan = text.split()[3] host = text.split()[7] + "!" + text.split()[4] + "@" + text.split()[5] for data in _chandb.execute("select ban from bans where channel='%s'" % chan): if wmatch(host.lower(), str(data[0]).lower()): entry = False for data1 in _chandb.execute( "select exempt from exempts where channel='%s'" % chan): if wmatch(host.lower(), str(data1[0]).lower()): entry = True for botnick in _cache.execute("select name from botnick"): if str(text.split()[7]).lower() == str( text.split()[2]).lower(): entry = True if entry == False: put("MODE %s +b %s" % (chan, data[0])) put("KICK %s %s :Banned." % (chan, text.split()[7]))
def channel_auth(nick,host,chan,arg): whois(nick) put("NOTICE %s :[%s] Trying to auth ..." % (nick,chan)) auth = getauth(nick) hostmask = nick+"!"+host put("NOTICE %s :[%s] Getting flag for %s (%s)..." % (nick,chan,auth,hostmask)) flag = getflag(chan,auth) hostflag = gethostflag(chan,hostmask) put("NOTICE %s :[%s] Flag: %s, Hostflag: %s" % (nick,chan,flag,hostflag)) if flag == "n" or flag == "o" or hostflag == "o": putf("MODE %s +o %s" % (chan,nick)) elif flag == "v" or hostflag == "v": putf("MODE %s +v %s" % (chan,nick))
def channel_auth(nick, host, chan, arg): whois(nick) put("NOTICE %s :[%s] Trying to auth ..." % (nick, chan)) auth = getauth(nick) hostmask = nick + "!" + host put("NOTICE %s :[%s] Getting flag for %s (%s)..." % (nick, chan, auth, hostmask)) flag = getflag(chan, auth) hostflag = gethostflag(chan, hostmask) put("NOTICE %s :[%s] Flag: %s, Hostflag: %s" % (nick, chan, flag, hostflag)) if flag == "n" or flag == "o" or hostflag == "o": putf("MODE %s +o %s" % (chan, nick)) elif flag == "v" or hostflag == "v": putf("MODE %s +v %s" % (chan, nick))
def channel_listuser(nick,host,chan,arg): for owner in _chandb.execute("select auth from channel where channel='%s' and flags='n'" % chan): put("NOTICE %s :[%s] %s is the owner" % (nick,chan,owner[0])) op = list() for operator in _chandb.execute("select auth from channel where channel='%s' and flags='o'" % chan): op.append(str(operator[0])) operators = ' '.join(op) put("NOTICE %s :[%s] Operators: %s" % (nick,chan,operators)) v = list() for voice in _chandb.execute("select auth from channel where channel='%s' and flags='v'" % chan): v.append(str(voice[0])) voices = ' '.join(v) put("NOTICE %s :[%s] Voices: %s" % (nick,chan,voices))
def channel_msg_auth(nick,host,arg): if len(arg) == 0: irc_send(nick, "no channel specified") elif arg.startswith("#"): whois(nick) chan = arg.split()[0] put("NOTICE %s :[%s] Trying to auth ..." % (nick,chan)) auth = getauth(nick) hostmask = nick+"!"+host put("NOTICE %s :[%s] Getting flag for %s (%s)..." % (nick,chan,auth,hostmask)) flag = getflag(chan,auth) hostflag = gethostflag(chan,hostmask) put("NOTICE %s :[%s] Flag: %s, Hostflag: %s" % (nick,chan,flag,hostflag)) if flag == "n" or flag == "o" or hostflag == "o": putf("MODE %s +o %s" % (chan,nick)) elif flag == "v" or hostflag == "v": putf("MODE %s +v %s" % (chan,nick)) else: irc_send(nick, "invalid channel")
def channel_msg_auth(nick, host, arg): if len(arg) == 0: irc_send(nick, "no channel specified") elif arg.startswith("#"): whois(nick) chan = arg.split()[0] put("NOTICE %s :[%s] Trying to auth ..." % (nick, chan)) auth = getauth(nick) hostmask = nick + "!" + host put("NOTICE %s :[%s] Getting flag for %s (%s)..." % (nick, chan, auth, hostmask)) flag = getflag(chan, auth) hostflag = gethostflag(chan, hostmask) put("NOTICE %s :[%s] Flag: %s, Hostflag: %s" % (nick, chan, flag, hostflag)) if flag == "n" or flag == "o" or hostflag == "o": putf("MODE %s +o %s" % (chan, nick)) elif flag == "v" or hostflag == "v": putf("MODE %s +v %s" % (chan, nick)) else: irc_send(nick, "invalid channel")
def channel_listuser(nick, host, chan, arg): for owner in _chandb.execute( "select auth from channel where channel='%s' and flags='n'" % chan): put("NOTICE %s :[%s] %s is the owner" % (nick, chan, owner[0])) op = list() for operator in _chandb.execute( "select auth from channel where channel='%s' and flags='o'" % chan): op.append(str(operator[0])) operators = ' '.join(op) put("NOTICE %s :[%s] Operators: %s" % (nick, chan, operators)) v = list() for voice in _chandb.execute( "select auth from channel where channel='%s' and flags='v'" % chan): v.append(str(voice[0])) voices = ' '.join(v) put("NOTICE %s :[%s] Voices: %s" % (nick, chan, voices))
def channel_delvoice(nick, host, chan, arg): auth = getauth(nick) flag = getflag(chan, auth) target = getauth(arg.split()[0]) uatarget = arg.split()[0] if flag == "n": if auth != target: if wmatch(uatarget, "*!*@*"): entry = True for data in _chandb.execute( "select flags from channel where channel='%s' and auth = '%s' and flags='v'" % (chan, uatarget)): entry = False if entry is False: _chandb.execute( "delete from channel where channel='%s' and auth='%s' and flags='v'" % (chan, uatarget)) put("NOTICE %s :[%s] %s has been removed from the voices list" % (nick, chan, uatarget)) else: put("NOTICE %s :[%s] %s is not on the voices list" % (nick, chan, uatarget)) else: entry = True for data in _chandb.execute( "select flags from channel where channel='%s' and auth='%s' and flags='v'" % (chan, target)): entry = False if entry is False: _chandb.execute( "delete from channel where channel='%s' and auth='%s' and flags='v'" % (chan, target)) put("NOTICE %s :[%s] %s has been removed from the voices list" % (nick, chan, target)) put("MODE %s -v %s" % (chan, arg.split()[0])) else: put("NOTICE %s :[%s] %s is not on the voices list" % (nick, chan, target)) else: put("NOTICE %s :[%s] You cannot remove yourself!" % (nick, chan))
def channel_addvoice(nick,host,chan,arg): auth = getauth(nick) flag = getflag(chan,auth) target = getauth(arg.split()[0]) uatarget = arg.split()[0] if flag == "n": if auth != target: if wmatch(uatarget, "*!*@*"): entry = False for data in _chandb.execute("select flags from channel where channel='%s' and auth = '%s' and flags='v'" % (chan,uatarget)): entry = True if entry is False: _chandb.execute("insert into channel values ('%s','%s','v')" % (chan,uatarget)) put("NOTICE %s :[%s] %s has been added to the voices list" % (nick,chan,uatarget)) else: put("NOTICE %s :[%s] %s is already on the voices list" % (nick,chan,uatarget)) else: entry = False for data in _chandb.execute("select flags from channel where channel='%s' and auth='%s' and flags='v'" % (chan,target)): entry = True if entry is False: _chandb.execute("insert into channel values ('%s','%s','v')" % (chan,target)) put("NOTICE %s :[%s] %s has been added to the voices list" % (nick,chan,target)) put("MODE %s +v %s" % (chan,arg.split()[0])) else: put("NOTICE %s :[%s] %s is already on the voices list" % (nick,chan,target)) else: put("NOTICE %s :[%s] You cannot add yourself!" % (nick,chan))
def channel_invite(nick, uhost, chan, target): if target.lower() == botnick().lower(): for data in _chandb.execute( "select channel from list where channel='%s'" % chan): put("JOIN %s" % chan)
def channel_addvoice(nick, host, chan, arg): auth = getauth(nick) flag = getflag(chan, auth) target = getauth(arg.split()[0]) uatarget = arg.split()[0] if flag == "n": if auth != target: if wmatch(uatarget, "*!*@*"): entry = False for data in _chandb.execute( "select flags from channel where channel='%s' and auth = '%s' and flags='v'" % (chan, uatarget)): entry = True if entry is False: _chandb.execute( "insert into channel values ('%s','%s','v')" % (chan, uatarget)) put("NOTICE %s :[%s] %s has been added to the voices list" % (nick, chan, uatarget)) else: put("NOTICE %s :[%s] %s is already on the voices list" % (nick, chan, uatarget)) else: entry = False for data in _chandb.execute( "select flags from channel where channel='%s' and auth='%s' and flags='v'" % (chan, target)): entry = True if entry is False: _chandb.execute( "insert into channel values ('%s','%s','v')" % (chan, target)) put("NOTICE %s :[%s] %s has been added to the voices list" % (nick, chan, target)) put("MODE %s +v %s" % (chan, arg.split()[0])) else: put("NOTICE %s :[%s] %s is already on the voices list" % (nick, chan, target)) else: put("NOTICE %s :[%s] You cannot add yourself!" % (nick, chan))
def channel_invite(nick,uhost,chan,target): if target.lower() == botnick().lower(): for data in _chandb.execute("select channel from list where channel='%s'" % chan): put("JOIN %s" % chan)
def notice(target,text): put("NOTICE %s :%s" % (target,text))
def on_quit(nick, uhost, arg): _userdb.execute("delete from auth where nick='%s'" % nick) if nick.lower() == _botnick.lower(): _cache.execute("update botnick set name='%s'" % _botnick) put("NICK %s" % _botnick)
def on_topic(nick,uhost,chan,arg): for mynick in _cache.execute("select name from botnick"): if nick != str(mynick[0]) and nick != "Q" and nick != "ChanServ": for data in _chandb.execute("select topic from info where channel='%s'" % chan): put("TOPIC %s :%s" % (chan,str(data[0])))
def uname(nick,host,chan,arg): sysinfo = ' '.join(os.uname()) put("PRIVMSG %s :%s" % (chan, sysinfo))
def channel_join(text): putf("JOIN %s" % c.get("BOT", "channels")) for data in _chandb.execute("select channel from list"): put("JOIN %s" % data[0])
def channel_kick(nick,uhost,chan,target,arg): for data in _cache.execute("select name from botnick"): for user in target.split(","): if user.lower() == str(data[0]).lower(): put("JOIN %s" % chan)
def irc_send(target,message): if target.startswith("#"): put("PRIVMSG %s :%s" % (target,message)) else: put("NOTICE %s :%s" % (target,message))
def irc_botnick(nick, host, chan, arg): for data in _cache.execute("select name from botnick"): put("PRIVMSG %s :My configured nick is %s and my current nick is %s." % (chan, _botnick, str(data[0])))
def notice(target, text): put("NOTICE %s :%s" % (target, text))
def channel_kick(nick, uhost, chan, target, arg): for data in _cache.execute("select name from botnick"): for user in target.split(","): if user.lower() == str(data[0]).lower(): put("JOIN %s" % chan)
def client(self, sock, addr, servsock): try: printc("!! conntected with " + addr + " !!") self.send(sock, "Hello. I am %s." % c.get("BOT", "username")) self.send(sock, "Welcome to the remote interface of PIRB.") self.send(sock, "Please enter the administrators password to unlock!") if str(sock.recv(100)).rstrip() == c.get("ADMIN", "password"): self.send(sock, "Access granted.") printc("!! " + addr + " logged in !!") else: self.send(sock, "Access denied.") printc("!! " + addr + " failed login !!") sock.close() while 1: raw = sock.recv(1024) data = raw.rstrip() if not data: printc("!! losed connection with " + addr + " !!") sock.close() if data: cmd = data.split()[0].lower() if cmd == "crypt": sha = hashlib.sha1() sha.update(data[6:]) self.send(sock, "Hash: %s" % str(sha.hexdigest())) elif cmd == "put": open(".put_query", "a").write(data[4:] + "\n") self.send(sock, "Sent: %s" % data[4:]) elif cmd == "restart": if os.access("pirb.pid", os.F_OK): self.send(sock, "Restarting ...") servsock.close() sock.close() shell("sh pirb restart") else: self.send(sock, "Cannot restart when debug is running") elif cmd == "update": _file = open("version", "r") _old = _file.read() _file.close() _web = urllib2.urlopen( "https://raw.github.com/Pythonz/PIRB/master/version" ) _new = _web.read() _web.close() if _old != _new: self.send(sock, "{0} -> {1}".format(_old, _new)) __cache = len(os.listdir("database/updates/cache")) __chan = len(os.listdir("database/updates/chan")) __user = len(os.listdir("database/updates/user")) shell("git add .") shell("git rm --cached database/*.db") shell("git commit -m 'Save'") shell("git pull") ___cache = os.listdir("database/updates/cache") if __cache < len(___cache): while __cache != len(___cache): __cache += 1 for sql in ___cache: if sql.startswith(str(__cache) + "_"): self.send( sock, " - Insert 'cache/{0}'".format( sql)) shell( "sqlite3 database/cache.db < database/updates/cache/{0}" .format(sql)) ___chan == os.listdir("database/updates/chan") if __chan < len(___chan): while __chan != len(___chan): __chan += 1 for sql in ___chan: if sql.startswith(str(__chan) + "_"): self.send( sock, " - Insert 'chan/{0}'".format( sql)) shell( "sqlite3 database/chan.db < database/updates/chan/{0}" .format(sql)) ___user == os.listdir("database/updates/user") if __user < len(___user): while __user != len(___user): __user += 1 for sql in ___user: if sql.startswith(str(__user) + "_"): self.send( sock, " - Insert 'user/{0}'".format( sql)) shell( "sqlite3 database/user.db < database/updates/user/{0}" .format(sql)) put("QUIT :Updating...") servsock.close() sock.close() shell("sh pirb restart") else: self.send(sock, "No update available.") elif cmd == "version": file = open("version", "r") self.send(sock, "PIRB " + file.read()) file.close() elif cmd == "quit": self.send(sock, "Bye :(") sock.close() elif cmd == "die": servsock.close() sock.close() if os.access("pirb.pid", os.F_OK): shell("sh pirb stop") else: sys.exit(2) elif cmd == "help": tbl = list() tbl.append("help") tbl.append("crypt") tbl.append("put") tbl.append("restart") tbl.append("update") tbl.append("version") tbl.append("die") tbl.append("quit") for command in tbl: self.send(sock, command.upper()) else: self.send( sock, "unknown command '%s'. try 'HELP'" % cmd.upper()) except Exception, e: printe(e)
def on_mode(nick,uhost,chan,arg): for mynick in _cache.execute("select name from botnick"): if nick != str(mynick[0]): for data in _chandb.execute("select modes from info where channel='%s'" % chan): put("MODE %s %s" % (chan,str(data[0])))
def irc_send(target, message): if target.startswith("#"): put("PRIVMSG %s :%s" % (target, message)) else: put("NOTICE %s :%s" % (target, message))
def channel_delvoice(nick,host,chan,arg): auth = getauth(nick) flag = getflag(chan,auth) target = getauth(arg.split()[0]) uatarget = arg.split()[0] if flag == "n": if auth != target: if wmatch(uatarget, "*!*@*"): entry = True for data in _chandb.execute("select flags from channel where channel='%s' and auth = '%s' and flags='v'" % (chan,uatarget)): entry = False if entry is False: _chandb.execute("delete from channel where channel='%s' and auth='%s' and flags='v'" % (chan,uatarget)) put("NOTICE %s :[%s] %s has been removed from the voices list" % (nick,chan,uatarget)) else: put("NOTICE %s :[%s] %s is not on the voices list" % (nick,chan,uatarget)) else: entry = True for data in _chandb.execute("select flags from channel where channel='%s' and auth='%s' and flags='v'" % (chan,target)): entry = False if entry is False: _chandb.execute("delete from channel where channel='%s' and auth='%s' and flags='v'" % (chan,target)) put("NOTICE %s :[%s] %s has been removed from the voices list" % (nick,chan,target)) put("MODE %s -v %s" % (chan,arg.split()[0])) else: put("NOTICE %s :[%s] %s is not on the voices list" % (nick,chan,target)) else: put("NOTICE %s :[%s] You cannot remove yourself!" % (nick,chan))
def on_topic(nick, uhost, chan, arg): for mynick in _cache.execute("select name from botnick"): if nick != str(mynick[0]) and nick != "Q" and nick != "ChanServ": for data in _chandb.execute( "select topic from info where channel='%s'" % chan): put("TOPIC %s :%s" % (chan, str(data[0])))
def ctcp(target, text): put(u"PRIVMSG %s :\u0001%s\u0001" % (target, text))
def on_mode(nick, uhost, chan, arg): for mynick in _cache.execute("select name from botnick"): if nick != str(mynick[0]): for data in _chandb.execute( "select modes from info where channel='%s'" % chan): put("MODE %s %s" % (chan, str(data[0])))
def client(self,sock,addr,servsock): try: printc("!! conntected with "+addr+" !!") self.send(sock,"Hello. I am %s." % c.get("BOT","username")) self.send(sock,"Welcome to the remote interface of PIRB.") self.send(sock,"Please enter the administrators password to unlock!") if str(sock.recv(100)).rstrip() == c.get("ADMIN", "password"): self.send(sock,"Access granted.") printc("!! "+addr+" logged in !!") else: self.send(sock,"Access denied.") printc("!! "+addr+" failed login !!") sock.close() while 1: raw = sock.recv(1024) data = raw.rstrip() if not data: printc("!! losed connection with "+addr+ " !!") sock.close() if data: cmd = data.split()[0].lower() if cmd == "crypt": sha = hashlib.sha1() sha.update(data[6:]) self.send(sock,"Hash: %s" % str(sha.hexdigest())) elif cmd == "put": open(".put_query", "a").write(data[4:]+"\n") self.send(sock,"Sent: %s" % data[4:]) elif cmd == "restart": if os.access("pirb.pid", os.F_OK): self.send(sock,"Restarting ...") servsock.close() sock.close() shell("sh pirb restart") else: self.send(sock,"Cannot restart when debug is running") elif cmd == "update": _file = open("version", "r") _old = _file.read() _file.close() _web = urllib2.urlopen("https://raw.github.com/Pythonz/PIRB/master/version") _new = _web.read() _web.close() if _old != _new: self.send(sock, "{0} -> {1}".format(_old, _new)) __cache = len(os.listdir("database/updates/cache")) __chan = len(os.listdir("database/updates/chan")) __user = len(os.listdir("database/updates/user")) shell("git add .") shell("git rm --cached database/*.db") shell("git commit -m 'Save'") shell("git pull") ___cache = os.listdir("database/updates/cache") if __cache < len(___cache): while __cache != len(___cache): __cache += 1 for sql in ___cache: if sql.startswith(str(__cache)+"_"): self.send(sock, " - Insert 'cache/{0}'".format(sql)) shell("sqlite3 database/cache.db < database/updates/cache/{0}".format(sql)) ___chan == os.listdir("database/updates/chan") if __chan < len(___chan): while __chan != len(___chan): __chan += 1 for sql in ___chan: if sql.startswith(str(__chan)+"_"): self.send(sock, " - Insert 'chan/{0}'".format(sql)) shell("sqlite3 database/chan.db < database/updates/chan/{0}".format(sql)) ___user == os.listdir("database/updates/user") if __user < len(___user): while __user != len(___user): __user += 1 for sql in ___user: if sql.startswith(str(__user)+"_"): self.send(sock, " - Insert 'user/{0}'".format(sql)) shell("sqlite3 database/user.db < database/updates/user/{0}".format(sql)) put("QUIT :Updating...") servsock.close() sock.close() shell("sh pirb restart") else: self.send(sock, "No update available.") elif cmd == "version": file = open("version", "r") self.send(sock, "PIRB "+file.read()) file.close() elif cmd == "quit": self.send(sock,"Bye :(") sock.close() elif cmd == "die": servsock.close() sock.close() if os.access("pirb.pid", os.F_OK): shell("sh pirb stop") else: sys.exit(2) elif cmd == "help": tbl = list() tbl.append("help") tbl.append("crypt") tbl.append("put") tbl.append("restart") tbl.append("update") tbl.append("version") tbl.append("die") tbl.append("quit") for command in tbl: self.send(sock, command.upper()) else: self.send(sock,"unknown command '%s'. try 'HELP'" % cmd.upper()) except Exception,e: printe(e)
def on_quit(nick,uhost,arg): _userdb.execute("delete from auth where nick='%s'" % nick) if nick.lower() == _botnick.lower(): _cache.execute("update botnick set name='%s'" % _botnick) put("NICK %s" % _botnick)
def ctcp(target,text): put(u"PRIVMSG %s :\u0001%s\u0001" % (target,text))
def irc_botnick(nick,host,chan,arg): for data in _cache.execute("select name from botnick"): put("PRIVMSG %s :My configured nick is %s and my current nick is %s." % (chan,_botnick,str(data[0])))