def action(self, complete): msg = complete.message() if isAllowed(complete.userMask()) >= getLevel(complete.cmd()[0]): trigger = msg.split()[0] command = ' '.join(msg.split()[1:]) try: if trigger not in [ x[0] for x in settingsHandler.readSettingRaw( "'core-expansions'", "trigger") ]: settingsHandler.writeSetting("'core-expansions'", ["trigger", "command"], [trigger, command]) else: settingsHandler.updateSetting("'core-expansions'", "command", command, where="trigger='%s'" % trigger) msg = "%s will now substitute to the output of %s" % (trigger, command) except Exception as detail: msg = "Failure: %s" % detail else: msg = "Sorry, you need to be elevated to use this command!" return ["PRIVMSG $C$ :" + msg]
def save_alias( name ): #Saves alias to a file, to stick around between sessions. Returns 1 for complete, 0 for the plugin not existing in the current instnace, and 2 if it fails for some reason. if name in globalv.loadedAliases.keys( ): #To check if the alias is in the current instance (IE, it actually works) isIn = 0 for plugin in [ plugin[0] for plugin in settingsHandler.readSetting( "alias", "aliasName") ]: if name == plugin: isIn = 1 plugin = globalv.loadedAliases[name].split()[0] arguments = ' '.join(globalv.loadedAliases[name].split()[1:]) if not isIn: settingsHandler.writeSetting( "alias", ['aliasName', 'aliasPlugin', 'aliasArguments'], [name, plugin, arguments]) else: settingsHandler.updateSetting("alias", "aliasPlugin", plugin, "aliasName='" + name + "'") settingsHandler.updateSetting("alias", "aliasArguments", arguments, "aliasName='" + name + "'") return 1 else: return 0
def action(self, complete): msg=complete.message() plugins=settingsHandler.readSetting("'core-userlevels'","plugin,level") returner=[] output=[] if msg=="": for plugin, level in plugins: if int(level)>0: returner.append(':'.join((plugin,level))) out=', '.join(returner) output.append("PRIVMSG $C$ :"+out) output.append("PRIVMSG $C$ :All other functions do not require elevation") elif msg.split()[0]=="-list": if len(msg.split())==1: for plugin, level in plugins: returner.append(':'.join((plugin,level))) out=', '.join(returner) output.append("PRIVMSG $C$:"+out) else: yes=[] no=[] if msg.split()[1].isdigit(): userlevel=int(msg.split()[1]) else: userlevel=settingsHandler.readSetting("autoidentifyd","level",where="nickname='%s'"%msg.split()[1]) if userlevel==[]: userlevel="0" userlevel=int(userlevel) for plugin, level in plugins: if len(msg.split())!=2 or int(level)>0: if int(level)>userlevel: no.append(plugin) else: yes.append(plugin) output.append("PRIVMSG $C$ :Can use: "+', '.join(yes)) output.append("PRIVMSG $C$ :Can not use: "+', '.join(no)) if userlevel>=100: output.append("PRIVMSG $C$ :Can not be ignored.") elif userlevel>=20: output.append("PRIVMSG $C$ :Channelwide ignores will not take effect.") else: output.append("PRIVMSG $C$ :All ignores take effect") elif msg.split()[0] in globalv.loadedPlugins.keys(): if len(msg.split())==1: for plugin, level in plugins: if plugin.lower()==msg.split()[0].lower(): output.append("PRIVMSG $C$ :"+plugin+":"+level) elif msg.split()[1].isdigit(): settingsHandler.updateSetting("'core-userlevels'","level", msg.split()[1], where="plugin='%s'"%msg.split()[0]) output.append("PRIVMSG $C$ :Altered access requirements for that plugin") elif msg.split()[1] in globalv.loadedPlugins.keys(): for plugin, level in plugins: if plugin.lower()==msg.split()[1].lower(): newLevel=level break settingsHandler.updateSetting("'core-userlevels'","level", newLevel, where="plugin='%s'"%msg.split()[0]) output.append("PRIVMSG $C$ :Equalised plugin requirements") return output
def action(self, complete): msg=complete.message() command=msg.split()[0] if command=="list": names=settingsHandler.readSettingRaw("laterd","recipient, sender, timestamp", where="sent='0' AND anonymous='0'") returns=[] for name in names: try: recipient=name[0] sender=name[1] timestamp=name[2] ctime=time.strftime("%H:%M on %d-%m-%Y",time.gmtime(int(timestamp))) message=recipient+" has a message from "+sender+" (Sent on "+ctime+")" returns.append(message) except: pass if returns==[]: returns.append("No messages.") return ["PRIVMSG $C$ :"+', '.join(returns)] elif command=="remove": try: senderString=" and sender=='%s'"%complete.user() if isAllowed(complete.userMask())>=150: senderString="" where = "recipient=%s and sent='0'" % repr(msg.split()[1].lower()) where += senderString print where settingsHandler.updateSetting("laterd","sent", "'2'", where=where) return ["PRIVMSG $C$ :Later successfully removed!"] except Exception as detail: return ["PRIVMSG $C$ :Later not removed"] else: anonymous = "0" secret_pfx = "secret::" if msg.startswith(secret_pfx): anonymous = "1" msg = msg[len(secret_pfx):] channels=[] while msg.split()[0][0]=="#": channels.append(msg.split()[0]) msg=' '.join(msg.split()[1:]) channel='|'.join(channels) recipients=list(set(msg.split()[0].lower().split(','))) recipients = [re.sub('[^0-9a-z-[\]*?]', '?', x) for x in recipients] sender=complete.user() senderMask=complete.userMask() timestamp=str(int(time.time())) message=' '.join(msg.split()[1:]) message = message.replace('$U$','$recipient$') for recipient in recipients: print recipient id=str(int(settingsHandler.readSetting("laterd", "COUNT(id)"))+1) settingsHandler.writeSetting("laterd",["id", "recipient","sender","senderMask","timestamp","message", "channel", "anonymous", "sent"],[id, recipient, sender, senderMask, timestamp, message, channel, anonymous, "0"]) settingsHandler.db.commit() return ["PRIVMSG $C$ :Ok, I'll tell "+', '.join(recipients[:-1])+(" and "+recipients[-1] if len(recipients)>1 else recipients[-1])+" that when they next speak!"] return ["PRIVMSG $C$ :"+msg]
def action(self, complete): msg=complete.message() mode=plugin=setting=set=where="" mode=msg.split()[0] returns="No such mode '%s'" % mode plugin=msg.split()[1] try: setting=msg.split()[2] except: setting="" try: set=' '.join(msg.split()[3:]) except: set="" if len(set.split())<3: where = '1==1' elif set.split()[-2].lower()=="where": where=set.split()[-1] set=' '.join(set.split()[:-2]) else: where="1==1" if isAllowed(complete.userMask())>=getLevel(complete.cmd()[0]): if mode=="update": settingsHandler.updateSetting(plugin, setting, set, where=where) returns="Setting updated, sir!" if mode=="delete": settingsHandler.deleteSetting(plugin, setting, set) returns="Setting removed, my lord!" if mode=="add": setting=setting.split('||') set=set.split('||') settingsHandler.writeSetting(plugin, setting, set) returns="Setting Set, Cap'n!" if mode=="drop-table": settingsHandler.dropTable(plugin) returns="Settings lost, comrade!" if mode=="list": columns=settingsHandler.readColumns(plugin) returns=', '.join(columns) if mode=="current": results=settingsHandler.readSetting(plugin, setting) results=[str(x[0]) if len(x)==1 and type(x)==tuple else x for x in results] if type(results)==list else str(results) results=', '.join(results) if type(results)==list else results returns=results if mode=="commit": settingsHandler.db.commit() returns="Committed!" if mode=="copy": settingsHandler.executeQuery("INSERT INTO '%s' SELECT * FROM '%s'"%(msg.split())) if mode=="query": results=settingsHandler.executeQuery(' '.join(msg.split()[1:])) if results!=[]: returns=str(results) else: returns="Sorry, you can't do this." return ["PRIVMSG $C$ :"+returns]
def action(self, complete): msg = complete.message() if msg.split()[0] == "-list": users = settingsHandler.readSetting("autoidentifyd", "nickname, level") out = [] for name, level in users: if len(msg.split()) == 1: out.append(name + ":" + str(level)) elif msg.split()[1].lower() == name.lower(): out.append(name + ":" + str(level)) msg = ', '.join(out) elif len(msg.split()) == 1: users = settingsHandler.readSetting("autoidentifyd", "nickname, level") for name, level in users: if name == msg: return ["PRIVMSG $C$ :%s" % (level)] return ["PRIVMSG $C$ :0"] elif isAllowed(complete.userMask()) >= getLevel(complete.cmd()[0]): nick = msg.split()[0] level = msg.split()[1] if nick not in globalv.miscVars[0]: return ["PRIVMSG $C$ :That user does not exist."] if nick in [ x[0] for x in settingsHandler.readSetting( "autoidentifyd", "nickname") ]: settingsHandler.updateSetting("autoidentifyd", "level", str(level), where="nickname='%s'" % nick) msg = "Level updated" else: settingsHandler.writeSetting("autoidentifyd", ["nickname", "level"], [nick, level]) msg = "User Elevated" user = '******' + globalv.miscVars[0][nick] globalv.miscVars[2] = filter(lambda (x, y): x != user, globalv.miscVars[2]) globalv.miscVars[2].append((user, level)) print globalv.miscVars[2] else: msg = "Only elevated users can do this!" return ["PRIVMSG $C$ :" + msg]
def save_alias(name): #Saves alias to a file, to stick around between sessions. Returns 1 for complete, 0 for the plugin not existing in the current instnace, and 2 if it fails for some reason. if name in globalv.loadedAliases.keys(): #To check if the alias is in the current instance (IE, it actually works) isIn=0 for plugin in [plugin[0] for plugin in settingsHandler.readSetting("alias","aliasName")]: if name==plugin: isIn=1 plugin=globalv.loadedAliases[name].split()[0] arguments=' '.join(globalv.loadedAliases[name].split()[1:]) if not isIn: settingsHandler.writeSetting("alias",['aliasName', 'aliasPlugin', 'aliasArguments'],[name, plugin, arguments]) else: settingsHandler.updateSetting("alias","aliasPlugin", plugin, "aliasName='"+name+"'") settingsHandler.updateSetting("alias","aliasArguments", arguments, "aliasName='"+name+"'") return 1 else: return 0
def action(self, complete): msg=complete.message() if isAllowed(complete.userMask())>=getLevel(complete.cmd()[0]): trigger=msg.split()[0] command=' '.join(msg.split()[1:]) try: if trigger not in [x[0] for x in settingsHandler.readSettingRaw("'core-expansions'","trigger")]: settingsHandler.writeSetting("'core-expansions'",["trigger","command"],[trigger,command]) else: settingsHandler.updateSetting("'core-expansions'","command",command,where="trigger='%s'"%trigger) msg="%s will now substitute to the output of %s"%(trigger, command) except Exception as detail: msg="Failure: %s"%detail else: msg="Sorry, you need to be elevated to use this command!" return ["PRIVMSG $C$ :"+msg]
def action(self, complete): msg=complete.message() if msg.split()[0]=="-list": users=settingsHandler.readSetting("autoidentifyd","nickname, level") out=[] for name,level in users: if len(msg.split())==1: out.append(name+":"+str(level)) elif msg.split()[1].lower()==name.lower(): out.append(name+":"+str(level)) msg=', '.join(out) elif len(msg.split())==1: users=settingsHandler.readSetting("autoidentifyd","nickname, level") for name,level in users: if name==msg: return ["PRIVMSG $C$ :%s"%(level)] return ["PRIVMSG $C$ :0"] elif isAllowed(complete.userMask())>=getLevel(complete.cmd()[0]): nick = msg.split()[0] level = msg.split()[1] if nick not in globalv.miscVars[0]: return ["PRIVMSG $C$ :That user does not exist."] if nick in [x[0] for x in settingsHandler.readSetting("autoidentifyd","nickname")]: settingsHandler.updateSetting("autoidentifyd","level",str(level), where="nickname='%s'"%nick) msg="Level updated" else: settingsHandler.writeSetting("autoidentifyd",["nickname","level"], [nick, level]) msg="User Elevated" user = '******' + globalv.miscVars[0][nick] globalv.miscVars[2] = filter(lambda (x,y): x != user, globalv.miscVars[2]) globalv.miscVars[2].append((user, level)) print globalv.miscVars[2] else: msg="Only elevated users can do this!" return ["PRIVMSG $C$ :"+msg]
if len(datum.split())>1: if datum.split()[1]==NickInUse: send("NICK SomebodyStole"+nickname+str(random.randint(0,50))) if datum.split()[1]==motdEnd: okToSend=True send("NICKSERV IDENTIFY "+password) for channel in globalv.channels: send("JOIN "+channel) if datum.split()[1]=="TOPIC": globalv.miscVars[4].update({datum.split()[2]:' '.join(datum.split()[1:]).split(':',1)[1:]}) #Update the channel:topic disctionary whenever we get a topic change message if datum.split()[1]=="332": globalv.miscVars[4].update({datum.split()[3]:' '.join(datum.split()[1:]).split(':',1)[1:]}) #There are two different types of topic change message. if datum.split()[1]==privmsg: complete=datum[1:].split(' :',1) #Parse into [data, message] format if complete[0].split()[0].split('!')[0] in globalv.miscVars[0].keys(): settingsHandler.updateSetting("'core-nickmasks'","hostmask",complete[0].split()[0].split('!')[1],where="nick='%s'"%complete[0].split()[0].split('!')[0]) else: nickInfo=complete[0].split()[0].split('!') settingsHandler.writeSetting("'core-nickmasks'",["nick","hostmask"],[nickInfo[0],nickInfo[1]]) stuff=datum.split()[0].split(':', 1)[1].split('!') globalv.miscVars[0].update({stuff[0]:stuff[1]}) if stuff[0] not in globalv.accessRights.keys(): globalv.accessRights[stuff[0]]=security.accessRight(stuff[0]) if len(complete)>1: if complete[1].startswith(globalv.commandCharacter): try: parse(datum) except Exception as detail: print "Base Plugin Exection Failure:",detail traceback.print_tb(sys.exc_info()[2]) elif datum.split()[1]==join:
def setMessageSent(id): print "Attempting to set complete" settingsHandler.updateSetting("laterd", "sent", "1", where="id='%s'"%id) print "Set complete!"
def action(self, complete): msg = complete.message() command = msg.split()[0] if command == "list": names = settingsHandler.readSettingRaw( "laterd", "recipient, sender, timestamp", where="sent='0' AND anonymous='0'") returns = [] for name in names: try: recipient = name[0] sender = name[1] timestamp = name[2] ctime = time.strftime("%H:%M on %d-%m-%Y", time.gmtime(int(timestamp))) message = recipient + " has a message from " + sender + " (Sent on " + ctime + ")" returns.append(message) except: pass if returns == []: returns.append("No messages.") return ["PRIVMSG $C$ :" + ', '.join(returns)] elif command == "remove": try: senderString = " and sender=='%s'" % complete.user() if isAllowed(complete.userMask()) >= 150: senderString = "" where = "recipient=%s and sent='0'" % repr( msg.split()[1].lower()) where += senderString print where settingsHandler.updateSetting("laterd", "sent", "'2'", where=where) return ["PRIVMSG $C$ :Later successfully removed!"] except Exception as detail: return ["PRIVMSG $C$ :Later not removed"] else: anonymous = "0" secret_pfx = "secret::" if msg.startswith(secret_pfx): anonymous = "1" msg = msg[len(secret_pfx):] channels = [] while msg.split()[0][0] == "#": channels.append(msg.split()[0]) msg = ' '.join(msg.split()[1:]) channel = '|'.join(channels) recipients = list(set(msg.split()[0].lower().split(','))) recipients = [ re.sub('[^0-9a-z-[\]*?]', '?', x) for x in recipients ] sender = complete.user() senderMask = complete.userMask() timestamp = str(int(time.time())) message = ' '.join(msg.split()[1:]) message = message.replace('$U$', '$recipient$') for recipient in recipients: print recipient id = str( int(settingsHandler.readSetting("laterd", "COUNT(id)")) + 1) settingsHandler.writeSetting("laterd", [ "id", "recipient", "sender", "senderMask", "timestamp", "message", "channel", "anonymous", "sent" ], [ id, recipient, sender, senderMask, timestamp, message, channel, anonymous, "0" ]) settingsHandler.db.commit() return [ "PRIVMSG $C$ :Ok, I'll tell " + ', '.join(recipients[:-1]) + (" and " + recipients[-1] if len(recipients) > 1 else recipients[-1]) + " that when they next speak!" ] return ["PRIVMSG $C$ :" + msg]
def action(self, complete): msg=complete.message().split() nick=complete.user() if self.userScores=={}: userScores=settingsHandler.readSetting("chohan","nick, points") print userScores if len(userScores)!=2 and type(userScores[1])!=unicode: for user, score, in userScores: self.userScores[user]=int(score) else: user, score=userScores self.userScores[user]=int(score) if msg[0].lower()=="guess": if self.total==0: return ["PRIVMSG $C$ :Nobody's rolled the dice, yet! Roll with roll!"] elif nick not in self.userGuesses.keys(): self.userGuesses[nick]=msg[1] else: return ["PRIVMSG $C$ :You have already guessed!"] msg="Today could be your lucky day! Putting 1/5th of your points into the pot for a total prize of " if nick in self.userScores.keys(): self.prize+=(self.userScores[nick]/5)+100 self.userScores[nick]-=self.userScores[nick]/5 msg+=str(self.prize) elif msg[0].lower()=="roll": if self.total==0: self.total=0 self.dice=[] for i in range(2): rtd=random.randint(1,6) self.total+=rtd self.dice.append(rtd) print i,rtd self.prize=100 msg="Dice rolled!" else: msg="Dice already rolled! Start guessing!" elif msg[0].lower()=="reveal": if self.total==0: return ["PRIVMSG $C$ :No game in progress!"] print "revealan" oddEven="odd!" if self.total % 2 !=0 else "even!" winners=[] msg=["PRIVMSG $C$ :The result is "+oddEven+" ("+str(self.dice[0])+"+"+str(self.dice[1])+")"] print "winnerappendan" for user in self.userGuesses.keys(): if self.userGuesses[user]==oddEven[:-1]: winners.append(user) if winners!=[]: prize=self.prize/len(winners) else: prize=0 print "winnerpointdistributan",winners for winner in winners: print winner if winner in self.userScores.keys(): self.userScores[winner]+=prize settingsHandler.updateSetting("chohan","points",self.userScores[winner],"nick='"+winner+"'") else: self.userScores[winner]=prize print "settanwritan" settingsHandler.writeSetting("chohan", ["nick", "points"], [winner,str(prize)]) print "settanwrittan" print "dbhandlan" if len(winners)>1: winners=', '.join(winners[:-1])+" and "+winners[-1] winString=["winners are "," each"] elif len(winners)==1: winners=winners[0] winString=["winner is ",""] else: winners="" winString=["",""] if winners!="": msg+=["PRIVMSG $C$ :The "+winString[0]+winners+", and they"+winString[1]+" win "+str(prize)+" points"] else: msg+=["PRIVMSG $C$ :Nobody wins!"] self.total=0 self.userGuesses={} return msg elif msg[0].lower()=="points": if len(msg)==1: return ["PRIVMSG $C$ :You have "+str(self.userScores[nick])+" points"] else: nick=msg[1] if nick in self.userScores.keys(): return ["PRIVMSG $C$ :"+nick+" has "+str(self.userScores[nick])+" points"] else: return ["PRIVMSG $C$ :"+nick+" has 0 points"] elif msg[0].lower()=="e-penis": if len(msg)==1: return ["PRIVMSG $C$ :8="+('='*(self.userScores[nick]/100))+'D'] else: nick=msg[1] if nick in self.userScores.keys(): return ["PRIVMSG $C$ :8="+('='*(self.userScores[nick]/100))+'D'] else: return ["PRIVMSG $C$ :"+nick+" has 0 points"] elif msg[0].lower()=="scoreboard": num=3 if len(msg)==1 else int(msg[1]) scoreNames=[] for name in self.userScores.keys(): if self.userScores[name]>0: scoreNames.append((self.userScores[name],name)) scoreNames.sort(key=lambda scoreName:scoreName[0]) scoreNames.reverse() msg="The top "+str(num)+" users are: " for i in range(min(num,len(scoreNames))): msg+=scoreNames[i][1]+" with "+str(scoreNames[i][0])+" points" if i!=min(num,len(scoreNames))-1: msg+=", " else: msg+="!" elif msg[0].lower()=="donate": name=msg[1] amount=int(msg[2]) if complete.user() not in self.userScores.keys() or name not in self.userScores.keys(): msg="At least ONE of you don't have any points at all! Play a game of chohan first" elif self.userScores[complete.user()]>=amount and amount>0: self.userScores[name]+=amount self.userScores[complete.user()]-=amount settingsHandler.updateSetting("chohan","points",self.userScores[name],"nick='"+name+"'") settingsHandler.updateSetting("chohan","points",self.userScores[complete.user()],"nick='"+complete.user()+"'") msg="Donated points to "+name+", oh generous one!" elif amount<0: msg="Nice try!" elif self.userScores[complete.user()]<amount: msg="You don't have that much to give!" return ["PRIVMSG $C$ :"+msg]
def setMessageSent(id): print "Attempting to set complete" settingsHandler.updateSetting("laterd", "sent", "1", where="id='%s'" % id) print "Set complete!"
def action(self, complete): msg = complete.message().split() nick = complete.user() if self.userScores == {}: userScores = settingsHandler.readSetting("chohan", "nick, points") print userScores if len(userScores) != 2 and type(userScores[1]) != unicode: for user, score, in userScores: self.userScores[user] = int(score) else: user, score = userScores self.userScores[user] = int(score) if msg[0].lower() == "guess": if self.total == 0: return [ "PRIVMSG $C$ :Nobody's rolled the dice, yet! Roll with roll!" ] elif nick not in self.userGuesses.keys(): self.userGuesses[nick] = msg[1] else: return ["PRIVMSG $C$ :You have already guessed!"] msg = "Today could be your lucky day! Putting 1/5th of your points into the pot for a total prize of " if nick in self.userScores.keys(): self.prize += (self.userScores[nick] / 5) + 100 self.userScores[nick] -= self.userScores[nick] / 5 msg += str(self.prize) elif msg[0].lower() == "roll": if self.total == 0: self.total = 0 self.dice = [] for i in range(2): rtd = random.randint(1, 6) self.total += rtd self.dice.append(rtd) print i, rtd self.prize = 100 msg = "Dice rolled!" else: msg = "Dice already rolled! Start guessing!" elif msg[0].lower() == "reveal": if self.total == 0: return ["PRIVMSG $C$ :No game in progress!"] print "revealan" oddEven = "odd!" if self.total % 2 != 0 else "even!" winners = [] msg = [ "PRIVMSG $C$ :The result is " + oddEven + " (" + str(self.dice[0]) + "+" + str(self.dice[1]) + ")" ] print "winnerappendan" for user in self.userGuesses.keys(): if self.userGuesses[user] == oddEven[:-1]: winners.append(user) if winners != []: prize = self.prize / len(winners) else: prize = 0 print "winnerpointdistributan", winners for winner in winners: print winner if winner in self.userScores.keys(): self.userScores[winner] += prize settingsHandler.updateSetting("chohan", "points", self.userScores[winner], "nick='" + winner + "'") else: self.userScores[winner] = prize print "settanwritan" settingsHandler.writeSetting("chohan", ["nick", "points"], [winner, str(prize)]) print "settanwrittan" print "dbhandlan" if len(winners) > 1: winners = ', '.join(winners[:-1]) + " and " + winners[-1] winString = ["winners are ", " each"] elif len(winners) == 1: winners = winners[0] winString = ["winner is ", ""] else: winners = "" winString = ["", ""] if winners != "": msg += [ "PRIVMSG $C$ :The " + winString[0] + winners + ", and they" + winString[1] + " win " + str(prize) + " points" ] else: msg += ["PRIVMSG $C$ :Nobody wins!"] self.total = 0 self.userGuesses = {} return msg elif msg[0].lower() == "points": if len(msg) == 1: return [ "PRIVMSG $C$ :You have " + str(self.userScores[nick]) + " points" ] else: nick = msg[1] if nick in self.userScores.keys(): return [ "PRIVMSG $C$ :" + nick + " has " + str(self.userScores[nick]) + " points" ] else: return ["PRIVMSG $C$ :" + nick + " has 0 points"] elif msg[0].lower() == "e-penis": if len(msg) == 1: return [ "PRIVMSG $C$ :8=" + ('=' * (self.userScores[nick] / 100)) + 'D' ] else: nick = msg[1] if nick in self.userScores.keys(): return [ "PRIVMSG $C$ :8=" + ('=' * (self.userScores[nick] / 100)) + 'D' ] else: return ["PRIVMSG $C$ :" + nick + " has 0 points"] elif msg[0].lower() == "scoreboard": num = 3 if len(msg) == 1 else int(msg[1]) scoreNames = [] for name in self.userScores.keys(): if self.userScores[name] > 0: scoreNames.append((self.userScores[name], name)) scoreNames.sort(key=lambda scoreName: scoreName[0]) scoreNames.reverse() msg = "The top " + str(num) + " users are: " for i in range(min(num, len(scoreNames))): msg += scoreNames[i][1] + " with " + str( scoreNames[i][0]) + " points" if i != min(num, len(scoreNames)) - 1: msg += ", " else: msg += "!" elif msg[0].lower() == "donate": name = msg[1] amount = int(msg[2]) if complete.user() not in self.userScores.keys( ) or name not in self.userScores.keys(): msg = "At least ONE of you don't have any points at all! Play a game of chohan first" elif self.userScores[complete.user()] >= amount and amount > 0: self.userScores[name] += amount self.userScores[complete.user()] -= amount settingsHandler.updateSetting("chohan", "points", self.userScores[name], "nick='" + name + "'") settingsHandler.updateSetting("chohan", "points", self.userScores[complete.user()], "nick='" + complete.user() + "'") msg = "Donated points to " + name + ", oh generous one!" elif amount < 0: msg = "Nice try!" elif self.userScores[complete.user()] < amount: msg = "You don't have that much to give!" return ["PRIVMSG $C$ :" + msg]
def action(self, complete): msg = complete.message() plugins = settingsHandler.readSetting("'core-userlevels'", "plugin,level") returner = [] output = [] if msg == "": for plugin, level in plugins: if int(level) > 0: returner.append(':'.join((plugin, level))) out = ', '.join(returner) output.append("PRIVMSG $C$ :" + out) output.append( "PRIVMSG $C$ :All other functions do not require elevation") elif msg.split()[0] == "-list": if len(msg.split()) == 1: for plugin, level in plugins: returner.append(':'.join((plugin, level))) out = ', '.join(returner) output.append("PRIVMSG $C$:" + out) else: yes = [] no = [] if msg.split()[1].isdigit(): userlevel = int(msg.split()[1]) else: userlevel = settingsHandler.readSetting( "autoidentifyd", "level", where="nickname='%s'" % msg.split()[1]) if userlevel == []: userlevel = "0" userlevel = int(userlevel) for plugin, level in plugins: if len(msg.split()) != 2 or int(level) > 0: if int(level) > userlevel: no.append(plugin) else: yes.append(plugin) output.append("PRIVMSG $C$ :Can use: " + ', '.join(yes)) output.append("PRIVMSG $C$ :Can not use: " + ', '.join(no)) if userlevel >= 100: output.append("PRIVMSG $C$ :Can not be ignored.") elif userlevel >= 20: output.append( "PRIVMSG $C$ :Channelwide ignores will not take effect." ) else: output.append("PRIVMSG $C$ :All ignores take effect") elif msg.split()[0] in globalv.loadedPlugins.keys(): if len(msg.split()) == 1: for plugin, level in plugins: if plugin.lower() == msg.split()[0].lower(): output.append("PRIVMSG $C$ :" + plugin + ":" + level) elif msg.split()[1].isdigit(): settingsHandler.updateSetting("'core-userlevels'", "level", msg.split()[1], where="plugin='%s'" % msg.split()[0]) output.append( "PRIVMSG $C$ :Altered access requirements for that plugin") elif msg.split()[1] in globalv.loadedPlugins.keys(): for plugin, level in plugins: if plugin.lower() == msg.split()[1].lower(): newLevel = level break settingsHandler.updateSetting("'core-userlevels'", "level", newLevel, where="plugin='%s'" % msg.split()[0]) output.append("PRIVMSG $C$ :Equalised plugin requirements") return output
def action(self, complete): msg = complete.message() if msg.split()[0] == "-auto": users = settingsHandler.readSetting("autoidentifyd", "nickname, level") out = [] for name, level in users: if len(msg.split()) == 1: out.append(name + ":" + str(level)) elif msg.split()[1].lower() == name.lower(): out.append(name + ":" + str(level)) msg = ', '.join(out) elif msg.split()[0] == "-list": try: minimum = int(msg.split()[1]) pattern = '*' except: minimum = 0 try: pattern = '*' + msg.split()[1].lower() + '*' except: pattern = '*' out = [] for mask in globalv.miscVars[2]: if int(mask[1]) < minimum or not fnmatch.fnmatch( mask[0].lower(), pattern): continue out.append(mask[0] + ': ' + mask[1]) msg = ', '.join(out) elif len(msg.split()) == 1: users = settingsHandler.readSetting("autoidentifyd", "nickname, level") for name, level in users: if name == msg: return ["PRIVMSG $C$ :%s" % (level)] return ["PRIVMSG $C$ :0"] elif isAllowed(complete.userMask()) >= getLevel(complete.cmd()[0]): nick = msg.split()[0] level = msg.split()[1] try: level = int(level) except: if isinstance(level, str): level = unicode(level, 'utf-8', 'replace') if nick not in globalv.miscVars[0]: return ["PRIVMSG $C$ :That user does not exist."] if nick in [ x[0] for x in settingsHandler.readSetting( "autoidentifyd", "nickname") ]: settingsHandler.updateSetting("autoidentifyd", "level", level, where="nickname='%s'" % nick) msg = "Level updated" else: settingsHandler.writeSetting("autoidentifyd", ["nickname", "level"], [nick, level]) msg = "User Elevated" user = '******' + globalv.miscVars[0][nick] globalv.miscVars[2] = filter(lambda (x, y): x != user, globalv.miscVars[2]) globalv.miscVars[2].append((user, level)) print globalv.miscVars[2] else: msg = "Only elevated users can do this!" return ["PRIVMSG $C$ :" + msg]