Exemple #1
0
def handlePrivateChat(context, **kwargs):
    returnCode = FilterManager.CONTINUE
    chat = kwargs["chat"]
    bot = kwargs["bot"]
    globalState = bot.states["global"]

    if chat["text"] == "squelch":
        if BotUtils.canUserPerformAction(chat["userId"], "squelch", bot):
            globalState["isSquelched"] = True
            bot.writeState("global")
            bot.sendChatMessage("No longer broadcasting /clan to the other clan channels.")
        else:
            bot.sendChatMessage("You do not have permission to perform this action.")
        returnCode = FilterManager.FINISHED
    elif chat["text"] == "unsquelch":
        if BotUtils.canUserPerformAction(chat["userId"], "squelch", bot):
            globalState["isSquelched"] = False
            bot.writeState("global")
            bot.sendChatMessage("Now broadcasting /clan to the other clan channels.")
        else:
            bot.sendChatMessage("You do not have permission to perform this action.")
        returnCode = FilterManager.FINISHED
    elif chat["text"] == "squelchall":
        if BotUtils.canUserPerformAction(chat["userId"], "squelch", bot):
            for aBot in BotManager._bots:
                aBot.states["global"]["isSquelched"] = True
                aBot.writeState("global")
                aBot.sendChatMessage("All bots have been squelched.")
        else:
            bot.sendChatMessage("You do not have permission to perform this action.")
        returnCode = FilterManager.FINISHED
    elif chat["text"] == "unsquelchall":
        if BotUtils.canUserPerformAction(chat["userId"], "squelch", bot):
            for aBot in BotManager._bots:
                aBot.states["global"]["isSquelched"] = False
                aBot.writeState("global")
                aBot.sendChatMessage("All bots have been unsquelched.")
        else:
            bot.sendChatMessage("You do not have permission to perform this action.")
        returnCode = FilterManager.FINISHED
    elif chat["text"] == "who":
        response = bot.sendChatMessage("/who")
        whoChat = response[0]
        str = ""
        for user in whoChat["users"]:
            if user["userName"] != bot.id:
                if len(str) > 0:
                    str += ", "
                str += user["userName"]
        if len(str) > 0:
            bot.sendChatMessage("/w %s %s" % (chat["userId"], str))
        else:
            bot.sendChatMessage("/w %s There is no one else in my clan channel." % chat["userId"])
        returnCode = FilterManager.FINISHED

    return returnCode
Exemple #2
0
def botProcessChat(context, **kwargs):
    returnCode = FilterManager.CONTINUE
    chat = kwargs["chat"]
    
    if chat["type"] == "private":
        if BotUtils.canUserPerformAction(chat["userId"], "execute", kwargs["bot"]):
            doAction = False
            executeAll = False
            wordList = chat["text"].split()
            if len(wordList) > 0:
                if wordList[0].lower() == "execute":
                    doAction = True
                elif wordList[0].lower() == "executeall":
                    doAction = True
                    executeAll = True

            if doAction:
                returnCode = FilterManager.FINISHED
                del wordList[0]
                command = " ".join(wordList)

                if executeAll:
                    for bot in BotManager._bots:
                        if bot.session != None and bot.session.isConnected and hasattr(bot.session, "chatManager"):
                            try:
                                bot.sendChatMessage(command)
                            except AttributeError, inst:
                                Report.error("chat", "Could not execute command: %s" % command, inst)
                else:
                    kwargs["bot"].sendChatMessage(command)
Exemple #3
0
def botProcessChat(context, **kwargs):
	bot = kwargs["bot"]
	chat = kwargs["chat"]
	msg = BotUtils.getChatTextWithoutCmd(chat)
	
	if msg != "":
		bot.sendChatMessage(msg)
	else:
		bot.sendChatMessage("/msg %s You forgot to include a message." % (chat["userId"]))
			
	
	return FilterManager.FINISHED
Exemple #4
0
def resetHobopolisInstance(context, **kwargs):
    chat = kwargs["chat"]
    bot = kwargs["bot"]
    state = bot.states["global"]

    if BotUtils.canUserPerformAction(chat["userId"], "resetdungeon", bot):
        keysToClear = ["hobo:sewerTrapped", "hobo:tiresStacked"]
        for key in keysToClear:
            if key in state:
                del state[key]
        bot.writeState("global")
        bot.sendChatMessage("/w %s Hobopolis Data Cleared." % chat["userId"])
    else:
        bot.sendChatMessage("You do not have permission to perform this action.")
