/[sudobot]/trunk/src/commands/information/ProfileCommand.ts
ViewVC logotype

Diff of /trunk/src/commands/information/ProfileCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 550 by rakin, Mon Jul 29 17:30:19 2024 UTC revision 551 by rakin, Mon Jul 29 17:30:46 2024 UTC
# Line 17  Line 17 
17  * along with SudoBot. If not, see <https://www.gnu.org/licenses/>.  * along with SudoBot. If not, see <https://www.gnu.org/licenses/>.
18  */  */
19    
20  import { CommandInteraction, GuildMember, Message, User, UserFlags } from 'discord.js';  import { CommandInteraction, Guild, GuildMember, Message, Permissions, User, UserFlags } from 'discord.js';
21  import BaseCommand from '../../utils/structures/BaseCommand';  import BaseCommand from '../../utils/structures/BaseCommand';
22  import DiscordClient from '../../client/Client';  import DiscordClient from '../../client/Client';
23  import CommandOptions from '../../types/CommandOptions';  import CommandOptions from '../../types/CommandOptions';
# Line 62  export const getUserBadges = (user: User Line 62  export const getUserBadges = (user: User
62      return badges.map(b => `🔵 ${b}`);      return badges.map(b => `🔵 ${b}`);
63  };  };
64    
65    export function getPermissionLevel({ permissions, guild, id }: { id: string, permissions: GuildMember["permissions"], guild: Guild }, string: boolean = false) {
66        if (guild.ownerId === id) {
67            return string ? "100" : 100;
68        }
69    
70        const allBits = Object.values(Permissions.FLAGS).length;
71        const array = permissions.toArray();
72    
73        if (array.includes('ADMINISTRATOR')) {
74            return string ? "100" : 100;
75        }
76    
77        const percentage = (array.length / allBits) * 100;
78    
79        return string ? percentage.toString() : percentage;
80    }
81    
82  export default class ProfileCommand extends BaseCommand {  export default class ProfileCommand extends BaseCommand {
83      supportsInteractions: boolean = true;      supportsInteractions: boolean = true;
84    
# Line 70  export default class ProfileCommand exte Line 87  export default class ProfileCommand exte
87      }      }
88    
89      async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {      async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
90          let user: GuildMember | null = null;          let member: GuildMember | null = null;
91    
92          if (msg instanceof CommandInteraction && options.isInteraction) {          if (msg instanceof CommandInteraction && options.isInteraction) {
93              if (options.options.getMember('user'))              if (options.options.getMember('user'))
94                  user = <GuildMember> await options.options.getMember('user');                  member = <GuildMember> await options.options.getMember('user');
95              else              else
96                  user = <GuildMember> msg.member!;                  member = <GuildMember> msg.member!;
97          }          }
98          else if (msg instanceof Message && !options.isInteraction) {          else if (msg instanceof Message && !options.isInteraction) {
99              if (options.normalArgs[0]) {              if (options.normalArgs[0]) {
# Line 86  export default class ProfileCommand exte Line 103  export default class ProfileCommand exte
103                      if (!tempMember)                      if (!tempMember)
104                          throw new Error();                          throw new Error();
105                                            
106                      user = tempMember;                      member = tempMember;
107                  }                  }
108                  catch (e) {                  catch (e) {
109                      console.log(e);                                    console.log(e);              
# Line 103  export default class ProfileCommand exte Line 120  export default class ProfileCommand exte
120                  }                  }
121              }              }
122              else {              else {
123                  user = msg.member!;                  member = msg.member!;
124              }              }
125          }          }
126    
# Line 120  export default class ProfileCommand exte Line 137  export default class ProfileCommand exte
137              return s;              return s;
138          };              };    
139    
140          const statusText = '' + ((user?.presence?.clientStatus?.desktop ? 'Desktop (' + status(user?.presence?.clientStatus?.desktop) + ')\n' : '') + (user?.presence?.clientStatus?.web ? 'Web (' + status(user?.presence?.clientStatus?.web) + ')\n' : '') + (user?.presence?.clientStatus?.mobile ? 'Mobile (' + status(user?.presence?.clientStatus?.mobile) + ')' : ''));          const statusText = '' + ((member?.presence?.clientStatus?.desktop ? 'Desktop (' + status(member?.presence?.clientStatus?.desktop) + ')\n' : '') + (member?.presence?.clientStatus?.web ? 'Web (' + status(member?.presence?.clientStatus?.web) + ')\n' : '') + (member?.presence?.clientStatus?.mobile ? 'Mobile (' + status(member?.presence?.clientStatus?.mobile) + ')' : ''));
141          // const state = user?.presence?.activities.find(a => a.type === 'CUSTOM')?.state;          // const state = user?.presence?.activities.find(a => a.type === 'CUSTOM')?.state;
142          let activities: string[] | string = [];          let activities: string[] | string = [];
143    
144          if (user?.presence) {          if (member?.presence) {
145              for (const a of user?.presence?.activities.values()!) {              for (const a of member?.presence?.activities.values()!) {
146                  console.log(a);                  console.log(a);
147                                    
148                  if (a.type === 'CUSTOM') {                  if (a.type === 'CUSTOM') {
# Line 157  export default class ProfileCommand exte Line 174  export default class ProfileCommand exte
174    
175          activities = activities.join('\n');          activities = activities.join('\n');
176    
177          const allRoles = [...user!.roles.cache.values()].filter(role => role.id !== msg.guild!.id).sort((role1, role2) => {          const allRoles = [...member!.roles.cache.values()].filter(role => role.id !== msg.guild!.id).sort((role1, role2) => {
178              return role2.position - role1.position;              return role2.position - role1.position;
179          });          });
180          const limit = 10;          const limit = 10;
# Line 165  export default class ProfileCommand exte Line 182  export default class ProfileCommand exte
182          const fields = [          const fields = [
183              {              {
184                  name: "Nickname",                  name: "Nickname",
185                  value: `${user!.nickname?.replace(/\*\<\>\@\_\~\|/g, '') ?? '*Nickname not set*'}`                  value: `${member!.nickname?.replace(/\*\<\>\@\_\~\|/g, '') ?? '*Nickname not set*'}`
186              },              },
187              {              {
188                  name: "Account Created",                  name: "Account Created",
189                  value: `${user!.user.createdAt.toLocaleDateString('en-US')} (${timeSince(user!.user.createdTimestamp)})`                  value: `${member!.user.createdAt.toLocaleDateString('en-US')} (${timeSince(member!.user.createdTimestamp)})`
190              },              },
191              {              {
192                  name: "Joined at",                  name: "Joined at",
193                  value: `${user!.joinedAt!.toLocaleDateString('en-US')} (${timeSince(user!.joinedTimestamp!)})`                  value: `${member!.joinedAt!.toLocaleDateString('en-US')} (${timeSince(member!.joinedTimestamp!)})`
194              },              },
195              {              {
196                  name: 'Active Devices',                  name: 'Active Devices',
# Line 189  export default class ProfileCommand exte Line 206  export default class ProfileCommand exte
206              }              }
207          ];          ];
208    
209          const badges = getUserBadges(user!.user);          const badges = getUserBadges(member!.user);
210    
211          if (badges.length > 0) {          if (badges.length > 0) {
212              fields.push({              fields.push({
# Line 201  export default class ProfileCommand exte Line 218  export default class ProfileCommand exte
218          let banner: string | undefined;          let banner: string | undefined;
219    
220          try {          try {
221              await user?.user.fetch(true);              await member?.user.fetch(true);
222              banner = user!.user!.bannerURL({ size: 4096 }) ?? undefined;              banner = member!.user!.bannerURL({ size: 4096 }) ?? undefined;
223          }          }
224          catch (e) {          catch (e) {
225              console.log(e);              console.log(e);
226          }          }
227    
228          console.log("Banner", banner, user!.user!.banner);          console.log("Banner", banner, member!.user!.banner);
229    
230            let percentage = <string> getPermissionLevel(member!, true);
231            percentage = percentage.includes('.') ? percentage.substring(0, percentage.indexOf('.')) : percentage;
232    
233          await msg.reply({          await msg.reply({
234              embeds: [              embeds: [
# Line 217  export default class ProfileCommand exte Line 237  export default class ProfileCommand exte
237                          url: banner,                          url: banner,
238                      }                      }
239                  })                  })
240                  .setColor(user!.user!.hexAccentColor ? user!.user!.hexAccentColor! : '#007bff')                  .setColor(member!.user!.hexAccentColor ? member!.user!.hexAccentColor! : '#007bff')
241                  .setAuthor({                  .setAuthor({
242                      name: user?.user.tag!,                      name: member?.user.tag!,
243                      iconURL: user!.user.displayAvatarURL()                      iconURL: member!.user.displayAvatarURL()
244                  })                  })
245                  .setThumbnail(user!.displayAvatarURL({                  .setThumbnail(member!.displayAvatarURL({
246                      size: 4096                      size: 4096
247                  }))                  }))
248                  .setFields(fields)                  .setFields(fields)
249                  .setFooter({                  .setFooter({
250                      text: `${user?.user.bot ? 'Bot' : 'User'} • ${user!.id}`                      text: `${member?.user.bot ? 'Bot' : 'User'} • ${member!.id} • Has ${percentage.toString()}% permissions`
251                  })                  })
252              ]              ]
253          });          });

Legend:
Removed from v.550  
changed lines
  Added in v.551

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26