-
-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathusers.js
More file actions
76 lines (67 loc) · 1.97 KB
/
Copy pathusers.js
File metadata and controls
76 lines (67 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { ActivityTypes } from '@aquarius-bot/discordjs-fixes';
import { GuildMember } from 'discord.js';
/**
* @typedef {import('discord.js').User} User
* @typedef {import('discord.js').Guild} Guild
* @typedef {import('discord.js').Presence} Presence
* @typedef {import('discord.js').Activity} Activity
*/
/**
* Gets a User's nickname or username for a Guild
* @param {Guild} guild - The Guild to get a User's nickname in
* @param {User} user - The User to get the nickname for
* @returns {string} The User's Nickname or Username if not set
*/
export function getNickname(guild, user) {
if (!guild) {
return user.username;
}
let member = user;
if (!(member instanceof GuildMember)) {
member = guild.member(user);
}
return member?.nickname ?? member.user.username;
}
/**
* Checks to see if a user is a bot.
* @param {User} user - user to check
* @returns {boolean} whether the user is a bot in non-test environments
*/
export function isBot(user) {
if (process.env.BOT_IGNORE) {
return false;
}
return user.bot;
}
/**
* Checks to see if a user is streaming or not
* @param {Presence} presence - presence of the user to check
* @returns {boolean} whether the user is streaming or not
*/
export function isStreaming(presence) {
return (
presence?.activities?.some(
(activity) => activity.type === ActivityTypes.STREAMING
) ?? false
);
}
/**
* Finds the Game Activity of a User Presence
* @param {Presence} presence - presence of the user to check
* @returns {?Activity} The game Activity
*/
export function getGame(presence) {
return presence?.activities?.find(
(activity) => activity.type === ActivityTypes.PLAYING
);
}
/**
* Finds the Streaming Activity of a User Presence
* @param {Presence} presence - presence of the user to check
* @returns {?Activity} The streaming Activity
*/
export function getStream(presence) {
return presence?.activities?.find(
(activity) => activity.type === ActivityTypes.STREAMING
);
}