Skip to content

Commit

Permalink
bugfix new feats + fix up jobs module
Browse files Browse the repository at this point in the history
  • Loading branch information
No767 committed Aug 12, 2023
1 parent e0e3ce8 commit 4d38766
Show file tree
Hide file tree
Showing 5 changed files with 1,009 additions and 995 deletions.
2 changes: 1 addition & 1 deletion Bot/Cogs/dev_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async def dispatch_event(self, ctx: commands.Context, event: str) -> None:
Args:
ctx (commands.Context): _description_
"""
self.bot.dispatch(event, ctx.guild)
self.bot.dispatch(event, ctx.guild, ctx.author)
await ctx.send("Dispatched event")

@commands.check_any(commands.is_owner(), is_nat())
Expand Down
116 changes: 58 additions & 58 deletions Bot/Cogs/dictionary.py
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
import orjson
from discord import PartialEmoji, app_commands
from discord.ext import commands
from kumikocore import KumikoCore
from Libs.ui.dictionary import DictPages, JapaneseDictPages
from typing_extensions import Annotated
from yarl import URL


class Dictionary(commands.Cog):
"""Commands to search definitions of words"""

def __init__(self, bot: KumikoCore) -> None:
self.bot = bot
self.session = self.bot.session

@property
def display_emoji(self) -> PartialEmoji:
return PartialEmoji(name="\U0001f4d6")

@commands.hybrid_group(name="define", fallback="english")
@app_commands.describe(query="The word to define")
async def define(
self, ctx: commands.Context, *, query: Annotated[str, commands.clean_content]
) -> None:
"""Define a word from the English dictionary"""
url = URL("https://api.dictionaryapi.dev/api/v2/entries/en") / query
async with self.session.get(url) as r:
data = await r.json(loads=orjson.loads)
if len(data) == 0:
await ctx.send("No results found.")
return
pages = DictPages(data, ctx=ctx)
await pages.start()

@define.command(name="japanese", aliases=["ja", "jp"])
@app_commands.describe(
query="The word to define. This can be both in English or Japanese (romaji works)"
)
async def japanese(
self, ctx: commands.Context, *, query: Annotated[str, commands.clean_content]
) -> None:
"""Get the definition of a word from the Japanese dictionary"""
params = {"keyword": query}

async with self.session.get(
"https://jisho.org/api/v1/search/words", params=params
) as r:
data = await r.json(loads=orjson.loads)
if len(data["data"]) == 0:
await ctx.send("No results found.")
return
pages = JapaneseDictPages(data["data"], ctx=ctx)
await pages.start()


async def setup(bot: KumikoCore) -> None:
await bot.add_cog(Dictionary(bot))
import orjson
from discord import PartialEmoji, app_commands
from discord.ext import commands
from kumikocore import KumikoCore
from Libs.ui.dictionary import DictPages, JapaneseDictPages
from typing_extensions import Annotated
from yarl import URL


class Dictionary(commands.Cog):
"""Commands to search definitions of words"""

def __init__(self, bot: KumikoCore) -> None:
self.bot = bot
self.session = self.bot.session

@property
def display_emoji(self) -> PartialEmoji:
return PartialEmoji(name="\U0001f4d6")

@commands.hybrid_group(name="define", fallback="english")
@app_commands.describe(query="The word to define")
async def define(
self, ctx: commands.Context, *, query: Annotated[str, commands.clean_content]
) -> None:
"""Define a word from the English dictionary"""
url = URL("https://api.dictionaryapi.dev/api/v2/entries/en") / query
async with self.session.get(url) as r:
data = await r.json(loads=orjson.loads)
if "message" in data:
await ctx.send("No results found")
return
pages = DictPages(data, ctx=ctx)
await pages.start()

@define.command(name="japanese", aliases=["ja", "jp"])
@app_commands.describe(
query="The word to define. This can be both in English or Japanese (romaji works)"
)
async def japanese(
self, ctx: commands.Context, *, query: Annotated[str, commands.clean_content]
) -> None:
"""Get the definition of a word from the Japanese dictionary"""
params = {"keyword": query}

async with self.session.get(
"https://jisho.org/api/v1/search/words", params=params
) as r:
data = await r.json(loads=orjson.loads)
if len(data["data"]) == 0:
await ctx.send("No results found.")
return
pages = JapaneseDictPages(data["data"], ctx=ctx)
await pages.start()


async def setup(bot: KumikoCore) -> None:
await bot.add_cog(Dictionary(bot))
Loading

0 comments on commit 4d38766

Please sign in to comment.