Exemple #5
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
Exemple #6
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
Exemple #7
0
def botProcessKmail(context, **kwargs):
	returnCode = FilterManager.CONTINUE
	m = kwargs["kmail"]
	bot = kwargs["bot"]
	state = bot.states["job"]
	
	forwardKmail = True
	if "kmailForwardingCommands" in bot.params:
		cmd = BotUtils.getKmailCommand(m)
		if cmd not in bot.params["kmailForwardingCommands"]:
			forwardKmail = False
	
	if forwardKmail:
		returnCode = FilterManager.FINISHED
		if "forwardedKmail" not in state:
			fwd = copy.deepcopy(m)
			fwd["text"] = "Message from %s (#%s):\n%s" % (m["userName"], m["userId"], m["text"])
			fwd["userId"] = bot.params["forwardKmailsTo"]
			bot.sendKmail(fwd)
			state["forwardedKmail"] = True
			bot.writeState("job")
		
	return returnCode
Exemple #8
0
def handlePrivateChat(context, **kwargs):
    returnCode = FilterManager.CONTINUE
    chat = kwargs["chat"]
    bot = kwargs["bot"]
    globalState = bot.states["global"]

    arr = chat["text"].split()

    if chat["text"] == "squelch":
        if BotUtils.canUserPerformAction(chat["userId"], "squelch", bot):
            globalState["isSquelched"] = True
            bot.writeState("global")
            bot.sendChatMessage("No longer broadcasting /clan to the other clan channels.")
        else:
            bot.sendChatMessage("/w %s You do not have permission to perform this action." % chat["userId"])
        returnCode = FilterManager.FINISHED
    elif chat["text"] == "unsquelch":
        if BotUtils.canUserPerformAction(chat["userId"], "squelch", bot):
            globalState["isSquelched"] = False
            bot.writeState("global")
            bot.sendChatMessage("Now broadcasting /clan to the other clan channels.")
        else:
            bot.sendChatMessage("/w %s You do not have permission to perform this action." % chat["userId"])
        returnCode = FilterManager.FINISHED
    elif chat["text"] == "muteall":
        if BotUtils.canUserPerformAction(chat["userId"], "muteall", bot):
            for aBot in BotManager._bots:
                aBot.states["global"]["isSquelched"] = True
                aBot.writeState("global")
                aBot.sendChatMessage("All bots have been muted.")
        else:
            bot.sendChatMessage("/w %s You do not have permission to perform this action." % chat["userId"])
        returnCode = FilterManager.FINISHED
    elif chat["text"] == "unmuteall":
        if BotUtils.canUserPerformAction(chat["userId"], "muteall", bot):
            for aBot in BotManager._bots:
                aBot.states["global"]["isSquelched"] = False
                aBot.writeState("global")
                aBot.sendChatMessage("All bots have been unmuted.")
        else:
            bot.sendChatMessage("/w %s You do not have permission to perform this action." % chat["userId"])
        returnCode = FilterManager.FINISHED
    elif chat["text"] == "who":
        response = bot.sendChatMessage("/who")
        whoChat = response[0]
        str = ""
        for user in whoChat["users"]:
            if user["userName"] != bot.id:
                if len(str) > 0:
                    str += ", "
                str += user["userName"]
        if len(str) > 0:
            bot.sendChatMessage("/w %s %s" % (chat["userId"], str))
        else:
            bot.sendChatMessage("/w %s There is no one else in my clan channel." % chat["userId"])
        returnCode = FilterManager.FINISHED
    elif chat["text"] == "help":
        m = {}
        m["userId"] = chat["userId"]
        m["text"] = generateHelpText(bot.params["userName"])
        bot.sendKmail(m)
        returnCode = FilterManager.FINISHED
    elif chat["text"] == "mymsgs":
        m = {}
        m["userId"] = chat["userId"]
        message = (
            "Enter Message: "
            + HogDatabase.getEnterMessage(chat["userId"], chat["userName"])
            + "\n"
            + "Exit Message: "
            + HogDatabase.getExitMessage(chat["userId"], chat["userName"])
        )
        m["text"] = message
        bot.sendKmail(m)
        returnCode = FilterManager.FINISHED
    elif chat["text"] == "autolog":
        toggle = HogDatabase.toggleAutolog(chat["userId"], chat["userName"])
        if toggle == 1:
            bot.sendChatMessage("/w %s autolog enabled." % (chat["userId"]))
        else:
            bot.sendChatMessage("/w %s autolog disabled." % (chat["userId"]))
        returnCode = FilterManager.FINISHED
    elif chat["text"] == "log":
        sendLatestLog(bot, chat["userId"], bot.params["userClan"])
        returnCode = FilterManager.FINISHED

    if len(arr) > 0 and arr[0] == "entermsg":
        enterMsg = chat["text"].replace("entermsg ", "", 1)
        HogDatabase.setEnterMessage(chat["userId"], chat["userName"], enterMsg)
        bot.sendChatMessage("/w %s Enter message changed to: %s" % (chat["userId"], enterMsg))
        returnCode = FilterManager.FINISHED
    elif len(arr) > 0 and arr[0] == "exitmsg":
        exitMsg = chat["text"].replace("exitmsg ", "", 1)
        HogDatabase.setExitMessage(chat["userId"], chat["userName"], exitMsg)
        bot.sendChatMessage("/w %s Exit message changed to: %s" % (chat["userId"], exitMsg))
        returnCode = FilterManager.FINISHED
    elif len(arr) > 0 and arr[0] == "seen":
        user = chat["text"].replace("seen ", "", 1)
        lastSeen = HogDatabase.getLastSeen(user)
        if lastSeen == None or lastSeen[0] == None:
            bot.sendChatMessage("/w %s %s hasn't been seen by the bot" % (chat["userId"], user))
        else:
            bot.sendChatMessage("/w %s %s last seen on %s" % (chat["userId"], user, lastSeen[0]))
        returnCode = FilterManager.FINISHED

    return returnCode
