Пример #1
0
 def action(self, complete):
     msg = complete.message()
     msgBack = []
     message = lambda x: msgBack.append("PRIVMSG $C$ :" + x)
     if isAllowed(complete.userMask()) >= getLevel(complete.cmd()[0]):
         if msg.split()[0] != "-remove":
             result = save_alias(msg)
             print globalv.loadedAliases.keys()
             if result == 1:
                 message("Alias Saved.")
             elif result == 2:
                 message("Alias unsuccessful. Alias is already set.")
             else:
                 message(
                     "Alias unsuccessful. Make sure you have previously !alias-ed this command"
                 )
                 print globalv.loadedAliases.keys()
         else:
             settingsHandler.deleteSetting("alias", "aliasName",
                                           msg.split()[1])
             message("Alias Removed")
     else:
         message(
             "Alias unsuccessful. This action requires higher priviledges. Use "
             + globalv.commandCharacter + "alias for temporary aliases.")
     return msgBack
Пример #2
0
 def action(self, complete):
     msg = complete.message()
     sender = complete.userMask()
     if len(msg.split()) > 1:
         mode = msg.split()[1].lower()
     else:
         mode = "on"
     msg = msg.split()[0]
     print sender
     print globalv.basePlugin
     if msg == "list":
         return [
             "PRIVMSG $C$ :" + ', '.join([
                 x[0] for x in settingsHandler.readSettingRaw(
                     "coreAutoLoad", "loadAs")
             ])
         ]
     if isAllowed(sender) >= getLevel(complete.cmd()[0]):
         if mode == "on":
             settingsHandler.writeSetting("coreAutoLoad",
                                          ["plugin", "loadAs"],
                                          [globalv.basePlugin[msg], msg])
             return ["PRIVMSG $C$ :Plugin set to autoload"]
         else:
             settingsHandler.deleteSetting("coreAutoLoad", "loadAs", msg)
             return ["PRIVMSG $C$ :Plugin no longer autoloading"]
     return ["PRIVMSG $C$ :You do not have the required access rights!"]
Пример #3
0
 def action(self, complete):
     msg=complete.message()
     isElevated=(isAllowed(complete.userMask())>=getLevel(complete.cmd()[0]))
     self.__init_answers__(complete)
     if len(msg.split())>=1:
         cmd=msg.split()[0]
         msg=' '.join(msg.split()[1:])
     else:
         cmd=""
         msg=""
     if cmd=="-add" and isElevated:
         settingsHandler.writeSetting("'"+complete.cmd()[0]+"'","answer",msg)
         toReturn="Added that answer"
         self.__init_answers__(complete)
     elif cmd=="-delete" and isElevated:
         settingsHandler.deleteSetting("'"+complete.cmd()[0]+"'","answer",msg)
         toReturn="Wiped that answer."
         self.__init_answers__(complete)
     elif cmd=="-wipe" and isElevated:
         settingsHandler.dropTable("'"+complete.cmd()[0]+"'")
         settingsHandler.newTable("'"+complete.cmd()[0]+"'","answer")
         toReturn="Answer table wiped!"
         self.__init_answers__(complete)
     elif cmd=="-dump":
         self.__init_answers__(complete)
         return ["PRIVMSG $C$ :[%s]"%', '.join(["'"+x+"'" for x in self.answers])]
     else:
         toReturn=self.answers.pop()
         if complete.message()=="":
             toReturn=toReturn.replace("$1$","$U$")
         else:
             toReturn=toReturn.replace("$1$",complete.message())
     return ["PRIVMSG $C$ :"+toReturn]
