コード例 #1
0
 def parseResponse(self):
     items = []
     itemMatchPattern = PatternManager.getOrCompilePattern('mallItemSearchResult')
     itemDetailsPattern = PatternManager.getOrCompilePattern('mallItemSearchDetails')
     for itemMatch in itemMatchPattern.finditer(self.responseText):
         matchText = itemMatch.group(1)
         match = itemDetailsPattern.search(matchText)
         itemId = int(match.group('itemId'))
         try:
             item = ItemDatabase.getItemFromId(itemId)
             item["price"] = int(match.group('price').replace(',', ''))
             item["storeId"] = int(match.group('storeId'))
             item["storeName"] = match.group('storeName').replace('<br>', ' ')
             item["quantity"] = int(match.group('quantity').replace(',', ''))
             limit = match.group('limit').replace(',', '')
             if len(limit) > 0:
                 limit = int(limit)
             item["limit"] = limit
             if matchText.find('limited"') >= 0:
                 item["hitLimit"] = True
             items.append(item)
         except Error.Error, inst:
             if inst.code == Error.ITEM_NOT_FOUND:
                 Report.info("itemdatabase", "Unrecognized item found in mall search: %s" % itemId, inst)
             else:
                 raise inst
コード例 #2
0
 def parseResponse(self):
     items = []
     itemMatchPattern = PatternManager.getOrCompilePattern(
         'mallItemSearchResult')
     itemDetailsPattern = PatternManager.getOrCompilePattern(
         'mallItemSearchDetails')
     for itemMatch in itemMatchPattern.finditer(self.responseText):
         matchText = itemMatch.group(1)
         match = itemDetailsPattern.search(matchText)
         itemId = int(match.group('itemId'))
         try:
             item = ItemDatabase.getItemFromId(itemId, self.session)
             item["price"] = int(match.group('price').replace(',', ''))
             item["storeId"] = int(match.group('storeId'))
             item["storeName"] = match.group('storeName').replace(
                 '<br>', ' ')
             item["quantity"] = int(
                 match.group('quantity').replace(',', ''))
             limit = match.group('limit').replace(',', '')
             if len(limit) > 0:
                 limit = int(limit)
             item["limit"] = limit
             if matchText.find('limited"') >= 0:
                 item["hitLimit"] = True
             items.append(item)
         except ItemNotFoundError, inst:
             Report.info(
                 "itemdatabase",
                 "Unrecognized item found in mall search: %s" % itemId,
                 inst)
コード例 #3
0
ファイル: ChatUneffecter.py プロジェクト: MicN/HogBotGit
def uneffect(bot, id):
    r = UneffectRequest(bot.session, id)
    try:
        r.doRequest()
        resp = "Effect successfully removed!"
    except Error:
        resp = "Unable to remove effect for unknown reason."
    
    Report.info("bot", resp)    