Exemple #9
0
# $Id: SmileHandler.py 646 2008-10-01 04:22:39Z scelis $
Exemple #10
0
def botProcessKmail(context, **kwargs):
    returnCode = FilterManager.CONTINUE
    message = kwargs['kmail']
    bot = kwargs['bot']

    user_name = str(message['userName'])
    user_id = str(message['userId'])
    current_time = time.time()
    cmd = BotUtils.getKmailCommand(message)
    meat = message['meat']
    items = message['items']

    # Our response
    response = ''
    # Should items and meat be sent back?
    return_goodies = True
    # Should a candy heart be sent?
    send_heart = False

    # if 1 arrow was sent and the kmail is empty, interpret it as "arrow"
    if cmd == "" and len(items) == 1 and items[0]['id'] == ITEM_ID_ARROW and items[0]['quantity'] == 1 and meat == 0:
        cmd = 'arrow'

    if cmd == 'arrow':
        # Handle arrow request
        if len(items) == 1 and items[0]['id'] == ITEM_ID_ARROW and items[0]['quantity'] == 1 and meat == 0:
            # Everything is okay
            try:
                Report.info('bot', 'Firing arrow at player: ' + user_name)
                arrowreq = CursePlayerRequest(bot.session, user_id, ITEM_ID_ARROW)
                arrowreq.doRequest()
                return_goodies = False
            except Error.Error as err:
                if err.code == Error.ITEM_NOT_FOUND:
                    response = aleabot.config.get('error_arrow_no_arrows')
                elif err.code == Error.USER_NOT_FOUND:
                    response = aleabot.config.get('error_arrow_player_not_found')
                elif err.code == Error.USER_IN_HARDCORE_RONIN:
                    response = aleabot.config.get('error_arrow_ronin')
                elif err.code == Error.ALREADY_COMPLETED:
                    response = aleabot.config.get('error_arrow_already_hit')
                else:
                    response = aleabot.config.get('error_arrow_generic')

        elif len(items) == 0 and meat == 0:
            Report.warning('bot', 'Arrow request without arrow from ' + user_name)
            response = aleabot.config.get('kmailtext_arrow_notattached')

        else:
            Report.warning('bot', 'Arrow request with extra items or meat from ' + user_name)
            response = aleabot.config.get('kmailtext_arrow_extraattached')

    elif cmd == 'donate' or cmd == 'donation':
        # Handle donation
        if len(items) == 0 and meat == 0:
            # Empty donation kmail?
            Report.warning('bot', 'Empty donation received from ' + user_name)
            response = aleabot.config.get('kmailtext_donate_empty')
        else:
            Report.info('bot', 'Donation received from ' + user_name)
            response = aleabot.config.get('kmailtext_donate_thanks')
            return_goodies = False
            send_heart = True

    else:
        # Handle unknown command
        Report.warning('bot', 'Unknown kmail command: ' + cmd)
        response = aleabot.config.get('kmailtext_unknown')

    # Send our response
    if response != '' or (return_goodies and (len(items) != 0 or meat != 0)):
        Report.info('bot', 'Responding to kmail')
        response_kmail = {}
        response_kmail['userId'] = message['userId']
        response_kmail['text'] = format_reply(response + '\n\n' + aleabot.config.get('kmailtext_quote'), user_name=user_name, user_id=user_id, current_time=current_time) + '\n' + quote_kmail(message)
        if return_goodies:
            response_kmail['items'] = items
            response_kmail['meat'] = meat
        try:
            bot.sendKmail(response_kmail)
        except Error.Error as err:
            if err.code == Error.USER_IN_HARDCORE_RONIN:
                Report.error('bot', 'Tried to send items and meat back, but user is in Hardcore or Ronin!')
                response_kmail2 = {}
                response_kmail2['userId'] = message['userId']
                response_kmail2['text'] = format_reply(response + '\n\n' + aleabot.config.get('kmailtext_quote_ronin'), user_name=user_name, user_id=user_id, curent_time=current_time) + '\n' + quote_kmail(message)
                try:
                    bot.sendKmail(response_kmail2)
                except Error.Error as err2:
                    Report.error('bot', 'Unexpected error while sending response_kmail2: ' + str(err2))
            else:
                Report.error('bot', 'Unexpected error while sending response_kmail: ' + str(err))

    # Send a candy heart
    if send_heart:
        try:
            Report.info('bot', 'Sending candy heart to player: ' + user_name)
            heartreq = CursePlayerRequest(bot.session, user_id, ITEM_ID_CANDYHEART)
            heartreq.requestData['texta'] = 'THANK'
            heartreq.requestData['textb'] = 'YOU'
            heartreq.doRequest()
        except Error.Error as err:
            Report.error('bot', 'Couldn\'t send candy heart: ' + str(err))

    returnCode = FilterManager.FINISHED
    return returnCode