Пример #4
0
 def action(self, complete):
     msg=complete.message()
     amsg=msg
     if isAllowed(complete.userMask())<getLevel(complete.cmd()[0]):
         return ["PRIVMSG $C$ :No."]
     if msg=="*":
         #settingsHandler.deleteSetting("coreIgnorance","1","1")
         settingsHandler.dropTable("coreIgnorance")
         settingsHandler.newTable("coreIgnorance","ignorance","nickname")
         return ["PRIVMSG $C$ :Unignored everything, my lord"]
     if msg in globalv.miscVars[0]:
         msg=globalv.miscVars[0][msg]
     try:
         if amsg in [x[0] for x in settingsHandler.readSettingRaw("coreIgnorance","ignorance")]:
             settingsHandler.deleteSetting("coreIgnorance","ignorance",amsg)
             return ["PRIVMSG $C$ :"+amsg + " successfully unignored, cap'n!"]
         msg=".*@"+msg.split('@')[1] if msg.find('@')>0 else msg
         if msg in [x[0] for x in settingsHandler.readSettingRaw("coreIgnorance","ignorance")]:
             settingsHandler.deleteSetting("coreIgnorance","ignorance",msg)
             return ["PRIVMSG $C$ :"+amsg + " successfully unignored, cap'n!"]
         else:
             matches=difflib.get_close_matches(msg,[x[0] for x in settingsHandler.readSettingRaw("coreIgnorance","ignorance")],3,0.4)
             matches=["None"] if matches==[] else matches
             globalv.variables['ignored']=matches[0]
             return ["PRIVMSG $C$ :"+msg+" is not ignored, commander! Near matches: "+', '.join(matches)+". ~ignored~ set to nearest match."]
     except Exception as detail:
         return ["PRIVMSG $C$ :"+msg+" not unignored: "+str(detail)]
     return ["PRIVMSG $C$ :"+amsg + " successfully unignored, cap'n!"]
Пример #5
0
 def action(self, complete):
     msg = complete.message()
     returner = ""
     elevated = getLevel(complete.userMask()) >= isAllowed(
         complete.cmd()[0])
     if msg == "":
         returner = "This is the %s dictionary. Run !%s -list for a list of known values!" % (
             complete.cmd()[0], complete.cmd()[0])
     elif msg.split()[0] == "-add" and elevated:
         settingsHandler.writeSetting(
             complete.cmd()[0], ["key", "value"],
             [msg.split()[1], ' '.join(msg.split()[2:])])
         returner = "Key:Value pair added!"
     elif msg.split()[0] == "-delete" and elevated:
         settingsHandler.deleteSetting(complete.cmd()[0], "key",
                                       msg.split()[1])
         returner = "Key removed!"
     elif msg.split()[0] == "-list":
         keypairs = [
             x[0] for x in settingsHandler.readSettingRaw(
                 complete.cmd()[0], "key")
         ]
         returner = ', '.join(keypairs)
     elif msg.split()[0] == "-random":
         keypairs = settingsHandler.readSettingRaw(complete.cmd()[0],
                                                   "key, value")
         pairs = {}
         for keypair in keypairs:
             pairs[keypair[0].lower()] = keypair[1]
         import random
         keys = pairs.keys()
         random.shuffle(keys)
         returner = keys[0] + ": " + pairs[keys[0]]
     else:
         keypairs = settingsHandler.readSettingRaw(complete.cmd()[0],
                                                   "key, value")
         pairs = {}
         for keypair in keypairs:
             pairs[keypair[0].lower()] = keypair[1]
         if unicode(msg.split()[0]).lower() in pairs.keys():
             returner = pairs[unicode(msg.split()[0]).lower()]
         elif "default" not in pairs.keys():
             returner = "No definition."
             matches = difflib.get_close_matches(msg.split()[0],
                                                 pairs.keys(), 10, 0.1)
             if len(matches) > 0:
                 returner += " Perhaps you meant: " + ', '.join(
                     matches[:-1])
                 if len(matches) > 1:
                     returner += " or " + matches[-1]
             else:
                 returner += " No similar definitions"
         else:
             returner = pairs['default']
     if returner == "":
         return [""]
     return ["PRIVMSG $C$ :" + returner]
Пример #6
0
 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]
