@@ -28,12 +28,9 @@ async def fetch_anime(self, anime_name: str):
28
28
except Exception as e :
29
29
raise e
30
30
31
- @commands .command (
32
- name = "anime" ,
33
- aliases = ["ani" ],
34
- help = "Fetch anime information from MyAnimeList. \n Usage: `anime Lycoris Recoil` or `anime 50709`." ,
35
- )
36
- async def base_anime (self , ctx : commands .Context , * , anime_name : str ):
31
+ async def build_anime_embed (self , anime_name ):
32
+ embed = nextcord .Embed (color = EMBED_COLOR )
33
+ is_error_embed = False
37
34
url = f"https://api.jikan.moe/v4/anime?q={ anime_name } &limit=1"
38
35
try :
39
36
anime = await self .fetch_anime (anime_name )
@@ -69,115 +66,94 @@ async def base_anime(self, ctx: commands.Context, *, anime_name: str):
69
66
embed .description += f"\n > **Rating**: { rating } "
70
67
embed .set_thumbnail (url = cover_image )
71
68
embed .set_footer (text = str (mal_id ))
69
+ return embed , is_error_embed
72
70
73
71
else :
74
- embed = nextcord . Embed (
75
- description = ":x: Anime not found." ,
76
- color = ERROR_COLOR ,
77
- )
72
+ embed . description = ":x: Anime not found."
73
+ embed . color = ERROR_COLOR
74
+ is_error_embed = True
75
+ return embed , is_error_embed
78
76
79
77
except Exception as e :
80
78
embed = nextcord .Embed (description = str (e ), color = ERROR_COLOR )
81
- await ctx .reply (embed = embed , mention_author = False )
82
-
83
- @nextcord .slash_command (
84
- name = "anime" , description = "MyAnimeList anime information commands."
85
- )
86
- async def anime (
87
- self ,
88
- interaction : nextcord .Interaction ,
89
- ):
90
- pass
79
+ is_error_embed = True
80
+ return embed , is_error_embed
91
81
92
- @anime .subcommand (
93
- name = "info" , description = "Fetch anime information from MyAnimeList."
94
- )
95
- async def slash_anime_info (
96
- self ,
97
- interaction : Interaction ,
98
- anime_name : str = SlashOption (description = "Name of the anime" ),
99
- ):
100
- await interaction .response .defer ()
82
+ async def build_anisyn_embed (self , anime_name ):
83
+ embed = nextcord .Embed (color = EMBED_COLOR )
84
+ is_error_embed = False
101
85
url = f"https://api.jikan.moe/v4/anime?q={ anime_name } &limit=1"
102
86
try :
103
87
anime = await self .fetch_anime (anime_name )
104
88
if anime :
105
89
title = anime .get ("title" )
106
- episodes = anime .get ("episodes" )
107
- score = anime .get ("score" )
108
90
synopsis = anime .get ("synopsis" )
109
- source = anime .get ("source" )
91
+ if len (synopsis ) > 700 :
92
+ synopsis = synopsis [:700 ] + "..."
110
93
english_title = anime .get ("title_english" )
111
- aired = anime .get ("aired" , {}).get ("string" )
112
- type = anime .get ("type" )
113
94
cover_image = anime ["images" ]["jpg" ]["image_url" ]
114
95
url = anime .get ("url" )
115
- rating = anime .get ("rating" )
116
96
mal_id = anime .get ("mal_id" )
117
- genres = ", " .join ([genre ["name" ] for genre in anime .get ("genres" , [])])
118
- studios = ", " .join (
119
- [studio ["name" ] for studio in anime .get ("studios" , [])]
120
- )
121
97
122
98
embed = nextcord .Embed (title = title , url = url , color = EMBED_COLOR )
123
99
embed .description = ""
124
100
if english_title and english_title != title :
125
101
embed .description += f"-# { english_title } \n "
126
- embed .description += f"\n > **Type**: { type } "
127
- embed .description += f"\n > **Episodes**: { episodes } "
128
- embed .description += f"\n > **Score**: { score } "
129
- embed .description += f"\n > **Source**: { source } "
130
- embed .description += f"\n > **Aired**: { aired } "
131
- embed .description += f"\n > **Genres**: { genres } "
132
- embed .description += f"\n > **Studios**: { studios } "
133
- embed .description += f"\n > **Rating**: { rating } "
102
+ embed .description += f"\n { synopsis } "
134
103
embed .set_thumbnail (url = cover_image )
135
104
embed .set_footer (text = str (mal_id ))
105
+ return embed , is_error_embed
136
106
137
107
else :
138
- embed = nextcord . Embed (
139
- description = ":x: Anime not found." ,
140
- color = ERROR_COLOR ,
141
- )
108
+ embed . description = ":x: Anime not found."
109
+ embed . color = ERROR_COLOR
110
+ is_error_embed = True
111
+ return embed , is_error_embed
142
112
143
113
except Exception as e :
114
+ is_error_embed = True
144
115
embed = nextcord .Embed (description = str (e ), color = ERROR_COLOR )
145
- await interaction . send ( embed = embed )
116
+ return embed , is_error_embed
146
117
147
118
@commands .command (
148
- aliases = ["animeplot" , "anisyn" , "animesyn" ],
149
- help = "Fetch a anime's summary from MyAnimeList. \n Usage: `anisyn Lycoris Recoil` or `anisyn 50709`." ,
119
+ name = "anime" ,
120
+ aliases = ["ani" ],
121
+ help = "Fetch anime information from MyAnimeList. \n Usage: `anime Lycoris Recoil` or `anime 50709`." ,
150
122
)
151
- async def anime_synopsis (self , ctx : commands .Context , * , anime_name : str ):
152
- url = f"https://api.jikan.moe/v4/anime?q={ anime_name } &limit=1"
153
- try :
154
- anime = await self .fetch_anime (anime_name )
155
- if anime :
156
- title = anime .get ("title" )
157
- synopsis = anime .get ("synopsis" )
158
- if len (synopsis ) > 700 :
159
- synopsis = synopsis [:700 ] + "..."
160
- english_title = anime .get ("title_english" )
161
- cover_image = anime ["images" ]["jpg" ]["image_url" ]
162
- url = anime .get ("url" )
163
- mal_id = anime .get ("mal_id" )
123
+ async def base_anime (self , ctx : commands .Context , * , anime_name : str ):
124
+ embed , is_error_embed = await self .build_anime_embed (anime_name )
125
+ await ctx .reply (embed = embed , mention_author = False )
164
126
165
- embed = nextcord .Embed (title = title , url = url , color = EMBED_COLOR )
166
- embed .description = ""
167
- if english_title and english_title != title :
168
- embed .description += f"-# { english_title } \n "
169
- embed .description += f"\n { synopsis } "
170
- embed .set_thumbnail (url = cover_image )
171
- embed .set_footer (text = str (mal_id ))
127
+ @nextcord .slash_command (
128
+ name = "anime" , description = "MyAnimeList anime information commands."
129
+ )
130
+ async def anime (
131
+ self ,
132
+ interaction : nextcord .Interaction ,
133
+ ):
134
+ pass
172
135
173
- else :
174
- embed = nextcord .Embed (
175
- description = ":x: Anime not found." ,
176
- color = ERROR_COLOR ,
177
- )
136
+ @anime .subcommand (
137
+ name = "info" , description = "Fetch anime information from MyAnimeList."
138
+ )
139
+ async def slash_anime_info (
140
+ self ,
141
+ interaction : Interaction ,
142
+ anime_name : str = SlashOption (description = "Name of the anime" ),
143
+ ):
144
+ await interaction .response .defer ()
145
+ embed , is_error_embed = await self .build_anime_embed (anime_name )
146
+ if is_error_embed :
147
+ await interaction .send (embed = embed , ephemeral = True )
148
+ else :
149
+ await interaction .send (embed = embed )
178
150
179
- except Exception as e :
180
- embed = nextcord .Embed (description = str (e ), color = ERROR_COLOR )
151
+ @commands .command (
152
+ aliases = ["animeplot" , "anisyn" , "animesyn" ],
153
+ help = "Fetch a anime's summary from MyAnimeList. \n Usage: `anisyn Lycoris Recoil` or `anisyn 50709`." ,
154
+ )
155
+ async def anime_synopsis (self , ctx : commands .Context , * , anime_name : str ):
156
+ embed , is_error_embed = await self .build_anisyn_embed (anime_name )
181
157
await ctx .reply (embed = embed , mention_author = False )
182
158
183
159
@anime .subcommand (
@@ -189,38 +165,11 @@ async def slash_anime_synopsis(
189
165
anime_name : str = SlashOption (description = "Name of the anime" ),
190
166
):
191
167
await interaction .response .defer ()
192
- url = f"https://api.jikan.moe/v4/anime?q={ anime_name } &limit=1"
193
- try :
194
- anime = await self .fetch_anime (anime_name )
195
- if anime :
196
- title = anime .get ("title" )
197
- synopsis = anime .get ("synopsis" )
198
- if len (synopsis ) > 700 :
199
- synopsis = synopsis [:700 ] + "..."
200
- english_title = anime .get ("title_english" )
201
- cover_image = anime ["images" ]["jpg" ]["image_url" ]
202
- url = anime .get ("url" )
203
- mal_id = anime .get ("mal_id" )
204
-
205
- embed = nextcord .Embed (title = title , url = url , color = EMBED_COLOR )
206
- embed .description = ""
207
- if english_title and english_title != title :
208
- embed .description += f"-# { english_title } \n "
209
- embed .description += f"\n { synopsis } "
210
- embed .set_thumbnail (url = cover_image )
211
- embed .set_footer (text = str (mal_id ))
212
-
213
- else :
214
- embed = nextcord .Embed (
215
- description = ":x: Anime not found." ,
216
- color = ERROR_COLOR ,
217
- )
218
-
219
- except Exception as e :
220
- embed = nextcord .Embed (description = str (e ), color = ERROR_COLOR )
168
+ embed , is_error_embed = await self .build_anisyn_embed (anime_name )
169
+ if is_error_embed :
221
170
await interaction .send (embed = embed , ephemeral = True )
222
- return
223
- await interaction .send (embed = embed )
171
+ else :
172
+ await interaction .send (embed = embed )
224
173
225
174
226
175
def setup (bot ):
0 commit comments