Exemple #11
0
def handlePrivateChat(context, **kwargs):
    returnCode = FilterManager.CONTINUE
    chat = kwargs["chat"]
    bot = kwargs["bot"]
    globalState = bot.states["global"]

    if chat["text"] == "squelch":
        if BotUtils.canUserPerformAction(chat["userId"], "squelch", bot):
            globalState["isSquelched"] = True
            bot.writeState("global")
            bot.sendChatMessage(
                "No longer broadcasting /clan to the other clan channels.")
        else:
            bot.sendChatMessage(
                "You do not have permission to perform this action.")
        returnCode = FilterManager.FINISHED
    elif chat["text"] == "unsquelch":
        if BotUtils.canUserPerformAction(chat["userId"], "squelch", bot):
            globalState["isSquelched"] = False
            bot.writeState("global")
            bot.sendChatMessage(
                "Now broadcasting /clan to the other clan channels.")
        else:
            bot.sendChatMessage(
                "You do not have permission to perform this action.")
        returnCode = FilterManager.FINISHED
    elif chat["text"] == "squelchall":
        if BotUtils.canUserPerformAction(chat["userId"], "squelch", bot):
            for aBot in BotManager._bots:
                aBot.states["global"]["isSquelched"] = True
                aBot.writeState("global")
                aBot.sendChatMessage("All bots have been squelched.")
        else:
            bot.sendChatMessage(
                "You do not have permission to perform this action.")
        returnCode = FilterManager.FINISHED
    elif chat["text"] == "unsquelchall":
        if BotUtils.canUserPerformAction(chat["userId"], "squelch", bot):
            for aBot in BotManager._bots:
                aBot.states["global"]["isSquelched"] = False
                aBot.writeState("global")
                aBot.sendChatMessage("All bots have been unsquelched.")
        else:
            bot.sendChatMessage(
                "You do not have permission to perform this action.")
        returnCode = FilterManager.FINISHED
    elif chat["text"] == "who":
        response = bot.sendChatMessage("/who")
        whoChat = response[0]
        str = ""
        for user in whoChat["users"]:
            if user["userName"] != bot.id:
                if len(str) > 0:
                    str += ", "
                str += user["userName"]
        if len(str) > 0:
            bot.sendChatMessage("/w %s %s" % (chat["userId"], str))
        else:
            bot.sendChatMessage(
                "/w %s There is no one else in my clan channel." %
                chat["userId"])
        returnCode = FilterManager.FINISHED

    return returnCode