re designed kanji search
This commit is contained in:
parent
8f7bdf64e2
commit
31581fc6a6
|
@ -38,9 +38,9 @@ class Kanji(commands.Cog):
|
|||
node = response.nodes[self.activeObject.page]
|
||||
|
||||
embed = discord.Embed(
|
||||
title = node.kanji,
|
||||
title = node.meaning,
|
||||
url = node.url,
|
||||
description = node.meaning,
|
||||
description = f"{node.strokes} strokes",
|
||||
colour = 0x56d926
|
||||
)
|
||||
|
||||
|
@ -50,7 +50,8 @@ class Kanji(commands.Cog):
|
|||
embed.add_field(name="On", value="、 ".join(node.on), inline=False)
|
||||
|
||||
embed.add_field(name=f"Radical: {node.radical[0]}", value=node.radical[1], inline=False)
|
||||
embed.add_field(name=f"{node.strokes} strokes", value="\u200b", inline=False)
|
||||
|
||||
embed.set_thumbnail(url=node.image_url)
|
||||
|
||||
embed.set_footer(text=f"Jōyō kanji (Grade {node.grade}) | JLPT level {node.jlpt}\t\t{self.activeObject.page + 1}/{self.activeObject.total_pages}")
|
||||
|
||||
|
@ -86,11 +87,19 @@ class Kanji(commands.Cog):
|
|||
if kanji is None:
|
||||
return
|
||||
|
||||
embed = discord.Embed(
|
||||
title = "Loading...",
|
||||
description = "This might take a few seconds",
|
||||
colour = 0x56d926
|
||||
)
|
||||
|
||||
message = await ctx.send(embed=embed)
|
||||
|
||||
kanji = kanji[:5]
|
||||
|
||||
self.activeObject = JishoKanjiObject(kanji, ctx.author.id)
|
||||
embed = await self.createEmbed()
|
||||
message = await ctx.send(embed=embed)
|
||||
await message.edit(embed=embed)
|
||||
self.latestMessage = message.id
|
||||
|
||||
if self.activeObject.total_pages > 1:
|
||||
|
|
|
@ -95,6 +95,7 @@ class JishoKanjiNode():
|
|||
self.grade = ""
|
||||
self.jlpt = ""
|
||||
self.strokes = ""
|
||||
self.image_url = ""
|
||||
|
||||
|
||||
class JishoKanji():
|
||||
|
@ -158,4 +159,17 @@ class JishoKanji():
|
|||
self.nodes[-1].jlpt = info.findChild("div", {"class": "jlpt"}, recursive=True).findChild("strong").string
|
||||
|
||||
# Strokes
|
||||
self.nodes[-1].strokes = info.findChild("div", {"class": "kanji-details__stroke_count"}, recursive=True).findChild("strong").string
|
||||
self.nodes[-1].strokes = info.findChild("div", {"class": "kanji-details__stroke_count"}, recursive=True).findChild("strong").string
|
||||
|
||||
# Stroke order diagram
|
||||
r = requests.get(url=("https://jitenon.com/kanji/" + urllib.parse.quote_plus(self.nodes[-1].kanji)), headers=HEADER)
|
||||
if r.status_code != 200:
|
||||
continue
|
||||
|
||||
strokediag = BeautifulSoup(r.text, features="html.parser")
|
||||
image_url = strokediag.find("div", {"class": "kanji_main ChangeElem_Panel"}).findChild("img")["src"]
|
||||
image_url = "https:" + image_url
|
||||
image_url = image_url.replace("shotai3", "shotai2")
|
||||
self.nodes[-1].image_url = image_url
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue