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 rename_alias(name, newName): if (name not in globalv.loadedAliases.keys()): return False if (newName in globalv.loadedAliases.keys()): return False globalv.loadedPlugins[newName] = globalv.loadedPlugins[name] globalv.loadedAliases[newName] = globalv.loadedAliases[name] globalv.aliasExtensions[newName] = globalv.aliasExtensions[name] del globalv.loadedPlugins[name] del globalv.loadedAliases[name] del globalv.aliasExtensions[name] settingsHandler.executeQuery("UPDATE alias SET aliasName=\"%s\" WHERE aliasName=\"%s\""%(newName, name)) return True
def rename_alias(name, newName): if (name not in globalv.loadedAliases.keys()): return False if (newName in globalv.loadedAliases.keys()): return False globalv.loadedPlugins[newName] = globalv.loadedPlugins[name] globalv.loadedAliases[newName] = globalv.loadedAliases[name] globalv.aliasExtensions[newName] = globalv.aliasExtensions[name] del globalv.loadedPlugins[name] del globalv.loadedAliases[name] del globalv.aliasExtensions[name] settingsHandler.executeQuery( "UPDATE alias SET aliasName=\"%s\" WHERE aliasName=\"%s\"" % (newName, name)) return True
def getCrabFromDatabase(self, table, user): try: data=settingsHandler.executeQuery("SELECT name, XP, level, abilities FROM %s WHERE user='******'"%(table,user)) data=data[0] newCrab=crab(user, data[0][:50], data[1], data[2], data[3].rjust(len(self.abilities),"0"), self.abilities) return newCrab except Exception as detail: print detail return False
def action(self, complete): msg=complete.message() global crab if msg.split()[0]=="battle" or msg.split()[0]=="blowbyblow": events=[] if len(msg.split())==1: oneCrab=self.getCrabFromDatabase(complete.cmd()[0],complete.user()) newLevel=oneCrab.level+int(random.gauss(0,4)) if newLevel<=0: newLevel=1 if newLevel>100: newLevel=100 nameList=["Giant Enemy Crab", "Enemy Crab", "The Lord Of The Moon Seas", "God", "Hyper Crab", "Devil Crab", "Generic Enemy Crab", "Generic Angsty Teenage Crab","Hitler"] random.shuffle(nameList) newName=nameList[0] abilityString="1"*(1+int(newLevel/5)) abilityString=abilityString.rjust(len(self.abilities), "0") abilityString=list(abilityString) random.shuffle(abilityString) abilityString=''.join(abilityString) twoCrab=crab("-WorldSpace-", newName, oneCrab.XP, newLevel, abilityString, self.abilities) events.append("PRIVMSG $C$ :%s has come across the level %s %s!"%(oneCrab.name, twoCrab.level, twoCrab.name)) else: oneCrab=self.getCrabFromDatabase(complete.cmd()[0],complete.user()) twoCrab=self.getCrabFromDatabase(complete.cmd()[0],msg.split()[1]) if oneCrab==False: return ["PRIVMSG $C$ :You don't have a crab! Run !crab init [crab name] to get one!"] elif twoCrab==False: print "it's this" return ["PRIVMSG $C$ :%s doesn't have a crab! They can run !crab init [crab name] to get one!"%msg.split()[1]] turn=0 battleWon=False if oneCrab.level < twoCrab.level-5: events.append("PRIVMSG $C$ :%s gets an underdog bonus! Attack and Defence improved 20%%!"%oneCrab.name) oneCrab.attack*=1.2 oneCrab.defence*=1.2 if twoCrab.level < oneCrab.level-5: events.append("PRIVMSG $C$ :%s gets a jerk penalty! Attack and Defence drop 25%%!"%oneCrab.name) oneCrab.attack*=0.75 oneCrab.defence*=0.75 for i in range(30): if turn==0: events.append("PRIVMSG $C$ :"+oneCrab.attackCrab(twoCrab)) else: events[-1]+="; "+twoCrab.attackCrab(oneCrab) oneIsDead=oneCrab.isDead(twoCrab) twoIsDead=twoCrab.isDead(oneCrab) if oneIsDead[0]: winner=twoCrab loser=oneCrab battleWon=True if oneIsDead[1]!="": events.append("PRIVMSG $C$ :%s"%oneIsDead[1]) elif twoIsDead[0]: winner=oneCrab loser=twoCrab battleWon=True if twoIsDead[1]!="": events.append("PRIVMSG $C$ :%s"%twoIsDead[1]) if battleWon: break else: turn=(1 if turn==0 else 0) if msg.split()[0]=="battle": events=[] if battleWon: winnerXP=((loser.level+1)*(loser.level)*10)/((winner.level/5)+1) if loser.user!=winner.user: if winner.user!="-WorldSpace-": levelUp=winner.awardXP(winnerXP) else: levelUp=False events.append("PRIVMSG $C$ :%s won the battle, and is awarded %s XP!"%(winner.name, winnerXP)) else: levelUp=False events.append("PRIVMSG $C$ :%s won the battle, but gets no XP from fighting themself!"%(winner.name,)) if levelUp!=False: events.append("PRIVMSG $C$ :%s levelled up! %s is now level %s!"%(winner.name, winner.name, levelUp)) if int(levelUp/5)>winner.numAbilities-1: events.append("PRIVMSG $C$ :%s can now choose %s more abilities!"%(winner.name,1+int(levelUp/5)-winner.numAbilities)) if winner.user!="-WorldSpace-": winner.save(complete.cmd()[0]) else: events.append("PRIVMSG $C$ :Both crabs retreat to recover. There is no winner!") return events elif msg.split()[0]=="init": if len(msg.split())==1: return ["PRIVMSG $C$ :You need to give your new crab a name!"] name=' '.join(msg.split()[1:]) settingsHandler.executeQuery("INSERT INTO %s VALUES ('%s','%s',0,1,'%s')"%(complete.cmd()[0],complete.user(), name, "0"*len(self.abilities))) return ["PRIVMSG $C$ :%s successfully initialised! Type !crab list abilities to see all abilities, and !crab choose ability [name] to choose one!"%name] elif msg.split()[0]=="rename": newCrab=self.getCrabFromDatabase(complete.cmd()[0], complete.user()) newCrab.name=' '.join(msg.split()[1:]) newCrab.save(complete.cmd()[0]) elif msg.split()[0]=="stats" or msg.split()[0]=="info": returnString=[] if len(msg.split())==1: user=complete.user() else: user=msg.split()[1] newCrab=self.getCrabFromDatabase(complete.cmd()[0], user) if newCrab==False: return ["PRIVMSG $C$ :%s doesn't have a crab! Run !crab init [crab name] to get one"%user] returnString.append("PRIVMSG $C$ :%s's stats: %s HP, %s XP, Level %s, %s attack, %s defence, %s agility, %s%% crit rate. %s has %s free ability slot(s)."%(newCrab.name, newCrab.hp, newCrab.XP, newCrab.level, newCrab.attack, newCrab.defence, newCrab.agility,newCrab.critMultiplier*10,newCrab.name,1+int(newCrab.level/5)-newCrab.numAbilities)) ret=[] for ability in range(len(newCrab.abilities)): if newCrab.abilities[ability]=="1": for abilitylist in self.abilities: if abilitylist[0]==ability: ret.append(abilitylist[1]) returnString.append("PRIVMSG $C$ :Abilities are: "+', '.join(ret)) return returnString elif msg.split()[0]=="list": if msg.split()[1]=="abilities": returnString=", ".join([ability[1] for ability in self.abilities]) return ["PRIVMSG $C$ :"+returnString] elif msg.split()[0:2]==["choose","ability"]: targetAbility=' '.join(msg.split()[2:]) newCrab=self.getCrabFromDatabase(complete.cmd()[0], complete.user()) if int(newCrab.level/5)<=newCrab.numAbilities-1: return ["PRIVMSG $C$ :%s has no free ability slots!"%newCrab.name] ID=-1 for ability in self.abilities: if ability[1].lower()==targetAbility.lower(): abilityName=ability[1] ID=ability[0] if ID!=-1: newCrab.awardAbility(ID) newCrab.save(complete.cmd()[0]) return ["PRIVMSG $C$ :Awarded %s the ability '%s'"%(newCrab.name, abilityName)] else: return ["PRIVMSG $C$ :There is no ability by that name!"] elif msg.split()[0:2]==["remove","ability"]: targetAbility=' '.join(msg.split()[2:]) newCrab=self.getCrabFromDatabase(complete.cmd()[0], complete.user()) for ability in self.abilities: if ability[1].lower()==targetAbility.lower(): abilityName=ability[1] ID=ability[0] if newCrab.abilities[ID]=="0": return ["PRIVMSG $C$ :%s does not have that ability!"%newCrab.name] else: newCrab.removeAbility(ID) newCrab.save(complete.cmd()[0]) return ["PRIVMSG $C$ :Removed that ability"] elif msg.split()[0]=="resetAbilities": newCrab=self.getCrabFromDatabase(complete.cmd()[0], complete.user()) newCrab.abilities="0"*len(self.abilities) newCrab.save(complete.cmd()[0])
def save(self,table): settingsHandler.executeQuery("UPDATE %s SET name='%s', XP=%s, level=%s, abilities='%s' WHERE user='******'"%(table, self.name, self.XP, self.level, self.abilities,self.user))