Пример #7
0
 def action(self, complete):
     name=complete.message()
     msg="There was an error in your input!"
     if isAllowed(complete.userMask())<getLevel(complete.cmd()[0]):
         return [""]
     if name.split()[0]=="list":
         return ["PRIVMSG $C$ :"+' '.join(globalv.loadedInputs.keys())]
     elif name.split()[0]=="clean":
         newDict={}
         for plugin in globalv.loadedInputs.keys():
             if globalv.loadedInputs[plugin].isSet()==False:
                 newDict[plugin]=globalv.loadedInputs[plugin]
         globalv.loadedInputs=newDict
         return ["PRIVMSG $C$ :ID list cleaned up manually"]
     elif name.split()[0]=="kickstart":
         globalv.input.startInputDaemons()
         return ["PRIVMSG $C$ :Kickstarted stalling plugins manually"]
     elif name.split()[0]=="reboot":
         definition=settingsHandler.readSetting("'core-input'","definition",where="input='%s'"%name.split()[1])
         print "def"
         x=__import__(str(definition.split()[0]))
         reload(x)
         arguments=str(' '.join(definition.split()[1:]))
         arguments=shlex.split(arguments)
         globalv.loadedInputs[name.split()[1]]=globalv.input.addInputSource(x.asyncInput,tuple(arguments))
         globalv.input.startInputDaemons()
         msg="Rebooting input plugin..."
     elif name.split()[0]=="add":
         name= ' '.join(name.split()[1:])
         try:
             if name.split()[0] in globalv.loadedInputs.keys():
                 raise Exception("An input module with that ID already exists!")
             x=__import__(name.split()[1])
             reload(x)
             arguments=shlex.split(' '.join(name.split()[2:]))
             globalv.loadedInputs[name.split()[0]]=globalv.input.addInputSource(x.asyncInput,tuple(arguments))
             print arguments
             settingsHandler.writeSetting("'core-input'", ["input", "definition"], [name.split()[0], ' '.join(name.split()[1:])])
             globalv.input.startInputDaemons()
             msg="Plugin loaded successfully!"
         except Exception as detail:
             msg="Load failure: "+str(detail)
     elif name.split()[0]=="send":
         plugin = name.split()[1]
         command = " ".join(name.split()[2:])
         globalv.loadedInputs[plugin].put(command)
         msg = "Sent message to plugin"
     elif name.split()[0]=="autosend":
         name= ' '.join(name.split()[1:])
         settingsHandler.writeSetting("'core-input'", ["input", "definition"], [name.split()[0], ' '.join(name.split()[1:])])
         msg = "Plugin configuration added"
     elif name.split()[0]=="unautosend":
         settingsHandler.deleteSetting("'core-input'", "definition", ' '.join(name.split()[1:]))
         msg="Configuration removed!"
     return ["PRIVMSG $C$ :"+msg]
Пример #8
0
 def action(self, complete):
     msg = complete.message()
     amsg = msg
     if isAllowed(complete.userMask()) < getLevel(complete.cmd()[0]):
         return ["PRIVMSG $C$ :No."]
     if msg == "*":
         #settingsHandler.deleteSetting("coreIgnorance","1","1")
         settingsHandler.dropTable("coreIgnorance")
         settingsHandler.newTable("coreIgnorance", "ignorance", "nickname")
         return ["PRIVMSG $C$ :Unignored everything, my lord"]
     if msg in globalv.miscVars[0]:
         msg = globalv.miscVars[0][msg]
     try:
         if amsg in [
                 x[0] for x in settingsHandler.readSettingRaw(
                     "coreIgnorance", "ignorance")
         ]:
             settingsHandler.deleteSetting("coreIgnorance", "ignorance",
                                           amsg)
             return [
                 "PRIVMSG $C$ :" + amsg + " successfully unignored, cap'n!"
             ]
         msg = ".*@" + msg.split('@')[1] if msg.find('@') > 0 else msg
         if msg in [
                 x[0] for x in settingsHandler.readSettingRaw(
                     "coreIgnorance", "ignorance")
         ]:
             settingsHandler.deleteSetting("coreIgnorance", "ignorance",
                                           msg)
             return [
                 "PRIVMSG $C$ :" + amsg + " successfully unignored, cap'n!"
             ]
         else:
             matches = difflib.get_close_matches(msg, [
                 x[0] for x in settingsHandler.readSettingRaw(
                     "coreIgnorance", "ignorance")
             ], 3, 0.4)
             matches = ["None"] if matches == [] else matches
             globalv.variables['ignored'] = matches[0]
             return [
                 "PRIVMSG $C$ :" + msg +
                 " is not ignored, commander! Near matches: " +
                 ', '.join(matches) + ". ~ignored~ set to nearest match."
             ]
     except Exception as detail:
         return ["PRIVMSG $C$ :" + msg + " not unignored: " + str(detail)]
     return ["PRIVMSG $C$ :" + amsg + " successfully unignored, cap'n!"]
