import abc import collections.abc as collections import dataclasses import datetime import json import typing import alluka import hikari import markdownify # pyright: reportMissingTypeStubs=warning import tanjun import yuyo from .. import utility docs_group = tanjun.slash_command_group("docs", "Search relevant document sites.") _T = typing.TypeVar("_T") _CoroT = typing.Coroutine[typing.Any, typing.Any, _T] _DocIndexT = typing.TypeVar("_DocIndexT", bound="DocIndex") _MessageCommandT = typing.TypeVar("_MessageCommandT", bound=tanjun.MessageCommand[typing.Any]) _SlashCommandT = typing.TypeVar("_SlashCommandT", bound=tanjun.SlashCommand[typing.Any]) HIKARI_PAGES = "https://www.hikari-py.dev" SAKE_PAGES = "https://sake.cursed.solutions" TANJUN_PAGES = "https://tanjun.cursed.solutions" YUYO_PAGES = "https://yuyo.cursed.solutions" SPECIAL_KEYS: frozenset[str] = frozenset(("df", "tf", "docs")) @dataclasses.dataclass(slots=True) class DocEntry:
from hikari.embeds import Embed from hikari.internal.data_binding import JSONDecodeError import tanjun import hikari import requests import difflib poke_group = tanjun.slash_command_group("pokemon", "Info about Pokemons") @poke_group.with_command @tanjun.with_str_slash_option("nature", "Nature of pokemon.") @tanjun.as_slash_command("nature", "Get nature information of a pokemon.") async def pokemon_nature(ctx:tanjun.abc.SlashContext, nature:str): possibilities = ["adamant","bashful","bold","brave","calm","careful","docile","gentle","hardy","hasty","impish","jolly","lax","lonely","mild","modest","naive","naughty","quiet","quirky","rash","relaxed","sassy","serious","timid"] matches = difflib.get_close_matches( nature.lower(), possibilities, n=1, cutoff=0.3) pokemondata = (requests.get("https://pokeapi.co/api/v2/nature/{}/".format(matches[0].lower()))).json() move_preference = pokemondata['move_battle_style_preferences'] embed= hikari.Embed( title = pokemondata["name"].title(), color = hikari.Color(0xffcb05) ) embed.add_field(name="Decreased Stat", value = pokemondata['decreased_stat']['name'].title(), inline=True) embed.add_field(name="Increased Stat", value = pokemondata['increased_stat']['name'].title(), inline=True) embed.add_field(name="Likes Flavor", value = pokemondata['likes_flavor']['name'].title(), inline=True) embed.add_field(name="Hates Flavor", value = pokemondata['hates_flavor']['name'].title(), inline=True)
This is matched case-sensitively. Returns ------- typing.Optional[collections.Sequence[str]] The references to the type if found else `None`. """ if result := self._object_paths_to_uses.get(path): return result if alias := self._aliases.get(path): return self._object_paths_to_uses[alias] reference_group = tanjun.slash_command_group( "references", "Find the references for a type in a library") @dataclasses.dataclass(frozen=True, slots=True) class _IndexCommand: index: ReferenceIndex library_repr: str async def __call__( self, ctx: tanjun.abc.Context, path: str, absolute: bool, public: bool, component_client: alluka.Injected[yuyo.ComponentClient], ) -> None:
) await ctx.respond("Starting message deletes", component=utility.delete_row(ctx)) async for messages in iterator: await ctx.rest.delete_messages(ctx.channel_id, *messages) break try: await ctx.edit_last_response(content="Cleared messages.", component=utility.delete_row(ctx), delete_after=2) except hikari.NotFoundError: await ctx.respond(content="Cleared messages.", component=utility.delete_row(ctx), delete_after=2) ban_group = ( tanjun.slash_command_group("ban", "Ban commands") .add_check(tanjun.checks.GuildCheck()) .add_check(tanjun.checks.AuthorPermissionCheck(hikari.Permissions.BAN_MEMBERS)) .add_check(tanjun.checks.OwnPermissionCheck(hikari.Permissions.BAN_MEMBERS)) ) def get_top_role( role_ids: collections.Sequence[hikari.Snowflake], roles: collections.Mapping[hikari.Snowflake, hikari.Role] ) -> hikari.Role | None: try: next(iter(sorted(((role.position, role) for role in map(roles.get, role_ids) if role), reverse=True)))[1] except StopIteration: return None @dataclasses.dataclass(slots=True)
from hikari.embeds import Embed import tanjun import hikari import requests mtg_group = tanjun.slash_command_group("mtg", "Info about MTG cards.") @mtg_group.with_command @tanjun.with_str_slash_option("card", "Card to pull up.") @tanjun.as_slash_command("card", "Look up a certain card.") async def mtg_card(ctx:tanjun.abc.SlashContext, card:str): try: mtgdata = (requests.get("https://api.magicthegathering.io/v1/cards?name={}&pageSize=1&contains=imageUrl".format(card.lower()))).json() card = mtgdata.get("cards")[0] await ctx.respond(card["imageUrl"]) except IndexError: await ctx.respond("Please double check the spelling of the card.") @mtg_group.with_command @tanjun.with_str_slash_option("card", "Card to pull up.") @tanjun.as_slash_command("rulings", "Look up cards ruling.") async def mtg_rulings(ctx:tanjun.abc.SlashContext, card:str): try:
import tanjun import hikari import random import typing dice_group = tanjun.slash_command_group("roll", "Roll a dice/coin.") @dice_group.with_command @tanjun.as_slash_command("d20", "Roll a d20") async def roll_d20(ctx: tanjun.abc.SlashContext) -> None: roll = random.randint(1, 20) await ctx.respond("**" + ctx.member.display_name + "**" + " rolled a " + str(roll) + "!") @dice_group.with_command @tanjun.as_slash_command("d6", "Roll a d6") async def roll_d6(ctx: tanjun.abc.SlashContext) -> None: roll = random.randint(1, 6) await ctx.respond("**" + ctx.member.display_name + "**" + " rolled a " + str(roll) + "!") @dice_group.with_command @tanjun.as_slash_command("coin", "Flip a coin") async def flip_coin(ctx: tanjun.abc.SlashContext) -> None: coinflip = ['Heads', 'Tails']