def kl(inp, say=None, nick=None, input=None, bot=None): "kill switch." if not perm.isowner(input): input.notice("Only the bot owner can use this command!") elif perm.isowner(input): confofall=bot.config for xcon in bot.conns: confofall['connections'][xcon]=bot.conns[xcon].conf json.dump(confofall, open('config', 'w'), sort_keys=True, indent=1) time.sleep(0.1) for xcon in bot.conns: bot.conns[xcon].send("NICK "+input.conn.nick+"|offline") time.sleep(0.5) for xcon in bot.conns: if inp=="": bot.conns[xcon].send('QUIT :\x02\x034,1Kill switch ' 'activated by %s.' % (input.nick)) else: bot.conns[xcon].send('QUIT :\x02\x034,1Kill switch ' 'activated by %s. Reason: %s' % (input.nick, inp)) time.sleep(0.1) if os.name == 'posix': #client("127.0.0.1", 4329, "bot term. shutdown. NOW") #os.system("kill "+str(os.getpid())) bot.term=True os._exit(0) elif os.name == 'nt': #client("127.0.0.1", 4329, "bot term. shutdown. NOW") #os.system("taskkill "+str(os.getpid())) bot.term=True os._exit(0)
def kickss(inp, input=None, bot=None): repchan = input.conn.conf["reportchan"] nickf = munge.munge(0, input, bot, 0, "") json.dump(bot.config, open('config', 'w'), sort_keys=True, indent=1) if input.nick==input.conn.nick and not perm.isowner(input) and not perm.isbot(input): input.conn.conf['channels'].remove(input.inp) input.conn.send("PRIVMSG "+repchan+" :I have been kicked in "+input.chan+" by "+nickf)
def nick(inp, input=None, notice=None): ".nick <nick> -- change the bots nickname to <nick>" if not perm.isowner(input): notice("Only the bot owner can use this command!") return notice("Changing nick to %s." % (inp)) input.conn.send("NICK %s" % (inp))
def scp(inp, db_global=None,input=None): ",scp <query>/<item id> -- Returns SCP Foundation wiki search result for <query>/<item id>." db_global.execute("create table if not exists scpwiki(itemname, itemid, classtype, desc, url, time)") db_global.commit() if ((inp=="clear cache") and (perm.isowner(input))): db_global.execute("DELETE FROM main.`scpwiki`") db_global.commit() return("cache cleared.") timemon = time.strftime("%m", time.gmtime()) inten=1 for data in badlet: if data in input.inp: inten=0 if inten==0: url = page(inp,input.host) if inten==1: if len(inp)==3: url = page(inp,input.host) if len(inp)==2: url = page("0"+inp,input.host) if len(inp)==1: url = page("00"+inp,input.host) dburl = db_global.execute("select url from scpwiki where url=(?)",(url,)).fetchone() if not dburl==None: return dbresponse(url,db_global) else: scpid = url.replace("http://www.scp-wiki.net/scp-","") print(scpid) url = "http://www.scp-wiki.net/scp-"+scpid return goturlforscp(url,scpid,db_global,timemon,inten)
def mcmess(inp,bot=None,input=None): "the disconnect message users recieve on the fake minecraft classic" \ " server when they try to connect. bot owner only." if perm.isowner(input): global mess mess = inp return "Done." else: return "Nope.avi"
def tcp(inp,bot=None,input=None): ",tcp <IP/web-address> <port> <message> -- sends a tcp packet to " \ "<IP/web-address> at port <port> with <message> as the message." \ " only the bot owner can use this." check = input.inp.split(" ") check2 = input.inp.replace(check[0]+" "+check[1]+" ","") if perm.isowner(input): return(str(client(check[0],int(check[1]),check2))) return "Nope.avi"
def awatch(bot, input, func, kind, args): repchan = ''.join(input.conn.conf["reportchan"]) #the channel to report back to cmdpre = "," #your cmd prefix ignorenick=''.join(input.conn.conf["owner"]) nickf = munge.munge(0, input, bot, 0, "") cmduse = (sorted(bot.commands)) cmdign=",auth" cmdign2="auth" #print(input.lastparam) if kind=="command" and not perm.isowner(input) and not input.lastparam.startswith(cmdign) and not input.lastparam.startswith(cmdign2): cmdused = input.trigger if input.lastparam==",stfu" or input.lastparam==",ignore": input.conn.send("PRIVMSG "+repchan+" :I have been muted in "+input.chan+" by "+nickf+'!'+input.mask) if input.lastparam==",kthx" or input.lastparam==",listen": input.conn.send("PRIVMSG "+repchan+" :I have been unmuted in "+input.chan+" by "+nickf+'!'+input.mask) if input.lastparam==",join": input.conn.send("PRIVMSG "+repchan+" :I have joined "+input.chan+" as told to by "+nickf+'!'+input.mask) if input.lastparam==",part" or input.lastparam==",gtfo": input.conn.send("PRIVMSG "+repchan+" :I have left "+input.chan+" as told to by "+nickf+'!'+input.mask) if input.chan==input.nick and not perm.isowner(input) and cmdused in cmduse and not input.lastparam.startswith(cmdign):#cmd use in a private msg input.conn.send("PRIVMSG "+repchan+" :"+nickf+'!'+input.mask+" (used/tried to use) "+input.lastparam+" in a private message.") if input.chan.startswith("#") and not input.chan==repchan and not perm.isowner(input) and cmdused in cmduse and not input.lastparam.startswith(cmdign):#cmd use in a channel input.conn.send("PRIVMSG "+repchan+" :"+nickf+'!'+input.mask+" (used/tried to use) "+input.lastparam+" in "+input.chan) if input.chan==repchan and not perm.isowner(input) and cmdused in cmduse and not input.lastparam.startswith(cmdign):#cmd use in the report chan which is sent back to the owner. input.conn.send("PRIVMSG "+ignorenick+" :"+input.nick+'!'+input.mask+" (used/tried to use) "+input.lastparam+" in "+repchan) elif (not perm.isowner(input)) and ((input.lastparam.startswith("?") and not input.lastparam=="?") or (input.lastparam.startswith("!") and not input.lastparam=="!")): if (input.command=="PRIVMSG" and not input.lastparam in cmduse): if input.chan==input.nick and not perm.isowner(input):#factoids in a privmsg input.conn.send("PRIVMSG "+repchan+" :"+nickf+'!'+input.mask+" asked me "+input.lastparam+" in a private message.") elif not input.lastparam.startswith(cmdign): input.conn.send("PRIVMSG "+repchan+" :"+nickf+'!'+input.mask+" asked me "+input.lastparam+" in "+input.chan) return input
def rcon(inp,bot=None,input=None): if inp=="": return(",rcon <hostname/ip> <port> <password(must have NO spaces...)> <command to use on server> -- rcon client for a minecraft server. Best to use this in a PM.") check = input.inp.split(" ") check2 = input.inp.replace(check[0]+" "+check[1]+" "+check[2]+" ","") if perm.isowner(input): try: rdata = (rconclient(check[0],int(check[1]),check[2],check2)) except Exception, msg: return("Error. "+str(msg)) rdat = rdata.split('\n') for dat in rdat: input.say(dat) return "Done."
def fakemcserver(inp,bot=None,input=None): ",fakemcserver <port> <max players> <server-name-with-no-spaces> " \ "<players-you-want-on-it> -- makes a fake minecraft classic server." \ "also appears on the mc classic server list..." if perm.isowner(input): check = input.inp.split(" ") if len(check)==4: i = 0 HOST, PORT = "", int(check[0]) global bottest bottest = ThreadedTCPServer((HOST, PORT), \ ThreadedTCPRequestHandler) ip, portss = bottest.server_address global server_thread server_thread = threading.Thread(target=bottest.serve_forever) server_thread.daemon = True server_thread.start() perm.repamsg(input,"Server loop running in thread: %s" % (server_thread.name)) url1 = ("http://www.minecraft.net/heartbeat.jsp?port=%s" % (check[0])) url2 = ("&max=%s&name=%s&public=True&version=7" % (check[1],check[2])) url3 = "&users=%s" % (check[3]) pageUrl = ("%s%s&salt=wo6kVAHjxoJcInKx%s" % (url1,url2,url3)) web = str(http.get(pageUrl)) perm.repamsg(input,web) while True: web = str(http.get(pageUrl)) if i==100: i=0 perm.repamsg(input,web) global plays plays = int(str(playeramount[-1]).replace("Thread-","")) bot.test["test"]=int(plays)-2 i+=1 time.sleep(45) else: return("error.") else: return("Nope.avi")
def wikia(inp,input,db_global,wiki,wikiname,wikiurl,wikilen,wikiwiki): db_global.execute("create table if not exists "+wikiname+"wiki(desc, url, time, query)") db_global.commit() if ((inp=="clear cache") and (perm.isowner(input))): db_global.execute("DELETE FROM main.`"+wikiname+"wiki`") db_global.commit() return("cache cleared.") timemon = time.strftime("%m", time.gmtime()) if len(inp)>0: requesturl = wikiwiki+"api.php?format=json&action=query&titles="+inp.replace(" ","%20")+"&prop=revisions&rvprop=content" dburl = db_global.execute("select query from "+wikiname+"wiki where query=(?)",(inp.lower(),)).fetchone() dbtime = db_global.execute("select time from "+wikiname+"wiki where query=(?)",(inp.lower(),)).fetchone() if ((not dburl==None) and (not dbtime==None)): (dburl,) = dburl (dbtime,) = dbtime if ((dbtime==timemon) and (dburl==inp.lower())): return dbresponse(inp,requesturl,db_global,wikiname).encode("utf8") else: url = http.get_json(requesturl)["query"] return apiget(inp,url,requesturl,timemon,db_global,wiki,wikiname,wikiurl,wikilen).encode("utf8")
def sieve_suite(bot, input, func, kind, args): inuserhost = input.user+'@'+input.host if perm.isignored(input) and not (perm.isvoiced(input)): if not (input.paraml[0].startswith("\x01ACTION ")): return None else: return input if perm.isbot(input): if not (input.paraml[0].startswith("\x01ACTION ")): return None else: return input if (input.chan in input.conn.conf["ignore"]) and not (perm.isvoiced(input)): if not (input.paraml[0].startswith("\x01ACTION ")): return None else: return input ignored = input.conn.conf['ignore'] if kind == "command": if "^" in input.paraml[1]: input.inp = input.inp.replace("^",bot.chanseen[input.conn.name][input.chan][0]) input.paraml[1] = input.paraml[1].replace("^",bot.chanseen[input.conn.name][input.chan][0]) if input.trigger in bot.config["disabled_commands"]: return None connitem = input.conn for xconn in bot.conns: if connitem==bot.conns[xconn]: server=bot.conns[xconn].name if input.nick in bot.cooldown[str(server)]: bot.cooldown[str(server)][input.nick]+=1 return None if input.paraml[0].startswith("\x01PING "): input.conn.send("NOTICE "+input.nick+" :"+input.inp[1]) fn = re.match(r'^plugins.(.+).py$', func._filename) disabled = bot.config.get('disabled_plugins', []) if fn and fn.group(1).lower() in disabled: return None acl = bot.config.get('acls', {}).get(func.__name__) if acl: if 'deny-except' in acl: allowed_channels = map(unicode.lower, acl['deny-except']) if input.chan.lower() not in allowed_channels: return None if 'allow-except' in acl: denied_channels = map(unicode.lower, acl['allow-except']) if input.chan.lower() in denied_channels: return None #the extended permissions were moved here. if args.get('adminonly', False): if not perm.isadmin(input): return None if args.get('superadminonly', False): if not perm.issuperadmin(input): return None if args.get('owneronly', False): if not perm.isowner(input): return None #extended permissions end here. return input
def permissions(inp, input=None, bot=None): "adds or removes permissions... use ,permissions help" check = input.inp.split(" ") cmdlist = ["add","remove","list","help"] if len(check)>=1: check[0]=check[0].lower() if len(check)>=2: check[1]=check[1].lower() if len(check)==0: return("Try using ',perm help' before stuffing around with" " this command.") if check[0] in cmdlist: if check[0]=="list" and len(check)==2: listlist=["bots","voice","admins","superadmins","owner"] if check[1]=="bots": return listbots(bot,input) if check[1]=="voiced": return listvoiced(bot,input) if check[1]=="admins": return listadmins(bot,input) if check[1]=="superadmins": return listsuperadmins(bot,input) if check[1]=="owner": return listowner(bot,input) elif not (check[1] in listlist): return("error. unknown error or not a permissions group.") if len(check)==3: check[1]=check[1].lower() if perm.isadmin(input): if check[0]=="add" and check[1]=="bot" and input.conn.conf["bots"].count(check[2])==0: return addperm(check[2],bot,input,"bot") if check[0]=="remove" and check[1]=="bot" and input.conn.conf["bots"].count(check[2])==1: return removeperm(check[2],bot,input,"bots") if check[0]=="add" and check[1]=="voice" and input.conn.conf["voiced"].count(check[2])==0: return addperm(check[2],bot,input,"voice") if check[0]=="remove" and check[1]=="voice" and input.conn.conf["voiced"].count(check[2])==1: return removeperm(check[2],bot,input,"voiced") else: if check[1]=="bot" and check[0]=="add": return("error. unknown error or already a "+check[1]) if check[1]=="bot" and check[0]=="remove": return("error. unknown error or not a "+check[1]) if perm.issuperadmin(input): if check[0]=="add": if check[1]=="admin" and input.conn.conf["admins"].count(check[2])==0: return addperm(check[2],bot,input,"admin") if check[1]=="voice" and input.conn.conf["voiced"].count(check[2])==0: return addperm(check[2],bot,input,"voice") if check[1]=="bot" and input.conn.conf["bots"].count(check[2])==0: return addperm(check[2],bot,input,"bot") elif (check[1]=="bot" or check[1]=="admin" or check[1]=="voiced"): return("error. unknown error or already a "+check[1]) if check[0]=="remove": if check[1]=="admin" and input.conn.conf["admins"].count(check[2])==1: return removeperm(check[2],bot,input,"admins") if check[1]=="voice" and input.conn.conf["voiced"].count(check[2])==1: return removeperm(check[2],bot,input,"voiced") if check[1]=="bot" and input.conn.conf["bots"].count(check[2])==1: return removeperm(check[2],bot,input,"bots") elif (check[1]=="bot" or check[1]=="admin"): return("error. unknown error or not a "+check[1]) if perm.isowner(input): if check[0]=="add": if check[1]=="admin" and input.conn.conf["admins"].count(check[2])==0: return addperm(check[2], bot, input,"admin") if check[1]=="voice" and input.conn.conf["voiced"].count(check[2])==0: return addperm(check[2], bot, input,"voice") if check[1]=="superadmin" and input.conn.conf["superadmins"].count(check[2])==0: return addperm(check[2], bot, input,"superadmin") if check[1]=="bot" and input.conn.conf["bots"].count(check[2])==0: return addperm(check[2],bot,input,"bot") elif (check[1]=="bot" or check[1]=="admin" or check[1]=="superadmin"): return("error. unknown error or already a "+check[1]) if check[0]=="remove" and perm.isowner(input): if check[1]=="admin" and input.conn.conf["admins"].count(check[2])==1: return removeperm(check[2],bot,input,"admins") if check[1]=="voice" and input.conn.conf["voiced"].count(check[2])==1: return removeperm(check[2],bot,input,"voiced") if check[1]=="superadmin" and input.conn.conf["superadmins"].count(check[2])==1: return removeperm(check[2],bot,input,"superadmins") if check[1]=="bot" and input.conn.conf["bots"].count(check[2])==1: return removeperm(check[2],bot,input,"bots") elif (check[1]=="bot" or check[1]=="admin" or check[1]=="superadmin"): return ("error. unknown error or not a "+check[1]) elif not perm.isadmin(input): return("You are not an admin or not high enough in " "this bot's permission's system to do this.") if check[0]=="help": return errorMsg elif not ((check[0]=="list" and len(check)==2) or (len(check)==3)): return errorMsg elif not check[0] in cmdlist: return errorMsg
def joins(paraml, conn=None, input=None, bot=None): repchan = input.conn.conf["reportchan"] if not perm.isowner(input) and not perm.isignored(input) and not perm.isbot(input) and input.nick==conn.nick: input.conn.send("PRIVMSG "+repchan+" :I have joined "+paraml[-1])
def backup(inp, input=None, conn=None): ",backup -- makes the bot automatically back up it's data base every 3 hours into the location set in the configs. bot owner only." if perm.isowner(input): repnick=input.nick testss = True list = dircache.listdir(input.bot.persist_dir) while testss: if not ftplock.acquire(): raise Exception("Problem acquiring ftplock, probable thread crash. Abort.") try: testss = False filedir = '' ftp_pw = ''.join(input.conn.conf["ftp_pw"]) if ftp_pw: if ftp_pw in input.bot.config['censored_strings']: input.bot.config['censored_strings'].remove(ftp_pw) x=-1 list2=[] for file in list: if str(file).endswith(".db"): x=x+1 list2.append(str(file)) ftp_host = ''.join(input.conn.conf["ftp_host"]) ftp_user = ''.join(input.conn.conf["ftp_user"]) ftp_port = input.conn.conf["ftp_port"] now = datetime.datetime.now() day = now.strftime("%Y%m%d_%H") ftp = ftplib.FTP() ftp.connect(ftp_host,ftp_port) ftp.login(ftp_user, ftp_pw) ftp.cwd(''.join(input.conn.conf["ftp_dir"])) print(ftp.dir()) dirlists=str(ftp.dir()) print(unicode(dirlists)) if dirlists==None: dirlists="nothing." if day in dirlists: ftp.rmd(day) ftp.mkd(day+"_2") if day not in dirlists: ftp.mkd(day) ftp.cwd(day) for file in list2: file_bu = open(str(input.bot.persist_dir)+"/"+str(file) ,'rb') ftp.storbinary('STOR '+str(file).replace(".db","")+".."+ day +'..db' , file_bu) file_bu.close() ftp.quit() input.bot.config['censored_strings'].append(ftp_pw) input.conn.send("PRIVMSG "+repnick+" done.") input.conn.send("PRIVMSG "+repnick+" :waiting for "+str(3)+" hours before backing up again!") time.sleep(2) time.sleep(3600*3) input.conn.send("PRIVMSG "+repnick+" :waiting done.") input.conn.send("PRIVMSG "+repnick+" :doing another backup.") testss = True except: raise finally: ftplock.release() if not perm.isowner(input): input.conn.send("PRIVMSG "+input.nick+" Nope.avi") input.conn.send("PRIVMSG "+repnick+" :"+input.nick+" tried to use the auto backup command.")
def invite(paraml, conn=None, input=None, bot=None): repchan = input.conn.conf["reportchan"] nickf = munge.munge(0, input, bot, 0, "") if not perm.isowner(input) and not perm.isignored(input) and not perm.isbot(input): input.conn.send("PRIVMSG "+repchan+" :I have been invited to "+paraml[-1]+" by "+nickf)
def authenticate(inp, input=None, db_global=None, bot=None, conn=None): "authenticate with this bot. NOTE: no password is stored in plain text. all passwords are stored as a sha512 hash. usage: ,auth login <username> <password>" db_global.execute("create table if not exists auth(user, pass, groups)") db_global.commit() check=input.inp.split(' ') #print(check) if len(check)==1 and check[0]=="help": out="To register with "+conn.nick+" please use ,auth <signup/reg> <username-you-want> <password-you-want>" out=out+". To login with "+conn.nick+" please use ,auth login <username-you-set> <password-you-set>" out=out+". If you forgot your password please contact "+conn.conf["owner"]+" about it." out=out+". For bot owners to change a user's group use ,auth groupset <username-of-person> <admin/superadmin/owner>" return(out) if len(check)==2 and check[0]=="logout": groupcheck=''.join(str(db_global.execute("select groups from auth where user=(?)",(check[1],)).fetchone()[0])) if input.nick in bot.auth[str(conn.name)][groupcheck]: del bot.auth[str(conn.name)][groupcheck][str(input.nick)] return "Bye!" if len(check)>=3: cmdlist=["login",'groupset','set','reset'] if check[0] in cmdlist: usercheck=''.join(str(db_global.execute("select user from auth where user=(?)",(check[1],)).fetchone()[0])) passcheck=''.join(str(db_global.execute("select pass from auth where user=(?)",(check[1],)).fetchone()[0])) groupcheck=''.join(str(db_global.execute("select groups from auth where user=(?)",(check[1],)).fetchone()[0])) #print(usercheck+"\n"+passcheck+'\n'+groupcheck) if check[0]=='reg' or check[0]=='signup': usercheck=''.join(str(db_global.execute("select user from auth where user=(?)",(check[1],)).fetchone())) passcheck=''.join(str(db_global.execute("select pass from auth where user=(?)",(check[1],)).fetchone())) groupcheck=''.join(str(db_global.execute("select groups from auth where user=(?)",(check[1],)).fetchone())) check[2]=hashlib.sha512(check[2]).hexdigest() if check[1]==str(usercheck): return("you are already registered on this bot or choose another name.") else: db_global.execute("insert into auth(user, pass, groups) values (?,?,?)",(check[1], check[2],"none")) db_global.commit() perm.repamsg(input,input.nick+" is registering with me.") return("done. please login by using ,auth login "+check[1]+" <password-here>.") if check[0]=="login": print(input.nick+" is trying to auth as "+check[1]) hashcheck=hashlib.sha512(check[2]).hexdigest() if usercheck==check[1] and passcheck==hashcheck: print(groupcheck)#if groupcheck==None bot.auth[str(conn.name)][groupcheck][str(input.nick)]={} return("welcome back "+check[1]+" have a nice time.") else: return("incorrect password or username. please try again.") if perm.isowner(input) and check[0]=='groupset': if check[2] in ["voiced","admin","superadmin","owner"] and usercheck==check[1] and check[2] in ["admin","superadmin","owner"]: db_global.execute("delete from auth where user=(?)", (check[1],)).rowcount db_global.execute("insert or replace into auth(user, pass, groups) values (?,?,?)",(check[1], passcheck,check[2])) db_global.commit() del bot.auth[str(conn.name)][groupcheck][str(input.nick)] bot.auth[str(conn.name)][check[2]][str(input.nick)]={} return("done. group set to "+check[2]) else: return("user not found or group not found.") if perm.isowner(input) and check[0]=='set' and usercheck==check[1] and check[2]: if usercheck==check[1]: db_global.execute("delete from auth where user=(?)", (check[1],)).rowcount db_global.execute("insert or replace into auth(user, pass, groups) values (?,?,?)",(check[1], hashlib.sha512(check[2]).hexdigest(),groupcheck)) db_global.commit() return("done. reset password.") else: return("user not found.") if check[0]=='reset' and usercheck==check[1] and passcheck==hashlib.sha512(check[2]).hexdigest() and check[3]: db_global.execute("delete from auth where user=(?)", (check[1],)).rowcount db_global.execute("insert or replace into auth(user, pass, groups) values (?,?,?)",(check[1], hashlib.sha512(check[3]).hexdigest(),groupcheck)) db_global.commit() return("done. reset you password.") else: return("error. try ,auth help")
def raw(inp, input=None): "sends a raw irc command. bot owner only..." if perm.isowner(input): input.conn.send(inp) else: input.conn.send("PRIVMSG %s :You cannot do this." % (input.nick))