Пример #9
0
 def action(self, complete):
     name = complete.message().split()[0]
     if len(complete.message().split()) > 1:
         noKill = 1
     else:
         noKill = 0
     msg = "Successfully asked the plugin to stop"
     if isAllowed(complete.userMask()) < getLevel(complete.cmd()[0]):
         return ["PRIVMSG $C$ :Only elevated users can do that!"]
     try:
         globalv.loadedInputs[name.split()[0]].put("stop")
         del globalv.loadedInputs[name.split()[0]]
         if not noKill:
             settingsHandler.deleteSetting("'core-input'", "input", name)
     except Exception as detail:
         msg = "Unload failure: " + str(detail)
     return ["PRIVMSG $C$ :" + msg]
Пример #10
0
 def action(self, complete):
     name=complete.message().split()[0]
     if len(complete.message().split())>1:
         noKill=1
     else:
         noKill=0
     msg="Successfully asked the plugin to stop"
     if isAllowed(complete.userMask())<getLevel(complete.cmd()[0]):
         return ["PRIVMSG $C$ :Only elevated users can do that!"]
     try:
         globalv.loadedInputs[name.split()[0]].put("stop")
         del globalv.loadedInputs[name.split()[0]]
         if not noKill:
             settingsHandler.deleteSetting("'core-input'","input",name)
     except Exception as detail:
         msg="Unload failure: "+str(detail)
     return ["PRIVMSG $C$ :"+msg]
Пример #11
0
 def action(self, complete):
     msg=complete.message()
     isElevated=(isAllowed(complete.userMask())>=getLevel(complete.cmd()[0]))
     self.__init_answers__(complete)
     hashDate = True
     hashUser = True
     if len(msg.split())>=1:
         cmd=msg.split()[0]
         msg=' '.join(msg.split()[1:])
         if "-date" in msg.split():
             hashUser = False
         if "-user" in msg.split():
             hashDate = False
     else:
         cmd=""
         msg=""
     if cmd=="-add" and isElevated:
         settingsHandler.writeSetting("'"+complete.cmd()[0]+"'","answer",msg)
         toReturn="Added that answer"
         self.__init_answers__(complete)
     elif cmd=="-delete" and isElevated:
         settingsHandler.deleteSetting("'"+complete.cmd()[0]+"'","answer",msg)
         toReturn="Wiped that answer."
         self.__init_answers__(complete)
     elif cmd=="-wipe" and isElevated:
         settingsHandler.dropTable("'"+complete.cmd()[0]+"'")
         settingsHandler.newTable("'"+complete.cmd()[0]+"'","answer")
         toReturn="Answer table wiped!"
         self.__init_answers__(complete)
     elif cmd=="-dump":
         self.__init_answers__(complete)
         return ["PRIVMSG $C$ :[%s]"%', '.join(["'"+x+"'" for x in self.answers])]
     else:
         totalHash = 0
         if hashDate:
             totalHash += hash(date.today())
         if hashUser:
             totalHash += hash(complete.user())
         answer = totalHash % len(self.answers)
         print answer, totalHash, self.answers
         toReturn=self.answers[answer]
         if complete.message()=="":
             toReturn=toReturn.replace("$1$","$U$")
         else:
             toReturn=toReturn.replace("$1$",complete.message())
     return ["PRIVMSG $C$ :"+toReturn]
