@@ -28,12 +28,9 @@ async def fetch_manga(self, manga_name: str):
28
28
except Exception as e :
29
29
raise e
30
30
31
- @commands .command (
32
- name = "manga" ,
33
- help = "Fetch manga information from MyAnimeList. \n Usage: `manga Lycoris Recoil` or `anime 135455`." ,
34
- )
35
- async def base_manga (self , ctx : commands .Context , * , manga_name : str ):
31
+ async def build_manga_embed (self , manga_name ):
36
32
url = f"https://api.jikan.moe/v4/manga?q={ manga_name } &limit=1"
33
+ embed = nextcord .Embed (color = EMBED_COLOR )
37
34
try :
38
35
manga = await self .fetch_manga (manga_name )
39
36
if manga :
@@ -66,113 +63,81 @@ async def base_manga(self, ctx: commands.Context, *, manga_name: str):
66
63
embed .description += f"\n > **Authors**: { authors } "
67
64
embed .set_thumbnail (url = cover_image )
68
65
embed .set_footer (text = str (mal_id ))
66
+ return embed
69
67
70
68
else :
71
- embed = nextcord .Embed (
72
- description = ":x: Manga not found." ,
73
- color = ERROR_COLOR ,
74
- )
69
+ embed .description = ":x: Manga not found."
70
+ embed .color = ERROR_COLOR
75
71
76
72
except Exception as e :
77
73
embed = nextcord .Embed (description = str (e ), color = ERROR_COLOR )
78
- await ctx . reply ( embed = embed , mention_author = False )
74
+ return embed
79
75
80
- @nextcord .slash_command (
81
- name = "manga" , description = "MyAnimeList manga information commands."
82
- )
83
- async def manga (
84
- self ,
85
- interaction : nextcord .Interaction ,
86
- ):
87
- pass
88
-
89
- @manga .subcommand (
90
- name = "info" , description = "Fetch manga information from MyAnimeList."
91
- )
92
- async def slash_manga_info (
93
- self ,
94
- interaction : Interaction ,
95
- manga_name : str = SlashOption (description = "Name of the manga" ),
96
- ):
97
- await interaction .response .defer ()
76
+ async def build_mangasyn_embed (self , manga_name ):
98
77
url = f"https://api.jikan.moe/v4/manga?q={ manga_name } &limit=1"
78
+ embed = nextcord .Embed (color = EMBED_COLOR )
99
79
try :
100
80
manga = await self .fetch_manga (manga_name )
101
81
if manga :
102
82
title = manga .get ("title" )
103
- chapters = manga .get ("chapters" )
104
- volumes = manga .get ("volumes" )
105
- score = manga .get ("score" )
106
- published = manga .get ("published" , {}).get ("string" )
107
83
english_title = manga .get ("title_english" )
108
- status = manga .get ("status" )
109
84
cover_image = manga ["images" ]["jpg" ]["image_url" ]
110
85
url = manga .get ("url" )
111
86
mal_id = manga .get ("mal_id" )
112
- genres = ", " .join ([genre ["name" ] for genre in manga .get ("genres" , [])])
113
- authors = " & " .join (
114
- [author ["name" ] for author in manga .get ("authors" , [])]
115
- )
87
+ synopsis = manga .get ("synopsis" )
88
+ if len (synopsis ) > 700 :
89
+ synopsis = synopsis [:700 ] + "..."
116
90
117
91
embed = nextcord .Embed (title = title , url = url , color = EMBED_COLOR )
118
92
embed .description = ""
119
93
if english_title and english_title != title :
120
94
embed .description += f"-# { english_title } \n "
121
- if status != "Publishing" :
122
- embed .description += f"\n > **Chapters**: { chapters } "
123
- embed .description += f"\n > **Volumes**: { volumes } "
124
- embed .description += f"\n > **Score**: { score } "
125
- embed .description += f"\n > **Status**: { status } "
126
- embed .description += f"\n > **Genres**: { genres } "
127
- embed .description += f"\n > **Published**: { published } "
128
- embed .description += f"\n > **Authors**: { authors } "
95
+ embed .description += f"\n { synopsis } "
129
96
embed .set_thumbnail (url = cover_image )
130
97
embed .set_footer (text = str (mal_id ))
98
+ return embed
131
99
132
100
else :
133
- embed = nextcord .Embed (
134
- description = ":x: Manga not found." ,
135
- color = ERROR_COLOR ,
136
- )
101
+ embed .description = ":x: Manga not found."
102
+ embed .color = ERROR_COLOR
103
+ return embed
137
104
138
105
except Exception as e :
139
106
embed = nextcord .Embed (description = str (e ), color = ERROR_COLOR )
107
+ return embed
108
+
109
+ @commands .command (
110
+ name = "manga" ,
111
+ help = "Fetch manga information from MyAnimeList. \n Usage: `manga Lycoris Recoil` or `anime 135455`." ,
112
+ )
113
+ async def base_manga (self , ctx : commands .Context , * , manga_name : str ):
114
+ embed = await self .build_manga_embed (manga_name )
115
+ await ctx .reply (embed = embed , mention_author = False )
116
+
117
+ @nextcord .slash_command (
118
+ name = "manga" , description = "MyAnimeList manga information commands."
119
+ )
120
+ async def manga (self , interaction : nextcord .Interaction ):
121
+ pass
122
+
123
+ @manga .subcommand (
124
+ name = "info" , description = "Fetch manga information from MyAnimeList."
125
+ )
126
+ async def slash_manga_info (
127
+ self ,
128
+ interaction : Interaction ,
129
+ manga_name : str = SlashOption (description = "Name of the manga" ),
130
+ ):
131
+ await interaction .response .defer ()
132
+ embed = await self .build_manga_embed (manga_name )
140
133
await interaction .send (embed = embed )
141
134
142
135
@commands .command (
143
136
aliases = ["mangaplot" , "mangasyn" ],
144
137
help = "Fetch a manga's summary from MyAnimeList. \n Usage: `mangasyn Lycoris Recoil` or `mangasyn 50709`." ,
145
138
)
146
139
async def manga_synopsis (self , ctx : commands .Context , * , manga_name : str ):
147
- url = f"https://api.jikan.moe/v4/manga?q={ manga_name } &limit=1"
148
- try :
149
- manga = await self .fetch_manga (manga_name )
150
- if manga :
151
- title = manga .get ("title" )
152
- english_title = manga .get ("title_english" )
153
- cover_image = manga ["images" ]["jpg" ]["image_url" ]
154
- url = manga .get ("url" )
155
- mal_id = manga .get ("mal_id" )
156
- synopsis = manga .get ("synopsis" )
157
- if len (synopsis ) > 700 :
158
- synopsis = synopsis [:700 ] + "..."
159
-
160
- embed = nextcord .Embed (title = title , url = url , color = EMBED_COLOR )
161
- embed .description = ""
162
- if english_title and english_title != title :
163
- embed .description += f"-# { english_title } \n "
164
- embed .description += f"\n { synopsis } "
165
- embed .set_thumbnail (url = cover_image )
166
- embed .set_footer (text = str (mal_id ))
167
-
168
- else :
169
- embed = nextcord .Embed (
170
- description = ":x: Manga not found." ,
171
- color = ERROR_COLOR ,
172
- )
173
-
174
- except Exception as e :
175
- embed = nextcord .Embed (description = str (e ), color = ERROR_COLOR )
140
+ embed = await self .build_mangasyn_embed (manga_name )
176
141
await ctx .reply (embed = embed , mention_author = False )
177
142
178
143
@manga .subcommand (
@@ -184,37 +149,7 @@ async def slash_manga_synopsis(
184
149
manga_name : str = SlashOption (description = "Name of the manga" ),
185
150
):
186
151
await interaction .response .defer ()
187
- url = f"https://api.jikan.moe/v4/manga?q={ manga_name } &limit=1"
188
- try :
189
- manga = await self .fetch_manga (manga_name )
190
- if manga :
191
- title = manga .get ("title" )
192
- english_title = manga .get ("title_english" )
193
- cover_image = manga ["images" ]["jpg" ]["image_url" ]
194
- url = manga .get ("url" )
195
- mal_id = manga .get ("mal_id" )
196
- synopsis = manga .get ("synopsis" )
197
- if len (synopsis ) > 700 :
198
- synopsis = synopsis [:700 ] + "..."
199
-
200
- embed = nextcord .Embed (title = title , url = url , color = EMBED_COLOR )
201
- embed .description = ""
202
- if english_title and english_title != title :
203
- embed .description += f"-# { english_title } \n "
204
- embed .description += f"\n { synopsis } "
205
- embed .set_thumbnail (url = cover_image )
206
- embed .set_footer (text = str (mal_id ))
207
-
208
- else :
209
- embed = nextcord .Embed (
210
- description = ":x: Manga not found." ,
211
- color = ERROR_COLOR ,
212
- )
213
-
214
- except Exception as e :
215
- embed = nextcord .Embed (description = str (e ), color = ERROR_COLOR )
216
- await interaction .send (embed = embed , ephemeral = True )
217
- return
152
+ embed = await self .build_mangasyn_embed (manga_name )
218
153
await interaction .send (embed = embed )
219
154
220
155
0 commit comments