コード例 #4
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
コード例 #5
0
ファイル: AleabotFilter.py プロジェクト: aleabot/aleabot
def botEndCycle(context, **kwargs):
    returnCode = FilterManager.CONTINUE
    bot = kwargs['bot']

    # Check for new kmails?
    aleabot.kmail_check_timer += aleabot.config.get('time_to_sleep')
    if aleabot.kmail_check_timer >= aleabot.config.get('time_to_sleep_kmail'):
        Report.trace('bot', 'Enabling doWork:kmail')
        bot.params['doWork:kmail'] = True
        aleabot.kmail_check_timer = 0
    else:
        Report.trace('bot', 'Disabling doWork:kmail')
        bot.params.pop('doWork:kmail', None)

    # Update clan state in regular intervals (as configured)
    try:
        aleabot.clanstate.set_session(bot.session)
        if aleabot.clanstate.update(aleabot.config.get('clan_state_refresh_time')):
            Report.info('bot', 'Clan state update successful.')
            Report.trace('bot', 'I am in clan: ' + repr(aleabot.clanstate.my_clan()))
            Report.trace('bot', 'I have ' + str(len(aleabot.clanstate.my_whitelists())) + ' whitelists')
            # Set timer to switch back to home clan
            if aleabot.home_clan_timer < 0:
                aleabot.home_clan_timer = 0
    except alea.clan.ClanRequestError as err:
        Report.error('bot', 'Unable to update clan state! Error: ' + str(err))

    # Switch to home clan after some delay
    if aleabot.home_clan_timer >= 0:
        aleabot.home_clan_timer += aleabot.config.get('time_to_sleep')
        if aleabot.home_clan_timer >= aleabot.config.get('home_clan_delay'):
            aleabot.home_clan_timer = -1

            # Breakfast now if not yet breakfasted today
            if 'breakfast' not in bot.states['rollover']:
                alea.breakfast.breakfast(bot.session)
                bot.states['rollover']['breakfast'] = True
                bot.writeState('rollover')

            # Switch to home clan now
            home_clan_id = aleabot.config.get('home_clan_id')
            if home_clan_id > 0 and aleabot.clanstate.my_clan().id() != home_clan_id:
                Report.info('bot', 'Switching back to home clan.')
                try:
                    aleabot.clanstate.switch(alea.clan.Clan(home_clan_id, ''))
                except alea.clan.ClanRequestError as err:
                    Report.error('bot', 'Unable to switch clan! Error: ' + str(err))

    return returnCode
コード例 #6
0
ファイル: BotManager.py プロジェクト: thedufer/pykol
def runBots():
	if len(_bots) > 1:
		Report.includeThreadName = True
	
	for bot in _bots:
		bot.start()
	
	try:
		while _haltEvent.isSet() == False:
			time.sleep(15)
	except KeyboardInterrupt:
		_haltEvent.set()
	
	Report.info("bot", "Shutting down.")
		
	for bot in _bots:
		bot.join()
コード例 #7
0
def runBots():
    if len(_bots) > 1:
        Report.setIncludeThreadName(True)

    FilterManager.executeFiltersForEvent("runBots")

    for bot in _bots:
        bot.start()

    try:
        while _haltEvent.isSet() == False:
            time.sleep(15)
    except KeyboardInterrupt:
        _haltEvent.set()

    Report.info("bot", "Shutting down.")

    for bot in _bots:
        bot.join()
コード例 #8
0
ファイル: ClanStashLogRequest.py プロジェクト: MicN/HogBotGit
	def parseStashActivity(self, clanLog):
		results = {}
		
		match = STASH_PATTERN.search(clanLog)
		if match:
			rows = match.group("rows").split("<br>")
			for row in rows:
				row = row.strip()
				if len(row) > 0:
					data = self.parseStashActivityRow(row)
					category = data["category"]
					if not category in results:
						results[category] = []
					results[category].append(data)
					del data["category"]
		else:
			Report.info("bot", "Stash activity not found in clan activity log")
			
		return results
コード例 #9
0
ファイル: UneffectHelper.py プロジェクト: Alecat/pykol
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
コード例 #10
0
ファイル: BotManager.py プロジェクト: MicN/HogBotGit
def runBots():
    if len(_bots) > 1:
        Report.setIncludeThreadName(True)

    FilterManager.executeFiltersForEvent("runBots")

    for bot in _bots:
        bot.start()

    try:
        while _haltEvent.isSet() == False:
            time.sleep(15)
    except KeyboardInterrupt:
        _haltEvent.set()

    Report.info("bot", "Shutting down.")

    for bot in _bots:
        bot.join()