Пример #12
0
 def action(self, complete):
     msg=complete.message()
     returner=""
     elevated = getLevel(complete.userMask()) >= isAllowed(complete.cmd()[0])
     if msg=="":
         returner="This is the %s dictionary. Run !%s -list for a list of known values!"%(complete.cmd()[0], complete.cmd()[0])
     elif msg.split()[0]=="-add" and elevated:
         settingsHandler.writeSetting(complete.cmd()[0],["key","value"], [msg.split()[1],' '.join(msg.split()[2:])])
         returner="Key:Value pair added!"
     elif msg.split()[0]=="-delete" and elevated:
         settingsHandler.deleteSetting(complete.cmd()[0],"key",msg.split()[1])
         returner="Key removed!"
     elif msg.split()[0]=="-list":
         keypairs=[x[0] for x in settingsHandler.readSettingRaw(complete.cmd()[0],"key")]
         returner=', '.join(keypairs)
     elif msg.split()[0]=="-random":
         keypairs=settingsHandler.readSettingRaw(complete.cmd()[0],"key, value")
         pairs={}
         for keypair in keypairs:
             pairs[keypair[0].lower()]=keypair[1]
         import random
         keys=pairs.keys()
         random.shuffle(keys)
         returner=keys[0]+": "+pairs[keys[0]]
     else:
         keypairs=settingsHandler.readSettingRaw(complete.cmd()[0],"key, value")
         pairs={}
         for keypair in keypairs:
             pairs[keypair[0].lower()]=keypair[1]
         if unicode(msg.split()[0]).lower() in pairs.keys():
             returner=pairs[unicode(msg.split()[0]).lower()]
         elif "default" not in pairs.keys():
             returner="No definition."
             matches=difflib.get_close_matches(msg.split()[0],pairs.keys(),10,0.1)
             if len(matches)>0:
                 returner+=" Perhaps you meant: "+', '.join(matches[:-1])
                 if len(matches)>1:
                     returner+=" or "+matches[-1]
             else:
                 returner+=" No similar definitions"
         else:
             returner=pairs['default']
     if returner=="":
         return [""]
     return ["PRIVMSG $C$ :"+returner]
Пример #13
0
 def action(self, complete):
     msg=complete.message()
     sender=complete.userMask()
     if len(msg.split())>1:
         mode=msg.split()[1].lower()
     else:
         mode="on"
     msg=msg.split()[0]
     print sender
     print globalv.basePlugin
     if msg=="list":
         return ["PRIVMSG $C$ :"+', '.join([x[0] for x in settingsHandler.readSettingRaw("coreAutoLoad", "loadAs")])]
     if isAllowed(sender)>=getLevel(complete.cmd()[0]):
         if mode=="on":
             settingsHandler.writeSetting("coreAutoLoad", ["plugin", "loadAs"], [globalv.basePlugin[msg], msg])
             return ["PRIVMSG $C$ :Plugin set to autoload"]
         else:
             settingsHandler.deleteSetting("coreAutoLoad", "loadAs", msg)
             return ["PRIVMSG $C$ :Plugin no longer autoloading"]
     return ["PRIVMSG $C$ :You do not have the required access rights!"]
Пример #14
0
    def action(self, complete):
        msg = complete.message()
        isElevated = (isAllowed(complete.userMask()) >= getLevel(
            complete.cmd()[0]))
        beRandom = True
        if len(self.answers) == 0:
            self.__init_answers__(complete, beRandom)
        if len(msg.split()) >= 1:
            cmd = msg.split()[0]
            msg = ' '.join(msg.split()[1:])
        else:
            cmd = ""
            msg = ""
        if cmd == "-add" and isElevated:
            settingsHandler.writeSetting("'" + complete.cmd()[0] + "'",
                                         "answer", msg)
            toReturn = "Added that answer"
            self.__init_answers__(complete, beRandom)
        elif cmd == "-delete" and isElevated:
            settingsHandler.deleteSetting("'" + complete.cmd()[0] + "'",
                                          "answer", msg)
            toReturn = "Wiped that answer."
            self.__init_answers__(complete, beRandom)
        elif cmd == "-wipe" and isElevated:
            settingsHandler.dropTable("'" + complete.cmd()[0] + "'")
            settingsHandler.newTable("'" + complete.cmd()[0] + "'", "answer")
            toReturn = "Answer table wiped!"
            self.__init_answers__(complete, beRandom)
        elif cmd == "-reset" and isElevated:
            self.__init_answers__(complete, beRandom)
            toReturn = "Re-randomising list..."
        else:
            toReturn = self.answers.pop()
            inputs = ":%s PRIVMSG %s :!%s" % (complete.userMask(),
                                              complete.channel(), toReturn)
            input = formatInput(pluginArguments(inputs))
            pluginOut = globalv.loadedPlugins[toReturn.split()[0]].action(
                input)
            return pluginOut

        return ["PRIVMSG $C$ :" + toReturn]
