async def build_embed(self) -> discord.Embed: embed = Embed( title="Guess your character!", description=("```swift\n" f"Question-Number : {self.questions}\n" f"Progression-Level: {self.aki.progression}\n```\n" f"{self.build_bar()}"), ) embed.add_field(name="- Question -", value=self.aki.question) embed.set_footer( text="Figuring out the next question | This may take a second") return embed
async def ping(self, ctx): """Get the Latency""" import time starttime = time.time() msg = await ctx.send(":ping_pong: Ping... :ping_pong:") async with ctx.channel.typing(): e = Embed( title=":ping_pong: Pong! :ping_pong:", description= f"Heartbeat : {round(self.bot.latency * 1000, 2)} ms", ) endtime = time.time() difference = float(int(starttime - endtime)) e.add_field(name=":inbox_tray: Script Speed :outbox_tray:", value=f"{difference}ms") e.set_image(url=await self.bot.get_random_image_from_tag( "ping pong anime")) await msg.edit(content="", embed=e)
async def get_waifu(self) -> Tuple[Embed, str]: """Returns a random waifu from the api :return: tuple of (Embed, name) :rtype: Tuple[Embed, str] """ waifu = await self.bot.dagpi.waifu() pic = waifu["display_picture"] name = waifu["name"] likes_rank = waifu["like_rank"] trash_rank = waifu["trash_rank"] anime = waifu["appearances"][0]["name"] url = waifu["url"] e = Embed(title=name) e.add_field(name="**Anime**", value=anime, inline=True) e.add_field(name="**:heartbeat:**", value=likes_rank, inline=True) e.add_field(name="**:wastebasket:**", value=trash_rank, inline=True) e.add_field(name="**:link:**", value=f"[Know More]({url})") e.set_image(url=pic) e.set_footer(text="React with any emoji in 30 sec to claim him/her") return e, name
async def mangasearch(self, ctx: commands.Context, *, manga_name: str): """Searches Manga from MAL and displays the first 10 search result.""" search = MangaSearch(str(manga_name).strip(" ").lower()) search_results = search.results[:10] description = "" for i, k in enumerate(search_results): description += f"{i+1}. **{k.title}**\n" e1 = Embed( title=f"Manga search results for {str(manga_name).capitalize()}", description=description, timestamp=ctx.message.created_at, ) e1.set_footer( text= f"Showing 10 results out of {len(search.results)} | Use the recations of this message to paginate", icon_url= "https://cdn.myanimelist.net/images/event/15th_anniversary/top_page/item7.png", ) embeds = [e1] for i in search_results: e = Embed(title=i.title, description=i.synopsis, timestamp=ctx.message.created_at) if i.score: e.add_field(name="**Score**", value=f"{i.score} :star:") if i.type: e.add_field(name="**Manga Type**", value=i.type) if i.url: e.add_field(name="**MAL Url**", value=f"[CLICK HERE]({i.url})") if i.mal_id: e.add_field(name="**MAL ID**", value=i.mal_id) if i.image_url: e.set_image(url=i.image_url) e.set_footer(text=f"{i.title} | {i.mal_id} | {i.score} stars", icon_url=i.image_url) embeds.append(e) paginator = EmbedPaginator(entries=embeds, ctx=ctx) await paginator.start()
async def animesearch(self, ctx: commands.Context, *, anime_name: str): """Searches Anime from MAL and displays the first 10 search result.""" search = AnimeSearch(str(anime_name).strip(" ").lower()) search_results = search.results[:10] description = "" for i, k in enumerate(search_results): description += f"{i+1}. **{k.title}**\n" e1 = Embed( title=f"Anime search results for {str(anime_name).capitalize()}", description=description[:4096], timestamp=ctx.message.created_at, ) e1.set_footer( text= f"Showing 10 results out of {len(search.results)} | Use the reactions of this message to paginate", icon_url=LinksAndVars.mal_logo.value, ) embeds = [e1] for i in search_results: e = Embed(title=i.title, description=i.synopsis, timestamp=ctx.message.created_at) if i.score: e.add_field(name="**Score**", value=f"{i.score} :star:") if i.type: e.add_field(name="**Anime Type**", value=i.type) if i.url: e.add_field(name="**MAL Url**", value=f"[CLICK HERE]({i.url})") if i.mal_id: e.add_field(name="**MAL ID**", value=i.mal_id) # if i.image_url: # e.set_image(url=i.image_url) #later it the comment will be removed e.set_footer(text=f"{i.title} | {i.mal_id} | {i.score} stars", icon_url=i.image_url) embeds.append(e) paginator = EmbedPaginator(entries=embeds, ctx=ctx) await paginator.start()
async def aboutmanga(self, ctx: commands.Context, mal_id: int): """Displays about the manga using the MAL MANGA ID. get it by using mangasearch command.""" message = await ctx.send(":mag: Searching...", delete_after=5) manga = Manga(int(mal_id)) embeds = [] e = Embed( title=manga.title, description=manga.synopsis[:4096], timestamp=ctx.message.created_at, ) if manga.title_japanese: e.add_field( name=":japanese_castle: **Title in Japanese**", value=f"{manga.title_japanese}", ) if manga.title_synonyms: e.add_field(name="**Title Synonyms**", value=" ,".join(manga.title_synonyms)) if manga.score: e.add_field(name=":star: **Score**", value=f"{manga.score} :star:") if manga.type: e.add_field(name=":dividers: **Type**", value=manga.type) if manga.url: e.add_field(name=":link: **MAL Url**", value=f"[CLICK HERE]({manga.url})") if manga.mal_id: e.add_field(name=":id: **MAL ID**", value=manga.mal_id) if manga.status: e.add_field(name=":hourglass_flowing_sand: **Status**", value=manga.status) if manga.genres: e.add_field(name=":arrow_right: **Genre**", value=" ,".join(manga.genres)) if manga.rank: e.add_field(name=":trophy: **Rank**", value=manga.rank) if manga.popularity: e.add_field(name="**Popularity**", value=f"#{manga.popularity}") if manga.chapters: e.add_field(name=":book: **No. of Chapters**", value=manga.chapters) if manga.volumes: e.add_field(name=":books: **Volumes**", value=manga.volumes) if manga.authors: e.add_field(name=":pen_fountain: **Author(s)**", value="\n・".join(manga.authors)) if manga.published: e.add_field(name=":map: **Published**", value=manga.published) if manga.characters and len(format_manga_characters( manga.characters)) <= 600: e.add_field(name="**Characters**", value=format_manga_characters(manga.characters)) else: if manga.characters: e1 = Embed( title="Characters", description=format_manga_characters( manga.characters)[:4096], ) e1.set_footer( text= f"{manga.title_japanese} | {manga.mal_id} | {manga.score} stars", icon_url=manga.image_url, ) embeds.append(e1) if (manga.related_manga and len(format_related_anime_manga(manga.related_manga)) < 1024): e.add_field( name="**Related Manga**", value=format_related_anime_manga(manga.related_manga), ) else: if manga.related_manga: e1 = Embed( title="Related Manga", description=format_related_anime_manga( manga.related_manga)[:4096], ) e1.set_footer( text= f"{manga.title_japanese} | {manga.mal_id} | {manga.score} stars", icon_url=manga.image_url, ) embeds.append(e1) if manga.image_url: e.set_image(url=manga.image_url) e.set_footer( text= f"{manga.title_japanese} | {manga.mal_id} | {manga.score} stars", icon_url=manga.image_url, ) paginator = EmbedPaginator(entries=[e] + embeds, ctx=ctx) await paginator.start()
async def aboutanime(self, ctx: commands.Context, mal_id: int): """Displays about the anime using the MAL ANIME ID. get it by using animesearch command.""" await ctx.send(":mag: Searching...", delete_after=5) anime = Anime(int(mal_id)) embeds = [] e = Embed( title=anime.title, description=anime.synopsis[:4096], timestamp=ctx.message.created_at, ) if anime.title_japanese: e.add_field( name=":japanese_castle: **Title in Japanese**", value=f"{anime.title_japanese}", ) if anime.title_synonyms: e.add_field(name="**Title Synonyms**", value=" ,".join(anime.title_synonyms)) if anime.score: e.add_field(name=":star: **Score**", value=f"{anime.score} :star:") if anime.type: e.add_field(name=":dividers: **Type**", value=anime.type) if anime.url: e.add_field(name=":link: **MAL Url**", value=f"[CLICK HERE]({anime.url})") if anime.mal_id: e.add_field(name=":id: **MAL ID**", value=anime.mal_id) if anime.status: e.add_field(name=":hourglass_flowing_sand: **Status**", value=anime.status) if anime.genres: e.add_field(name=":arrow_right: **Genre**", value=" ,".join(anime.genres)) if anime.rank: e.add_field(name=":trophy: **Rank**", value=anime.rank) if anime.popularity: e.add_field(name="**Popularity**", value=f"#{anime.popularity}") if anime.episodes: e.add_field(name=":minidisc: **No. of Episodes**", value=anime.episodes) if anime.premiered: e.add_field(name="**Premire(d)**", value=anime.premiered) if anime.aired: e.add_field(name=":calendar_spiral: **Air(ed/ing)**", value=anime.aired) if anime.broadcast: e.add_field(name="**Broadcast**", value=anime.broadcast) if anime.producers: e.add_field(name="**Producers**", value=" ,".join(anime.producers)) if anime.licensors: e.add_field(name="**Licensors**", value=" ,".join(anime.licensors)) if anime.studios: e.add_field(name=":microphone2: **Studios**", value=" ,".join(anime.studios)) if anime.source: e.add_field(name=":information_source: **Source**", value=anime.source) if anime.duration: e.add_field(name=":stopwatch: **Duration**", value=anime.duration) if anime.rating: e.add_field(name="**Rating**", value=anime.rating) if (anime.related_anime and len(format_related_anime_manga(anime.related_anime)) < 1024): e.add_field( name="**Related Anime**", value=format_related_anime_manga(anime.related_anime), ) else: if anime.related_anime: e1 = Embed( title="Related Anime", description=format_related_anime_manga( anime.related_anime)[:4096], ) e1.set_footer( text= f"{anime.title_japanese} | {anime.mal_id} | {anime.score} stars", icon_url=anime.image_url, ) embeds.append(e1) if anime.opening_themes and len(" ,".join( anime.opening_themes)) <= 1000: e.add_field( name=":play_pause: **Opening Theme(s)**", value="・\n".join(anime.opening_themes), ) else: if anime.opening_themes: e1 = Embed( title=":play_pause: Opening Theme(s)", description="・\n".join(anime.opening_themes)[:4096], ) e1.set_footer( text= f"{anime.title_japanese} | {anime.mal_id} | {anime.score} stars", icon_url=anime.image_url, ) embeds.append(e1) if anime.ending_themes and len(" ,".join(anime.ending_themes)) <= 1000: e.add_field( name=":stop_button: **Ending Theme(s)**", value="・\n".join(anime.ending_themes), ) else: if anime.ending_themes: e1 = Embed( title=":stop_button: Ending Theme(s)", description="・\n".join(anime.ending_themes)[:4096], ) e1.set_footer( text= f"{anime.title_japanese} | {anime.mal_id} | {anime.score} stars", icon_url=anime.image_url, ) embeds.append(e1) if anime.staff and len(format_staff(anime.staff)) <= 700: e.add_field(name=":factory_worker: Staff", value=format_staff(anime.staff)) else: if anime.staff: e1 = Embed( title=":factory_worker: Staff", description=format_staff(anime.staff)[:4096], ) e1.set_footer( text= f"{anime.title_japanese} | {anime.mal_id} | {anime.score} stars", icon_url=anime.image_url, ) embeds.append(e1) if anime.characters and len(format_characters( anime.characters)) <= 600: e.add_field(name="**Characters**", value=format_characters(anime.characters)) else: if anime.characters: e1 = Embed( title="Characters", description=format_characters(anime.characters)[:4096], ) e1.set_footer( text= f"{anime.title_japanese} | {anime.mal_id} | {anime.score} stars", icon_url=anime.image_url, ) embeds.append(e1) if anime.image_url: e.set_image(url=anime.image_url) e.set_footer( text= f"{anime.title_japanese} | {anime.mal_id} | {anime.score} stars", icon_url=anime.image_url, ) paginator = EmbedPaginator(entries=[e] + embeds, ctx=ctx) await paginator.start()
async def create_giveaway(self, ctx: commands.Context): """Allowes you to to create giveaway by answering some simple questions!""" # Ask Questions embed = Embed( title="Giveaway Time!! \U00002728", description= "Time for a new Giveaway. Answer the following questions in 25 seconds each for the Giveaway", color=ctx.author.color, ) await ctx.send(embed=embed) questions = [ "In Which channel do you want to host the giveaway?", "For How long should the Giveaway be hosted ? type number followed (s|m|h|d)", "What is the Prize?", "What role should a person must have in order to enter? If no roles required then type `none`", "Tasks that the person should do in order to participate? If no tasks then type `none`", ] answers = [] def check(m): return m.author == ctx.author and m.channel == ctx.channel for i, question in enumerate(questions): embed = Embed(title=f"Question {i+1}", description=question) await ctx.send(embed=embed) try: message = await self.bot.wait_for("message", timeout=25, check=check) except TimeoutError: await ctx.send("You didn't answer the questions in Time") return answers.append(message.content) # Check if Channel Id is valid try: channel_id = int(answers[0][2:-1]) except: await ctx.send( f"The Channel provided was wrong. The channel provided should be like {ctx.channel.mention}" ) return channel = self.bot.get_channel(channel_id) # Check if the role is valid role = answers[3] if role.lower() in ("none", "no", "no roles"): role = None else: try: int(answers[3][3:-1]) except: i = ctx.guild.roles for j in i: if j.name in ("@everyone", "@here"): i.remove(j) bot_roles = choice(i) await ctx.send( f"The role provided was wrong. The role should be like {bot_roles.mention}" ) return time_ends = convert(answers[1]) * 1000 # Check if Time is valid if time == -1: await ctx.send("The Time format was wrong") return if time == -2: await ctx.send("The Time was not conventional number") return prize = answers[2] task = answers[4] if task.lower() in ("none", "no", "no task"): task = None embed = Embed( title="**:tada::tada: Giveaway Time !! :tada::tada:**", description=f":gift: Win a **{prize}** today", colour=0x00FFFF, ) embed.set_author(name=ctx.author.display_name, icon_url=ctx.author.display_avatar.url) embed.set_image(url=self.giveaway_image) embed.add_field( name="Giveway ends in", value= f"{format_relative(discord.utils.utcnow() + timedelta(milliseconds=time_ends))} | [Timer]({LinksAndVars.website.value}/giveaway_timer.html?start={int(time.time() * 1000)}&length={time_ends})", ) if role: embed.add_field(name="Role Required", value=f"{role}") if task: embed.add_field(name="\U0001f3c1 Tasks", value=task) newMsg = await channel.send(embed=embed) embed.set_footer(text=f"Giveaway ID: {newMsg.id}") await newMsg.edit(embed=embed) await newMsg.add_reaction(discord.PartialEmoji(name="\U0001f389")) await ctx.send( f"Your giveaway will be hosted in {channel.mention} and will last for {answers[1]}\n{newMsg.jump_url}" ) await self.create_timer_for_giveaway( newMsg, (discord.utils.utcnow() + timedelta(milliseconds=time_ends)).timestamp())
async def determine_winner( self, giveaway_id: discord.Message, bot: commands.Bot) -> Union[str, discord.Member]: """Determines winner :param giveaway_id: The giveaway id :type giveaway_id: discord.Message :param bot: The bot class :type bot: commands.Bot :return: The winner details :rtype: Union[str, discord.Member] """ reactions = discord.utils.find( lambda a: str(a) == str(discord.PartialEmoji(name="\U0001f389")), giveaway_id.reactions) if reactions is None: return "The channel or ID mentioned was incorrect" try: giveaway_config = await self.get_giveaway_config( giveaway_id. id if not isinstance(giveaway_id.id, int) else giveaway_id) except AttributeError as e: return str(e) reacted_users = await reactions.users().flatten() if discord.utils.get(reacted_users, id=bot.application_id): reacted_users.remove( discord.utils.get(reacted_users, id=bot.application_id)) if giveaway_config.role_required is not None and len( reacted_users) <= 0: reacted_users = list( filter( lambda a: discord.utils.get( a.roles, id=int( giveaway_config.role_required.lstrip('<@&').lstrip( '<&').rstrip('>'))) is not None, reacted_users)) if len(reacted_users) <= 0: emptyEmbed = Embed( title= "\U0001f389\U0001f389 Giveaway Time !! \U0001f389\U0001f389", description="\U0001f381 Win a Prize today") emptyEmbed.set_author( name=giveaway_config.host.display_name, icon_url=giveaway_config.host.display_avatar.url) emptyEmbed.add_field( name="No winners", value="Not enough participants to determine the winners", ) emptyEmbed.set_image(url=self.giveaway_image) emptyEmbed.set_footer(text="No one won the Giveaway") await giveaway_id.edit(embed=emptyEmbed) return f"No one won the giveaway! As there were not enough participants!\n{giveaway_config.jump_url}" winner = choice(reacted_users) winnerEmbed = giveaway_config.embed if discord.utils.find( lambda a: a["name"].lower() == "\U0001f389 Winner \U0001f389". lower(), giveaway_config.embed_dict["fields"]) is None: winnerEmbed.add_field(name="\U0001f389 Winner \U0001f389", value=winner.mention, inline=False) await giveaway_id.edit(embed=winnerEmbed) return winner