コード例 #11
0
ファイル: SmileHandler.py プロジェクト: nchusid/pykol
# $Id: SmileHandler.py 646 2008-10-01 04:22:39Z scelis $
from kol.Error import ParseMessageError
from kol.bot import BotUtils
from kol.database import SkillDatabase
コード例 #12
0
ファイル: AleabotFilter.py プロジェクト: aleabot/aleabot
def botProcessChat(context, **kwargs):
    returnCode = FilterManager.CONTINUE
    bot = kwargs['bot']
    chat = kwargs['chat']
    if chat['type'] in ['private']:
        # Initialize variables for response formatting
        user_name = str(chat['userName'])
        user_id = str(chat['userId'])
        current_time = time.time()
        exprlist = []
        exprresults = []
        channel = ''
        clan = alea.clan.Clan(0, '')
        target_name = ''
        target_id = '0'
        uneffectable = alea.util.Uneffectable('')
        msg = ''

        try:
            # Parse the abomination that our chat partner hath wrought
            request = alea.parser.aleabot_parse(chat['text'])

            if request[0] == 'rollrequest':
                # Handle a dice rolling request
                exprlist = request[1]
                channel = request[2]

                # Get the reply text that applies to this kind of roll request
                diceless = all(expr.classify_dice() == 0 for expr in exprlist)
                if channel == '':
                    # Private rolling
                    if diceless:
                        msg = aleabot.config.get('rolltext_diceless_private')
                    else:
                        msg = aleabot.config.get('rolltext_private')
                else:
                    # Public rolling
                    if diceless:
                        msg = aleabot.config.get('rolltext_diceless_public')
                    else:
                        msg = aleabot.config.get('rolltext_public')

                # Check if channel is allowed, and switch clan if needed
                if channel != '':
                    if channel in aleabot.config.get('channels').split():
                        # Allowed public channel (e.g. /games)
                        pass
                    elif channel in aleabot.config.get('clanchannels').split():
                        # Allowed clan channel (e.g. /clan, /hobopolis, ...)
                        aleabot.clanstate.set_session(bot.session)
                        clan = aleabot.clanstate.player_clan(user_id)
                        Report.info('bot', '%s asked me to roll in clan %s' % (user_name, clan.name()))
                        if clan.id() == 0:
                            Report.warning('bot', 'A player who is not in a clan asked me to roll in ' + channel)
                            raise ClanlessPlayerError('clanless player')
                        elif not aleabot.clanstate.have_whitelist(clan):
                            Report.warning('bot', 'I do not have a whitelist in clan %s' % clan.name())
                            raise NeedWhitelistError('need whitelist')
                        else:
                            Report.info('bot', 'I have a whitelist in clan %s' % clan.name())
                            aleabot.clanstate.switch(clan)
                            # Set timer to switch back to home clan
                            aleabot.home_clan_timer = 0
                    else:
                        raise ChannelDisallowedError(channel)

                # Apply time-based limits
                aleabot.rolllimiter.check(channel, user_id, clan.id(),
                        current_time, aleabot.config)

                # Evaluate dice expressions
                exprresults = alea.expr.aleabot_eval(exprlist,
                        channel != '', aleabot.rng, aleabot.config)

                # Update time-based roll limiter
                aleabot.rolllimiter.update(channel, user_id, clan.id(),
                        current_time, aleabot.config)

                # Record roll and result in roll verification list
                state = bot.states['global']
                rollverify_key = 'rollverify_' + user_id
                if rollverify_key not in state:
                    state[rollverify_key] = []
                state[rollverify_key].insert(0, (
                    current_time,
                    [str(x) for x in exprlist],
                    [str(x) for x in exprresults],
                    str(channel),
                    str(clan.name())))
                rollverify_count = aleabot.config.get('rollverify_count')
                state[rollverify_key] = state[rollverify_key][0:rollverify_count]
                bot.writeState('global')

            elif request[0] == 'rollverifyrequest':
                # Handle a roll verification request
                try:
                    target_name, target_id = resolve_target(bot,
                            user_name, user_id, request[1])

                    # Get config settings
                    rollverify_count = aleabot.config.get('rollverify_count')
                    rollverify_header = aleabot.config.get('rollverify_header')
                    rollverify_entry_private = aleabot.config.get('rollverify_entry_private')
                    rollverify_entry_public = aleabot.config.get('rollverify_entry_public')
                    rollverify_entry_clan = aleabot.config.get('rollverify_entry_clan')
                    
                    # Get saved list of rolls
                    state = bot.states['global']
                    rollverify_key = 'rollverify_' + target_id
                    rolls = state.get(rollverify_key, [])
                    rolls = rolls[0:rollverify_count]

                    # Build kmail
                    rollverify_kmail = {}
                    rollverify_kmail['userId'] = user_id
                    rollverify_kmail['text'] = format_reply(rollverify_header,
                            user_name=user_name,
                            user_id=user_id,
                            current_time=current_time,
                            target_name=target_name,
                            target_id=target_id)
                    rollverify_kmail['text'] += '\n\n'
                    for roll in rolls:
                        if roll[4] != '':  # clan != ''
                            rollverify_entry = rollverify_entry_clan
                        elif roll[3] != '':  # channel != ''
                            rollverify_entry = rollverify_entry_public
                        else:
                            rollverify_entry = rollverify_entry_private
                        rollverify_kmail['text'] += format_reply(rollverify_entry,
                                user_name=user_name,
                                user_id=user_id,
                                current_time=roll[0],
                                target_name=target_name,
                                target_id=target_id,
                                exprlist=roll[1],
                                exprresults=roll[2],
                                channel=roll[3],
                                clan=roll[4])
                        rollverify_kmail['text'] += '\n'

                    # Try to send the kmail
                    bot.sendKmail(rollverify_kmail)

                except Error.Error as err:
                    if err.code == Error.USER_NOT_FOUND:
                        msg = aleabot.config.get('error_rollverify_player_not_found')
                    else:
                        msg = aleabot.config.get('error_generic')


            elif request[0] == 'helprequest':
                # Handle a help request
                msg = aleabot.config.get('helptext')

            elif request[0] == 'hellorequest':
                # Handle a hello request
                msg = aleabot.config.get('hellotext')

            elif request[0] == 'thanksrequest':
                # Handle a thanks request
                msg = aleabot.config.get('thankstext')

            elif request[0] == 'timerequest':
                # Handle a time request
                msg = aleabot.config.get('timetext')

            elif request[0] == 'wangrequest':
                # Handle a wang request
                try:
                    target_name, target_id = resolve_target(bot,
                            user_name, user_id, request[1])

                    # Check limits
                    # Use 'rollover' bot state which is cleared each rollover
                    state = bot.states['rollover']
                    wang_sender_count_key = 'wang_sender_count_' + user_id
                    wang_sender_count = state.get(wang_sender_count_key, 0)
                    wang_target_count_key = 'wang_target_count_' + target_id
                    wang_target_count = state.get(wang_target_count_key, 0)
                    if target_id == str(bot.session.userId):
                        msg = aleabot.config.get('error_wang_self')
                    elif wang_sender_count >= aleabot.config.get('wang_sender_limit'):
                        msg = aleabot.config.get('error_wang_sender_limit')
                    elif wang_target_count >= aleabot.config.get('wang_target_limit'):
                        msg = aleabot.config.get('error_wang_target_limit')
                    elif target_id != user_id and ('dontwangme_' + target_id) in bot.states['global']:
                        msg = aleabot.config.get('error_wang_notwanted')
                    else:

                        # Limits not reached yet. Slap!
                        Report.info('bot', 'Slapping player with wang: ' + target_name)
                        wangreq = CursePlayerRequest(bot.session, target_id, ITEM_ID_WANG)
                        wangreq.doRequest()
                        if target_id == user_id:
                            msg = aleabot.config.get('wangtext_self')
                        else:
                            msg = aleabot.config.get('wangtext')

                        # Increase limit counters
                        state[wang_sender_count_key] = wang_sender_count + 1
                        state[wang_target_count_key] = wang_target_count + 1
                        bot.writeState('rollover')

                except Error.Error as err:
                    if err.code == Error.ITEM_NOT_FOUND:
                        msg = aleabot.config.get('error_wang_no_wangs')
                    elif err.code == Error.USER_NOT_FOUND:
                        msg = aleabot.config.get('error_wang_player_not_found')
                    else:
                        msg = aleabot.config.get('error_wang_generic')

            elif request[0] == 'arrowrequest':
                # Handle an arrow request
                try:
                    target_name, target_id = resolve_target(bot,
                            user_name, user_id, request[1])

                    # Check limits
                    # Use 'rollover' bot state which is cleared each rollover
                    state = bot.states['rollover']
                    arrow_sender_count_key = 'arrow_sender_count_' + user_id
                    arrow_sender_count = state.get(arrow_sender_count_key, 0)
                    if target_id == str(bot.session.userId):
                        msg = aleabot.config.get('error_arrow_self')
                    elif arrow_sender_count >= aleabot.config.get('arrow_sender_limit'):
                        msg = aleabot.config.get('error_arrow_sender_limit')
                    else:

                        # Limits not reached yet. Fire!
                        Report.info('bot', 'Firing arrow at player: ' + target_name)
                        arrowreq = CursePlayerRequest(bot.session, target_id, ITEM_ID_ARROW)
                        arrowreq.doRequest()
                        if target_id == user_id:
                            msg = aleabot.config.get('arrowtext_self')
                        else:
                            msg = aleabot.config.get('arrowtext')

                        # Increase limit counters
                        state[arrow_sender_count_key] = arrow_sender_count + 1
                        bot.writeState('rollover')

                except Error.Error as err:
                    if err.code == Error.ITEM_NOT_FOUND:
                        msg = aleabot.config.get('error_arrow_no_arrows')
                    elif err.code == Error.USER_NOT_FOUND:
                        msg = aleabot.config.get('error_arrow_player_not_found')
                    elif err.code == Error.USER_IN_HARDCORE_RONIN:
                        msg = aleabot.config.get('error_arrow_ronin')
                    elif err.code == Error.ALREADY_COMPLETED:
                        msg = aleabot.config.get('error_arrow_already_hit')
                    else:
                        msg = aleabot.config.get('error_arrow_generic')

            elif request[0] == 'uneffectrequest':
                # Handle an uneffect request
                uneffectable = request[1]
                if uneffectable.inputname() == '':
                    msg = aleabot.config.get('error_uneffect_no_effect_given')
                elif uneffectable.count() == 0:
                    msg = aleabot.config.get('error_uneffect_no_match')
                elif uneffectable.count() >= 2:
                    msg = aleabot.config.get('error_uneffect_too_many_matches')
                else:
                    # Exactly one effect matched
                    effect_id = uneffectable.effect_ids()[0]
                    print str(effect_id)
                    uneffectreq = UneffectRequest(bot.session, effect_id)
                    try:
                        uneffectreq.doRequest()
                        msg = aleabot.config.get('uneffecttext')
                    except Error.Error as err:
                        if err.code == Error.EFFECT_NOT_FOUND:
                            msg = aleabot.config.get('error_uneffect_not_cursed')
                        elif err.code == Error.ITEM_NOT_FOUND:
                            msg = aleabot.config.get('error_uneffect_no_sgeea')
                        else:
                            msg = aleabot.config.get('error_uneffect_generic')

            elif request[0] == 'dontwangmerequest':
                # Handle a dontwangme request
                key = 'dontwangme_' + user_id
                bot.states['global'][key] = True
                bot.writeState('global')
                msg = aleabot.config.get('dontwangmetext')

            elif request[0] == 'allowwangrequest':
                # Handle an allowwang request
                key = 'dontwangme_' + user_id
                bot.states['global'].pop(key, None)
                bot.writeState('global')
                msg = aleabot.config.get('allowwangtext')

        except GenericAleabotError:
            msg = aleabot.config.get('error_generic')
        except ChannelDisallowedError:
            msg = aleabot.config.get('error_channel_disallowed')
        except ClanlessPlayerError:
            msg = aleabot.config.get('error_clanless_player')
        except NeedWhitelistError:
            msg = aleabot.config.get('error_need_whitelist')
        except alea.clan.ClanRequestError:
            msg = aleabot.config.get('error_clan_request')
        except alea.rolllimiter.PrivatePerPlayerRollLimitError:
            msg = aleabot.config.get('error_private_perplayer_limit')
        except alea.rolllimiter.PublicPerPlayerRollLimitError:
            msg = aleabot.config.get('error_public_perplayer_limit')
        except alea.rolllimiter.PublicPerChannelRollLimitError:
            msg = aleabot.config.get('error_public_perchannel_limit')
        except alea.expr.ResultCountExceededError:
            msg = aleabot.config.get('error_too_many_results')
        except alea.expr.DiceCountExceededError:
            msg = aleabot.config.get('error_expression_too_many_dice')
        except alea.expr.DicelessDisallowedError:
            msg = aleabot.config.get('error_diceless')
        except alea.expr.D1DisallowedError:
            msg = aleabot.config.get('error_d1')
        except alea.expr.AleabotEvalError:
            msg = aleabot.config.get('error_expression_eval')
        except alea.parser.AleabotSyntaxError:
            msg = aleabot.config.get('error_bad_syntax')

        # If not explicitly chatting to a public channel or a private
        # conversation, make sure we /msg the user who is talking to us
        if msg != '' and msg[0] != '/':
            msg = '/msg %p ' + msg

        # Format reply message
        msg = format_reply(msg,
                user_name=user_name,
                user_id=user_id,
                current_time=current_time,
                exprlist=exprlist,
                exprresults=exprresults,
                channel=channel,
                clan=clan,
                target_name=target_name,
                target_id=target_id,
                uneffectable=uneffectable)

        # Chat!
        if msg != '':
            response = bot.sendChatMessage(msg)
            response_text = "\n".join(x['text'] for x in response)

            # Handle chat errors
            if 'You cannot access that channel' in response_text:
                Report.warning('bot', 'Received error while chatting: ' + response_text)
                msg = aleabot.config.get('error_channel_inaccessible')
                msg = '/msg ' + user_id + ' ' + msg
                bot.sendChatMessage(msg)

        returnCode = FilterManager.FINISHED

    elif chat['type'] in ['notification:kmail']:
        Report.info('bot', 'Kmail notification received.')

        # Make sure to check for new kmails next cycle
        # (see botEndCycle handler)
        aleabot.kmail_check_timer = aleabot.config.get('time_to_sleep_kmail')

    elif chat['type'] in ['unknown']:
        # Handle some chat messages of type 'unknown'
        # Such as: whitelist changes, clan acceptance / rejection
        aleabot.clanstate.set_session(bot.session)
        if aleabot.clanstate.read_unknown_chat_message(chat['text']):
            Report.info('bot', 'Clan state is no longer valid, need to reload.')

    return returnCode