Пример #15
0
 def action(self, complete):
     msg=complete.message()
     msgBack=[]
     message=lambda x:msgBack.append("PRIVMSG $C$ :"+x)
     if isAllowed(complete.userMask())>=getLevel(complete.cmd()[0]):
         if msg.split()[0]!="-remove":
             result=save_alias(msg)
             print globalv.loadedAliases.keys()
             if result==1:
                 message("Alias Saved.")
             elif result==2:
                 message("Alias unsuccessful. Alias is already set.")
             else:
                 message("Alias unsuccessful. Make sure you have previously !alias-ed this command")
                 print globalv.loadedAliases.keys()
         else:
             settingsHandler.deleteSetting("alias","aliasName",msg.split()[1])
             message("Alias Removed")
     else:
         message("Alias unsuccessful. This action requires higher priviledges. Use "+globalv.commandCharacter+"alias for temporary aliases.")
     return msgBack
Пример #16
0
 def action(self, complete):
     msg = complete.message()
     isElevated = (isAllowed(complete.userMask()) >= getLevel(
         complete.cmd()[0]))
     self.__init_answers__(complete)
     if len(msg.split()) >= 1:
         cmd = msg.split()[0]
         msg = ' '.join(msg.split()[1:])
     else:
         cmd = ""
         msg = ""
     if cmd == "-add" and isElevated:
         settingsHandler.writeSetting("'" + complete.cmd()[0] + "'",
                                      "answer", msg)
         toReturn = "Added that answer"
         self.__init_answers__(complete)
     elif cmd == "-delete" and isElevated:
         settingsHandler.deleteSetting("'" + complete.cmd()[0] + "'",
                                       "answer", msg)
         toReturn = "Wiped that answer."
         self.__init_answers__(complete)
     elif cmd == "-wipe" and isElevated:
         settingsHandler.dropTable("'" + complete.cmd()[0] + "'")
         settingsHandler.newTable("'" + complete.cmd()[0] + "'", "answer")
         toReturn = "Answer table wiped!"
         self.__init_answers__(complete)
     elif cmd == "-dump":
         self.__init_answers__(complete)
         return [
             "PRIVMSG $C$ :[%s]" %
             ', '.join(["'" + x + "'" for x in self.answers])
         ]
     else:
         toReturn = self.answers.pop()
         if complete.message() == "":
             toReturn = toReturn.replace("$1$", "$U$")
         else:
             toReturn = toReturn.replace("$1$", complete.message())
     return ["PRIVMSG $C$ :" + toReturn]
