Example #1
0
    def __change_avatar(self, potion, pname, pid):
        try:
            # Find the IDs of the hard-shruggable effects we're under
            url = 'http://www.kingdomofloathing.com/charpane.php'
            pane = self.__session.opener.open(url, {}).text
            effects = [int(e) for e in re.findall('return hardshrug\((\d+),',
                                                  pane)]

            # Uneffect all active avatar potions
            for effect in avatar_potions.values():
                if effect in effects:
                    UneffectRequest(self.__session, effect).doRequest()
                    self.log("Uneffected ID #{}.".format(effect))

            # Use the new one and inform the person
            UseItemRequest(self.__session, potion).doRequest()
            self.log("Used avatar potion #{}.".format(potion))
            self.__chat_say(pname, pid, "Look at me!")
        except Error:
            try:
                self.__send_kmail(pname, pid,
                    "I couldn't use that avatar potion so I'm returning it.",
                    potion)
            except:
                self.__chat_say(pname, pid,
                    "I couldn't use that avatar potion and I couldn't return "
                    "it to you. Sorry.")
Example #2
0
def botProcessKmail(context, **kwargs):
    returnCode = FilterManager.CONTINUE
    message = kwargs["kmail"]
    bot = kwargs["bot"]
    cmd = BotUtils.getKmailCommand(message)

    if cmd == "uneffect":
        arr = message["text"].split()
        items = message["items"]

        # Get the effect ID.
        if len(arr) < 2:
            raise Error.Error(
                "You must specify the ID of the effect to remove.",
                Error.BOT_REQUEST)
        try:
            effectId = int(arr[1])
        except ValueError:
            raise Error.Error("Unable to remove effect. Invalid effect ID.",
                              Error.BOT_REQUEST)

        # Ensure the user sent a SGEEA.
        if len(items) != 1:
            raise Error.Error("Please include just a SGEEA in your kmail.",
                              Error.BOT_REQUEST)
        sgeea = ItemDatabase.getItemFromName(
            "soft green echo eyedrop antidote")
        if items[0]["id"] != sgeea["id"] or items[0]["quantity"] != 1:
            raise Error.Error(
                "Please include just a single SGEEA in your kmail.",
                Error.BOT_REQUEST)

        # Perform the request.
        m = {}
        m["userId"] = message["userId"]
        Report.info("bot", "Attempting to remove effect %s..." % effectId)
        r = UneffectRequest(bot.session, effectId)
        try:
            r.doRequest()
            m["text"] = "Effect successfully removed!"
        except Error.Error, inst:
            if inst.code == Error.EFFECT_NOT_FOUND:
                m["text"] = "I do not currently have that effect."
                m["items"] = items
            else:
                m["text"] = "Unable to remove effect for unknown reason."
                m["items"] = items

        bot.sendKmail(m)
        returnCode = FilterManager.FINISHED
Example #3
0
def botProcessChat(context, **kwargs):
    returnCode = FilterManager.CONTINUE
    bot = kwargs["bot"]
    chat = kwargs["chat"]
    if chat["type"] == "private":
        match = UNEFFECT_PATTERN.search(chat["text"])
        if match:
            effectId = int(match.group(1))
            r = UneffectRequest(bot.session, effectId)
            try:
                r.doRequest()
                resp = "Effect successfully removed!"
            except DontHaveEffectError, inst:
                resp = "I do not currently have that effect."
            except NotEnoughItemsError, inst:
                resp = "I do not have any SGEEAs. Would you be kind enough to send me some?"
            except Error, inst:
                resp = "Unable to remove effect for unknown reason."
Example #4
0
def botProcessChat(context, **kwargs):
    returnCode = FilterManager.CONTINUE
    bot = kwargs["bot"]
    chat = kwargs["chat"]
    if chat["type"] == "private":
        match = UNEFFECT_PATTERN.search(chat["text"])
        if match:
            effectId = int(match.group(1))
            r = UneffectRequest(bot.session, effectId)
            try:
                r.doRequest()
                resp = "Effect successfully removed!"
            except Error.Error, inst:
                if inst.code == Error.EFFECT_NOT_FOUND:
                    resp = "I do not currently have that effect."
                elif inst.code == Error.ITEM_NOT_FOUND:
                    resp = "I do not have any SGEEAs. Would you be kind enough to send me some?"
                else:
                    resp = "Unable to remove effect for unknown reason."

            bot.sendChatMessage("/w %s %s" % (chat["userId"], resp))
            returnCode = FilterManager.FINISHED