@@ -22,17 +22,15 @@ class MAL_Profiles(commands.Cog):
22
22
def __init__ (self , bot ):
23
23
self .bot = bot
24
24
25
- @commands .command (
26
- help = "Fetch information about a MyAnimeList user. \n Usage: `mal <username>`." ,
27
- )
28
- async def mal (self , ctx : commands .Context , * , username : str ):
25
+ async def build_embed (self , username ):
26
+ embed = nextcord .Embed (color = EMBED_COLOR )
29
27
try :
30
28
profile_data = await request (f"https://api.jikan.moe/v4/users/{ username } " )
31
29
32
30
if not profile_data or not profile_data .get ("data" ):
33
- embed = nextcord . Embed ( title = " User not found.", color = EMBED_COLOR )
34
- await ctx . send ( embed = embed , ephemeral = True )
35
- return
31
+ embed . description = ":x: User not found."
32
+ embed . color = ERROR_COLOR
33
+ return embed
36
34
37
35
user = profile_data ["data" ]
38
36
@@ -78,81 +76,34 @@ async def mal(self, ctx: commands.Context, *, username: str):
78
76
79
77
if profile_pic :
80
78
embed .set_thumbnail (url = profile_pic )
79
+ return embed
81
80
82
81
except Exception as e :
83
- embed = nextcord .Embed (description = str (e ), color = ERROR_COLOR )
82
+ embed .description = str (e )
83
+ embed .color = ERROR_COLOR
84
+ return embed
84
85
86
+ @commands .command (
87
+ help = "Fetch information about a MyAnimeList user. \n Usage: `mal <username>`." ,
88
+ )
89
+ async def mal (self , ctx : commands .Context , * , username : str ):
90
+ embed = await self .build_embed (username )
85
91
await ctx .reply (embed = embed , mention_author = False )
86
92
87
93
@nextcord .slash_command (
88
94
name = "mal" , description = "Fetch information about a MyAnimeList user."
89
95
)
90
96
async def mal_slash (
91
97
self ,
92
- ctx : nextcord .Interaction ,
98
+ interaction : nextcord .Interaction ,
93
99
* ,
94
100
username : str = nextcord .SlashOption (
95
101
description = "Username of the user to fetch"
96
102
),
97
103
):
98
104
await interaction .response .defer ()
99
- try :
100
- profile_data = await request (f"https://api.jikan.moe/v4/users/{ username } " )
101
-
102
- if not profile_data or not profile_data .get ("data" ):
103
- embed = nextcord .Embed (title = "User not found." , color = EMBED_COLOR )
104
- await ctx .send (embed = embed , ephemeral = True )
105
- return
106
-
107
- user = profile_data ["data" ]
108
-
109
- mal_id = user .get ("mal_id" )
110
- profile_url = user .get ("url" )
111
- profile_pic = user .get ("images" , {}).get ("jpg" , {}).get ("image_url" , "" )
112
- gender = user .get ("gender" ) or "Not Specified"
113
- last_online = format_date_long (user .get ("last_online" ))
114
- joined = format_date (user .get ("joined" ))
115
- location = user .get ("location" ) or "Not Specified"
116
- anime_list_url = f"https://myanimelist.net/animelist/{ username } "
117
- manga_list_url = f"https://myanimelist.net/mangalist/{ username } "
118
-
119
- # stats
120
- profile_stats = await request (
121
- f"https://api.jikan.moe/v4/users/{ username } /statistics"
122
- )
123
-
124
- anime_stats = profile_stats ["data" ].get ("anime" )
125
- days_watched = f"**{ str (anime_stats .get ("days_watched" ))} **"
126
- anime_mean = f"**{ str (anime_stats .get ("mean_score" ))} **"
127
-
128
- manga_stats = profile_stats ["data" ].get ("manga" )
129
- days_read = f"**{ str (manga_stats .get ("days_read" ))} **"
130
- manga_mean = f"**{ str (manga_stats .get ("mean_score" ))} **"
131
-
132
- embed = nextcord .Embed (
133
- title = f"{ username } 's Profile" ,
134
- url = profile_url ,
135
- color = EMBED_COLOR ,
136
- )
137
-
138
- embed .description = (
139
- f"-# [Anime List]({ anime_list_url } ) • [Manga List]({ manga_list_url } )\n "
140
- )
141
- embed .description += f"\n > **Gender**: { gender } "
142
- embed .description += f"\n > **Last Seen**: { last_online } "
143
- embed .description += f"\n > **Joined**: { joined } "
144
- embed .description += f"\n > **Location**: { location } "
145
- embed .description += f"\n > **Anime:** { days_watched } days watched with a mean score of { anime_mean } ."
146
- embed .description += f"\n > **Manga:** { days_read } days read with a mean score of { manga_mean } ."
147
- embed .set_footer (text = str (mal_id ))
148
-
149
- if profile_pic :
150
- embed .set_thumbnail (url = profile_pic )
151
-
152
- except Exception as e :
153
- embed = nextcord .Embed (description = str (e ), color = ERROR_COLOR )
154
-
155
- await ctx .send (embed = embed , ephemeral = True )
105
+ embed = await self .build_embed (username )
106
+ await interaction .send (embed = embed )
156
107
157
108
158
109
def setup (bot ):
0 commit comments