Пример #17
0
    def action(self, complete):
        msg=complete.message()
        isElevated=(isAllowed(complete.userMask())>=getLevel(complete.cmd()[0]))
        beRandom=True
        if len(self.answers)==0:
            self.__init_answers__(complete,beRandom)
        if len(msg.split())>=1:
            cmd=msg.split()[0]
            msg=' '.join(msg.split()[1:])
        else:
            cmd=""
            msg=""
        if cmd=="-add" and isElevated:
            settingsHandler.writeSetting("'"+complete.cmd()[0]+"'","answer",msg)
            toReturn="Added that answer"
            self.__init_answers__(complete,beRandom)
        elif cmd=="-delete" and isElevated:
            settingsHandler.deleteSetting("'"+complete.cmd()[0]+"'","answer",msg)
            toReturn="Wiped that answer."
            self.__init_answers__(complete,beRandom)
        elif cmd=="-wipe" and isElevated:
            settingsHandler.dropTable("'"+complete.cmd()[0]+"'")
            settingsHandler.newTable("'"+complete.cmd()[0]+"'","answer")
            toReturn="Answer table wiped!"
            self.__init_answers__(complete,beRandom)
        elif cmd=="-reset" and isElevated:
            self.__init_answers__(complete,beRandom)
            toReturn="Re-randomising list..."
        else:
            toReturn=self.answers.pop()
            inputs=":%s PRIVMSG %s :!%s"%(complete.userMask(), complete.channel(), toReturn)
            input=formatInput(pluginArguments(inputs))
            pluginOut=globalv.loadedPlugins[toReturn.split()[0]].action(input)
            return pluginOut

        return ["PRIVMSG $C$ :"+toReturn]
Пример #18
0
 def action(self, complete):
     name = complete.message()
     msg = "There was an error in your input!"
     if isAllowed(complete.userMask()) < getLevel(complete.cmd()[0]):
         return [""]
     if name.split()[0] == "list":
         return ["PRIVMSG $C$ :" + ' '.join(globalv.loadedInputs.keys())]
     elif name.split()[0] == "clean":
         newDict = {}
         for plugin in globalv.loadedInputs.keys():
             if globalv.loadedInputs[plugin].isSet() == False:
                 newDict[plugin] = globalv.loadedInputs[plugin]
         globalv.loadedInputs = newDict
         return ["PRIVMSG $C$ :ID list cleaned up manually"]
     elif name.split()[0] == "kickstart":
         globalv.input.startInputDaemons()
         return ["PRIVMSG $C$ :Kickstarted stalling plugins manually"]
     elif name.split()[0] == "reboot":
         definition = settingsHandler.readSetting("'core-input'",
                                                  "definition",
                                                  where="input='%s'" %
                                                  name.split()[1])
         print "def"
         x = __import__(str(definition.split()[0]))
         reload(x)
         arguments = str(' '.join(definition.split()[1:]))
         arguments = shlex.split(arguments)
         globalv.loadedInputs[name.split()
                              [1]] = globalv.input.addInputSource(
                                  x.asyncInput, tuple(arguments))
         globalv.input.startInputDaemons()
         msg = "Rebooting input plugin..."
     elif name.split()[0] == "add":
         name = ' '.join(name.split()[1:])
         try:
             if name.split()[0] in globalv.loadedInputs.keys():
                 raise Exception(
                     "An input module with that ID already exists!")
             x = __import__(name.split()[1])
             reload(x)
             arguments = shlex.split(' '.join(name.split()[2:]))
             globalv.loadedInputs[name.split()
                                  [0]] = globalv.input.addInputSource(
                                      x.asyncInput, tuple(arguments))
             print arguments
             settingsHandler.writeSetting(
                 "'core-input'", ["input", "definition"],
                 [name.split()[0], ' '.join(name.split()[1:])])
             globalv.input.startInputDaemons()
             msg = "Plugin loaded successfully!"
         except Exception as detail:
             msg = "Load failure: " + str(detail)
     elif name.split()[0] == "send":
         plugin = name.split()[1]
         command = " ".join(name.split()[2:])
         globalv.loadedInputs[plugin].put(command)
         msg = "Sent message to plugin"
     elif name.split()[0] == "autosend":
         name = ' '.join(name.split()[1:])
         settingsHandler.writeSetting(
             "'core-input'", ["input", "definition"],
             [name.split()[0], ' '.join(name.split()[1:])])
         msg = "Plugin configuration added"
     elif name.split()[0] == "unautosend":
         settingsHandler.deleteSetting("'core-input'", "definition",
                                       ' '.join(name.split()[1:]))
         msg = "Configuration removed!"
     return ["PRIVMSG $C$ :" + msg]