コード例 #13
0
ファイル: AleabotFilter.py プロジェクト: aleabot/aleabot
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
コード例 #14
0
ファイル: breakfast.py プロジェクト: aleabot/aleabot
def breakfast(session):
    Report.info('bot', 'Start of breakfast.')

    meatGained = 0

    Report.info('bot', 'Visiting hippy produce stand.')
    try:
        req = HippyProduceStandRequest(session)
        response = req.doRequest()
        meatGained += response['meat']
    except Error.Error as err:
        Report.error('bot', 'Error while visiting hippy produce stand: ' + str(err))

    Report.info('bot', 'Visiting potted meat bush.')
    try:
        req = MeatBushRequest(session)
        response = req.doRequest()
        meatGained += response['meat']
    except Error.Error as err:
        Report.error('bot', 'Error while visiting potted meat bush: ' + str(err))

    Report.info('bot', 'Visiting exotic hanging meat orchid.')
    try:
        req = MeatOrchidRequest(session)
        response = req.doRequest()
        meatGained += response['meat']
    except Error.Error as err:
        Report.error('bot', 'Error while visiting exotic hanging meat orchid: ' + str(err))

    Report.info('bot', 'Visiting potted meat tree.')
    try:
        req = MeatTreeRequest(session)
        response = req.doRequest()
        meatGained += response['meat']
    except Error.Error as err:
        Report.error('bot', 'Error while visiting potted meat tree: ' + str(err))

    Report.info('bot', 'End of breakfast. Meat gained: ' + str(meatGained))