Esempio n. 1
0
    def __init__(self, bot: Bot):

        self.b = bot
        self.hiddenstreet = HiddenStreet(bot.loop)
Esempio n. 2
0
class Maple:
    """Maple Story commands"""

    def __init__(self, bot: Bot):

        self.b = bot
        self.hiddenstreet = HiddenStreet(bot.loop)

        # if settings.SET_SERVER_START_DEFAULT is None:
        #     self.server_start = None
        #     log.warn('Server start wasn\'t set at bot start. Defaulting to None')
        #     self.cog_is_initializing = False
        # else:
        #     bot.loop.create_task(self._init_server_start())

    # @catch_exceptions
    # def pierre_alert_job(self, first_run=False):
    #
    #     assert not self.b.is_closed or self.b.is_logged_in, 'Connection to host is closed, skipping execution'
    #     assert self.server_start is not None, 'Server start is not currently set'
    #
    #     t = self.pierre_next_respawn().total_seconds()
    #
    #     for destination in [server.default_channel
    #                         for server in self.b.servers
    #                         if server.default_channel.type == ChannelType.text]:
    #         message = format_pierre_interval(t // 3600, t % 3600 // 60, t % 60)
    #         self.b.loop.create_task(self.b.send_message(destination, message))
    #         schedule_log.info('Pierre alert sent to channel {}: {}'.format(destination.name, message))
    #
    #     if first_run:
    #         schedule_log.info('First run, now rescheduling for next four hours')
    #         schedule.every(4).hours.do(self.pierre_alert_job, first_run=False)
    #         return schedule.CancelJob
    #     else:
    #         schedule_log.info('Standard run, terminating normally')
    #
    # def pierre_next_respawn(self) -> timedelta:
    #     now = utc.localize(datetime.utcnow(), is_dst=True)
    #     req_interval = now - self.server_start
    #     return timedelta(0, 14400 - (req_interval.total_seconds() % 14400))
    #
    # @asyncio.coroutine
    # def _init_server_start(self):
    #     self.cog_is_initializing = True
    #     with aiohttp.ClientSession() as client:
    #         response = yield from client.get(settings.SET_SERVER_START_DEFAULT)
    #         args = yield from response.text()
    #         args = args.rstrip()
    #
    #     yield from self.set_server_uptime.callback(self, *args.split())
    #     self.cog_is_initializing = False

    # @command()
    # @asyncio.coroutine
    # def event(self):
    #     """A quick Halloween Event guide for the lazy Mapler"""
    #     yield from self.b.say('**MapleRoyals Halloween Event 2016**\n'
    #                           '*October 15th ~ November 15th*\n\n'
    #                           '**Quick Guide:** https://mapleroyals.com/'
    #                           'forum/threads/pierre-the-clown.80732/\n\n'
    #                           'http://i.imgur.com/vTO05be.png')
    #
    # @command()
    # @asyncio.coroutine
    # def pierre(self):
    #     """Shows the next respawn time for Pierre."""
    #
    #     if self.server_start is None:
    #         yield from self.b.say(msg('pierre.date not set').format(**settings.BOT))
    #         return
    #
    #     t = self.pierre_next_respawn().total_seconds()
    #     yield from self.b.say(format_pierre_interval(t // 3600, t % 3600 // 60, t % 60))

    @command(name='mobstats')
    @asyncio.coroutine
    def monster_stats(self, *words):
        """Finds stats for a monster put --exact (or -e for short) to \
have the exact match for the name you're looking for. Data is by kind \
concession from http://bbb.hidden-street.net/"""
        flag = words[0] in ['--exact', '-e']
        if flag:
            name = ' '.join(words[1:])
        else:
            name = ' '.join(words)

        result = self.hiddenstreet.monsters_by_name(name, exact_match=flag)
        if len(result) == 0:
            yield from self.b.say(msg('monster_stats.no results').format(name))
        elif len(result) > 3:
            n = '", "'.join([m.name for m in result])
            yield from self.b.say(msg('monster_stats.too many').format(n))
        else:

            for monster in result:
                if monster.experience:
                    monster.experience *= 4
                mdict = monster.to_dict
                mdict['link'] = 'http://bbb.hidden-street.net/monster/{}'.format(
                    monster.name.lower().replace(' ', '-').replace('\'', ''))
                message = msg('monster_stats.result').format(**mdict)
                if monster.image_url:
                    message += '\n{}'.format(monster.image_url)
                yield from self.b.say(message)

    @command(name='maple')
    @asyncio.coroutine
    def maple_weapons_info(self, *search_terms):
        """Finds stats and drop locations for a Maple Weapon. Please note that level 77 Maple Pyrope Weapons \
are events only, and thus not available for searching."""

        if any(['pyrope' in keyword.lower() for keyword in search_terms]):
            yield from self.b.say(msg('maple_weapons_info.pyrope'))
            return

        result = self.hiddenstreet.maple_weapon_by_name(*search_terms)

        if len(result) == 0:
            yield from self.b.say(msg('maple_weapons_info.no results').format(keyword=' '.join(search_terms),
                                                                              **settings.BOT))
        elif len(result) > 3:
            yield from self.b.say(msg('maple_weapons_info.too many').format(**settings.BOT))
        else:
            log.debug('gotten {} records from backend'.format(len(result)))
            library_link = 'https://mapleroyals.com/library/?page=items&id={}'
            img_template = 'https://mapleroyals.com/library/images/item/{:08d}.png'
            for maple_weapon in result:
                log.debug(maple_weapon)
                d = maple_weapon.to_dict
                if maple_weapon.weapon_type in ['STAFF', 'WAND']:
                    d['magic_attack_string'] = ' **Magic Attack** ' + maple_weapon.magic_attack
                else:
                    d['magic_attack_string'] = ''
                d['library_link'] = library_link.format(maple_weapon.id_weapon)
                d['image_link'] = img_template.format(maple_weapon.id_weapon)
                yield from self.b.say(msg('maple_weapons_info.result').format(**d))

    @command(name='maplelist')
    @asyncio.coroutine
    def maple_list_info(self, weapon_level: int=None):
        """Prints a simple list for all the Maple Weapons currently available in game."""

        result = self.hiddenstreet.maple_list_by_level(weapon_level)

        log.debug('gotten {} records from backend'.format(len(result)))
        for w in result:
            yield from self.b.say(msg('maple_list_info.result').format(required_level=w.required_level,
                                                                       names=w.names))