1
- import datetime
1
+ import yaml
2
2
3
+ from pathlib import Path
3
4
from typing import Union
5
+ from datetime import datetime
4
6
from dateutil .relativedelta import relativedelta
5
7
from discord import ActivityType , Embed , Member , Spotify , Status
6
8
from discord .ext .commands import Cog , Context , MemberConverter , MemberNotFound , command
7
9
8
10
from bot .bot import Friendo
9
11
10
12
# Dictionaries for the emojis in userinfo embed
11
- BADGES = {'hypesquad_bravery' : '<:bravery:785001148453093386>' ,
12
- 'hypesquad_brilliance' : '<:brilliance:785001159864614933>' ,
13
- 'hypesquad_balance' : '<:balance:785001135676194856>' ,
14
- 'nitro' : '<:nitro:785001224302362624>' ,
15
- 'verified_bot_developer' : '<:dev:785001175820271657>' ,
16
- 'partner' : '<:partner:785001265733566524>' ,
17
- 'early_supporter' : '<:early:785001210599047199>' }
13
+
14
+ with open (Path .cwd () / 'bot' / 'resources' / 'user_badges.yaml' , 'r' , encoding = 'utf-8' ) as f :
15
+ info = yaml .load (f , Loader = yaml .FullLoader )
16
+ BADGES = info [0 ]
17
+
18
18
19
19
STATUSES = {Status .online : '<:online:785001253133484042>' ,
20
20
Status .offline : '<:offline:785001240621744149>' ,
21
21
Status .idle : '<:idle:785001811081035777>' ,
22
- Status .dnd : '<:dnd:785001198159527958>' }
22
+ Status .dnd : '<:dnd:785001198159527958>' ,
23
+ "spotify" : '<:spotify:785113868543852584>' }
23
24
24
25
ACTIVITIES = {ActivityType .playing : ':video_game: Playing ' ,
25
26
ActivityType .listening : ':headphones: Listening to ' ,
@@ -39,31 +40,27 @@ async def get_member(ctx: Context, member: str) -> Member:
39
40
return await MemberConverter ().convert (ctx , member )
40
41
41
42
@staticmethod
42
- def get_timedelta (a : datetime . datetime , b : datetime . datetime ) -> list :
43
+ def get_timedelta (a : datetime , b : datetime ) -> list :
43
44
"""Static method for getting parsed time delta between 2 datetimes."""
44
45
final = []
45
46
delta = relativedelta (a , b )
47
+
46
48
years = abs (delta .years )
47
49
months = abs (delta .months )
48
50
days = abs (delta .days )
49
51
hours = abs (delta .hours )
50
52
minutes = abs (delta .minutes )
51
53
52
- if minutes and not months and not years :
53
- final .append (f'{ minutes } minutes' )
54
-
55
- if hours :
56
- final .append (f'{ hours } hours' )
54
+ dates = {years : "years" ,
55
+ months : "months" ,
56
+ days : "days" ,
57
+ hours : "hours" ,
58
+ months : "months" ,
59
+ minutes : "minutes" }
57
60
58
- if days :
59
- final .append (f'{ days } days' )
60
-
61
- if months :
62
- final .append (f'{ months } months' )
63
-
64
- if years :
65
- final .append (f'{ years } years' )
66
- final = final [::- 1 ]
61
+ for date in dates :
62
+ if date :
63
+ final .append (f"{ date } { dates [date ]} " )
67
64
68
65
return final [:3 ]
69
66
@@ -86,14 +83,13 @@ async def userinfo(self, ctx: Context, member: Union[str, Member] = None) -> Non
86
83
await ctx .send (embed = error_embed )
87
84
return
88
85
89
- spotify_emoji = '<:spotify:785113868543852584>'
90
86
user_badges = []
91
87
roles = []
92
88
statuses = []
93
89
is_bot = "Bot: :x:"
94
90
95
- create_time = ', ' .join (self .get_timedelta (datetime .datetime . utcnow (), user .created_at ))
96
- joined_time = ', ' .join (self .get_timedelta (datetime .datetime . utcnow (), user .joined_at ))
91
+ create_time = ', ' .join (self .get_timedelta (datetime .utcnow (), user .created_at ))
92
+ joined_time = ', ' .join (self .get_timedelta (datetime .utcnow (), user .joined_at ))
97
93
98
94
flags = user .public_flags
99
95
@@ -124,31 +120,30 @@ async def userinfo(self, ctx: Context, member: Union[str, Member] = None) -> Non
124
120
info_emb .description = user_badges
125
121
men , id_ , nick = user .mention , user .id , user .nick
126
122
127
- base_activity = user .activity
123
+ base_activity = user .activities
128
124
if base_activity :
129
- activity = ACTIVITIES [base_activity .type ] + base_activity .name
125
+ activities = [ ACTIVITIES [i .type ] + i .name for i in base_activity if not isinstance ( i , Spotify )]
130
126
else :
131
- activity = "No activity is being done"
132
-
133
- if isinstance (base_activity , Spotify ):
134
- activity = "\n " .join ([f'{ spotify_emoji } { activity [12 :]} ' ,
135
- f"**Song**: { base_activity .title } " ,
136
- f"**Artist**: { base_activity .artist } " ,
137
- f"**Album**: { base_activity .album } " ])
138
-
139
- info_emb .add_field (name = 'User Information' ,
140
- value = f"Created: { create_time } ago\n Profile: { men } \n ID: { id_ } \n { is_bot } " ,
141
- inline = False )
142
- info_emb .add_field (name = "Guild Profile" ,
143
- value = f"Joined: { joined_time } ago\n Nick: { nick } \n Roles: { roles } " ,
144
- inline = False )
145
- info_emb .add_field (name = "Status" ,
146
- value = statuses ,
147
- inline = False )
148
- info_emb .add_field (name = "Activity" ,
149
- value = activity ,
150
- inline = False )
151
-
127
+ activities = "No activity is being done"
128
+
129
+ for activity in base_activity :
130
+ if isinstance (activity , Spotify ):
131
+ activities .append ("\n " .join ([f'{ STATUSES ["spotify" ]} Listening to Spotify' ,
132
+ f"**Song**: { activity .title } " ,
133
+ f"**Artist**: { activity .artist } " ,
134
+ f"**Album**: { activity .album } " ]))
135
+ break
136
+
137
+ activities = "\n " .join (activities )
138
+
139
+ user_info = {
140
+ 'User Information' : f'Created: { create_time } ago\n Profile: { men } \n ID: { id_ } \n { is_bot } ' ,
141
+ 'Guild Profile' : f'Joined: { joined_time } ago\n Nick: { nick } \n Roles: { roles } ' ,
142
+ 'Status' : statuses ,
143
+ 'Activities' : activities }
144
+
145
+ for k , v in user_info .items ():
146
+ info_emb .add_field (name = k , value = v , inline = False )
152
147
await ctx .send (embed = info_emb )
153
148
154
149
0 commit comments