Ejemplo n.º 1
0
def find_hero_from_emoji(ctx, argument):
    # read a hero emoji
    match = re.match(r'<(a?):hero_([a-zA-Z]+)([0-9]+)?:([0-9]+)>$', argument)
    if match:
        hero_name = match.group(2)
        hero_name = emoji_dict[
            hero_name] if hero_name in emoji_dict else hero_name.lower()
        if hero_name not in hero_list:
            raise custom_exceptions.HeroNotFound(hero_name.title())
        emoji_id = int(match.group(4))
        emoji = discord.utils.get(ctx.guild.emojis, id=emoji_id)
        if not emoji:
            emoji = ctx.bot.get_emoji(ctx.guild, hero_name)
        return hero_name, emoji
    raise custom_exceptions.HeroNotFound(argument.title())
Ejemplo n.º 2
0
 async def convert(self, ctx, argument):
     try:
         _, emoji = find_hero_from_emoji(ctx, argument)
     except:
         hero = find_hero_from_text(argument)
         emoji = ctx.bot.get_emoji(ctx.guild, hero)
     if emoji:
         return emoji
     raise custom_exceptions.HeroNotFound(argument.title())
Ejemplo n.º 3
0
    async def stats(self,
                    context,
                    unit: find_hero,
                    rank: numberComparisonConverter = None,
                    level: numberComparisonConverter = None):
        result = self.bot.db[context.guild.id].select("hero", unit)
        if result is None:
            raise custom_exceptions.HeroNotFound(unit.title())
        minRank, maxRank = result["minRank"], result["maxRank"]
        if rank is None:
            rank = maxRank
        if level is None:
            level = max_level

        if isinstance(rank, tuple):
            rank1, rank2 = rank[0], rank[1]
        else:
            rank1, rank2 = rank, rank
        if isinstance(level, tuple):
            level1, level2 = level[0], level[1]
        else:
            level1, level2 = level, level
        if (not 0 < level1 <= max_level) or (not 0 < level2 <= max_level):
            await context.send(
                f"Level of {unit.title()} must be between 1 and {max_level}.")
            return
        if (not minRank <= rank1 <= maxRank) or (
                not minRank <= rank2 <= maxRank):
            await context.send(
                f"Rank of {unit.title()} must be between rank {minRank} and rank {maxRank}."
            )
            return
        timeout = self.get_active_time(context.guild) * 60
        if rank1 == rank2 and level1 == level2:
            # display the stats
            guide = stats_guide.StatsMessage(unit,
                                             rank1,
                                             level1,
                                             result,
                                             context=context,
                                             timeout=timeout)
        else:
            # compare the stats
            guide = stats_guide.StatsCmpMessage(unit,
                                                rank1,
                                                level1,
                                                rank2,
                                                level2,
                                                result,
                                                context=context,
                                                timeout=timeout)
        await guide.start()
Ejemplo n.º 4
0
 def __init__(self, hero, parent=None, **attributes):
   super().__init__(parent, **attributes)
   db = self.context.bot.db[self.context.guild.id]
   result = db.query(f'SELECT ability, type, unlock, shortDescription, tag, world, link, introduction FROM ability JOIN hero on name=hero WHERE name="{hero}" ORDER BY tag')
   if len(result) == 0:
     raise custom_exceptions.HeroNotFound(string.capwords(hero))
   world = result[0][5]
   if self.parent is None:
     self.parent = HeroWorldMessage(world, None, **attributes)
   self.hero = hero
   self.link = result[0][6]
   self.introduction = result[0][7]
   self.abilities = []
   self.child_emojis = []
   self.ability_emojis = [] # match child_emojis to ability name
   self.extra_info = []
   for ability, abilityType, unlock, shortDescription, tag, _, _, _ in result:
     if tag < -2:
       continue
     elif tag == -2: # melee spell
       self.child_emojis.append(letter_emojis["M"]) 
       self.ability_emojis.append(ability)
       self.extra_info.append(f"{letter_emojis['M']} Melee")
     elif tag == -1: # ranged spell
       self.child_emojis.append(letter_emojis["R"]) 
       self.ability_emojis.append(ability)
       self.extra_info.append(f"{letter_emojis['R']} Ranged")
     else: # other spells
       self.child_emojis.append(num_emojis[tag+1]) 
       self.ability_emojis.append(ability)
       if abilityType == "active":
         activeTag = " (Active)"
       else:
         activeTag = ""
       if unlock:
         unlockTag = f" ({unlock.title()})"
       else:
         unlockTag = ""
       title = f"{num_emojis[tag+1]} {string.capwords(ability)}{activeTag}{unlockTag}"
       self.abilities.append((title, shortDescription, tag))
Ejemplo n.º 5
0
def hero_and_secret(word):
    word = word.lower()
    close_word = find_closest(word, list(transform_synonyms))
    if close_word:
        return transform_synonyms[close_word]
    raise custom_exceptions.HeroNotFound(word.title())
Ejemplo n.º 6
0
def find_hero_from_text(word):
    word = word.lower()
    close_word = find_closest(word, list(hero_synonyms))
    if close_word:
        return hero_synonyms[close_word]
    raise custom_exceptions.HeroNotFound(word.title())