Add new jikan cog
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
"""
|
"""
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
"""
|
|
||||||
Some anime-related commands
|
|
||||||
"""
|
|
||||||
|
|
||||||
import discord
|
|
||||||
from discord.ext import commands
|
|
||||||
import random
|
|
||||||
|
|
||||||
import loaddata
|
|
||||||
|
|
||||||
|
|
||||||
class Anime(commands.Cog):
|
|
||||||
def __init__(self, bot):
|
|
||||||
self.bot = bot
|
|
||||||
|
|
||||||
|
|
||||||
@commands.command(name="animepic")
|
|
||||||
async def animemedia(self, ctx):
|
|
||||||
"""
|
|
||||||
Sends a random Anime gif or picture
|
|
||||||
"""
|
|
||||||
|
|
||||||
media_type = random.choice(loaddata.__media_anime__)
|
|
||||||
media = random.choice(media_type)
|
|
||||||
await ctx.send(media)
|
|
||||||
|
|
||||||
|
|
||||||
@commands.command(name="waifupic")
|
|
||||||
async def waifumedia(self, ctx, name: str):
|
|
||||||
"""
|
|
||||||
Sends a random picture or gif of an Anime girl
|
|
||||||
"""
|
|
||||||
girl = name.capitalize()
|
|
||||||
|
|
||||||
if girl == "List":
|
|
||||||
girl_list = ""
|
|
||||||
for key in loaddata.__media_girl__.keys():
|
|
||||||
if not girl_list:
|
|
||||||
girl_list = girl_list + key
|
|
||||||
else:
|
|
||||||
girl_list = girl_list + ", " + key
|
|
||||||
|
|
||||||
await ctx.send(f"Currently listed girls: `{girl_list}`")
|
|
||||||
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
media = random.choice(loaddata.__media_girl__[girl])
|
|
||||||
await ctx.send(media)
|
|
||||||
except KeyError as error:
|
|
||||||
text = (
|
|
||||||
f"Girl `{girl}` not found in database!\n"
|
|
||||||
"It probably sucks...")
|
|
||||||
await ctx.send(text)
|
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
|
||||||
bot.add_cog(Anime(bot))
|
|
||||||
69
cogs/jikan.py
Normal file
69
cogs/jikan.py
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
"""
|
||||||
|
Jikan is an unofficial api to access data from myanimelist
|
||||||
|
https://jikanpy.readthedocs.io/en/latest/
|
||||||
|
"""
|
||||||
|
|
||||||
|
import discord
|
||||||
|
from discord.ext import commands
|
||||||
|
from jikanpy import Jikan
|
||||||
|
|
||||||
|
|
||||||
|
jikan = Jikan()
|
||||||
|
|
||||||
|
|
||||||
|
class Jikan(commands.Cog):
|
||||||
|
def __init__(self, bot):
|
||||||
|
self.bot = bot
|
||||||
|
|
||||||
|
@commands.group(name="anime")
|
||||||
|
async def anime(self, ctx):
|
||||||
|
if ctx.invoked_subcommand is None:
|
||||||
|
await ctx.invoke(self.bot.get_command("help"), query="anime")
|
||||||
|
|
||||||
|
|
||||||
|
@anime.command(name="query")
|
||||||
|
async def query(self, ctx, *query: str):
|
||||||
|
"""
|
||||||
|
Query some information about an anime
|
||||||
|
"""
|
||||||
|
search = jikan.search("anime", query)
|
||||||
|
results = search.get("results")
|
||||||
|
|
||||||
|
#await ctx.send("Which one of these do you mean?")
|
||||||
|
|
||||||
|
#anime_list = ""
|
||||||
|
#for i in range(5):
|
||||||
|
# anime_list += f'{i+1}: {results[i].get("title")}\n'
|
||||||
|
|
||||||
|
#await ctx.send(anime_list)
|
||||||
|
|
||||||
|
#reply = await commands.wait_for('message', timeout=30.0)
|
||||||
|
#top = results[reply+1]
|
||||||
|
top = results[0]
|
||||||
|
|
||||||
|
embed = discord.Embed(colour=discord.Colour.blue())
|
||||||
|
embed.set_thumbnail(url=top.get("image_url"))
|
||||||
|
|
||||||
|
embed.add_field(name="Title", value=top.get("title"), inline=True)
|
||||||
|
embed.add_field(name="URL", value=f'[MAL]({top.get("url")})', inline=True)
|
||||||
|
embed.add_field(name="Episodes", value=top.get("episodes"), inline=True)
|
||||||
|
embed.add_field(name="Airing", value=top.get("airing"), inline=True)
|
||||||
|
embed.add_field(name="Synopsis", value=top.get("synopsis"), inline=True)
|
||||||
|
|
||||||
|
await ctx.send(embed=embed)
|
||||||
|
|
||||||
|
|
||||||
|
@commands.group(name="manga")
|
||||||
|
async def manga(self, ctx):
|
||||||
|
if ctx.invoked_subcommand is None:
|
||||||
|
await ctx.invoke(self.bot.get_command("help"), query="manga")
|
||||||
|
|
||||||
|
|
||||||
|
@commands.group(name="character", aliases=["char"])
|
||||||
|
async def character(self, ctx):
|
||||||
|
if ctx.invoked_subcommand is None:
|
||||||
|
await ctx.invoke(self.bot.get_command("help"), query="character")
|
||||||
|
|
||||||
|
|
||||||
|
def setup(bot):
|
||||||
|
bot.add_cog(Jikan(bot))
|
||||||
@@ -2,3 +2,4 @@ discord.py[voice]
|
|||||||
youtube-dl
|
youtube-dl
|
||||||
praw
|
praw
|
||||||
argparse
|
argparse
|
||||||
|
jikanpy
|
||||||
|
|||||||
Reference in New Issue
Block a user