-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserverinfo userinfo command.ts
More file actions
387 lines (368 loc) · 13.1 KB
/
Copy pathserverinfo userinfo command.ts
File metadata and controls
387 lines (368 loc) · 13.1 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
const commands = new discord.command.CommandGroup({
defaultPrefix: '!'
});
const timeMap = new Map([
['decade', 1000 * 60 * 60 * 24 * 365 * 10],
['year', 1000 * 60 * 60 * 24 * 365],
['month', 1000 * 60 * 60 * 24 * 31],
['week', 1000 * 60 * 60 * 24 * 7],
['day', 1000 * 60 * 60 * 24],
['hour', 1000 * 60 * 60],
['minute', 1000 * 60],
['second', 1000],
['milisecond', 1]
]);
function getLongAgoFormat(ts: number, limiter: number) {
let runcheck = ts + 0;
let txt = new Map();
for (var [k, v] of timeMap) {
if (runcheck < v || txt.entries.length >= limiter) continue;
let runs = Math.ceil(runcheck / v) + 1;
for (var i = 0; i <= runs; i++) {
if (runcheck < v) break;
if (txt.has(k)) {
txt.set(k, txt.get(k) + 1);
} else {
txt.set(k, 1);
}
runcheck -= v;
}
}
let txtret = new Array();
let runsc = 0;
for (var [key, value] of txt) {
if (runsc >= limiter) break;
let cc = value > 1 ? key + 's' : key;
txtret.push(value + ' ' + cc);
runsc++;
}
return txtret.join(', ');
}
function pad(v: string, n: number, c = '0') {
return String(v).length >= n
? String(v)
: (String(c).repeat(n) + v).slice(-n);
}
function decomposeSnowflake(snowflake: string) {
let binary = pad(BigInt(snowflake).toString(2), 64);
const res = {
timestamp: parseInt(binary.substring(0, 42), 2) + 1420070400000,
workerID: parseInt(binary.substring(42, 47), 2),
processID: parseInt(binary.substring(47, 52), 2),
increment: parseInt(binary.substring(52, 64), 2),
binary: binary
};
return res;
}
commands.raw('server', async (message) => {
let edmsg = message.reply('<a:loading:735794724480483409>');
let embed = new discord.Embed();
const guild = await message.getGuild();
if (guild === null) throw new Error('guild not found');
let icon = guild.getIconUrl();
if (icon === null) icon = '';
embed.setAuthor({
name: guild.name,
iconUrl: 'https://cdn.discordapp.com/emojis/735781410509684786.png?v=1'
});
let dtCreation = new Date(decomposeSnowflake(guild.id).timestamp);
let diff = new Date(new Date().getTime() - dtCreation.getTime()).getTime();
let tdiff = getLongAgoFormat(diff, 2);
if (icon !== null) embed.setThumbnail({ url: icon });
let desc = '';
const formattedDtCreation = `${dtCreation.toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric'
})}`; /* @ ${dtCreation.toLocaleTimeString('en-US', {
hour12: false,
timeZone: 'UTC',
timeZoneName: 'short'
})}`;*/
let preferredLocale =
typeof guild.preferredLocale === 'string' &&
guild.features.includes(discord.Guild.Feature.DISCOVERABLE)
? `\n **Preferred Locale**: \`${guild.preferredLocale}\`\n`
: '';
let boosts =
guild.premiumSubscriptionCount > 0
? `\n<:booster3:735780703773655102>**Boosts**: ${guild.premiumSubscriptionCount}\n`
: '';
let boostTier =
guild.premiumTier !== null
? `\n **Boost Tier**: ${guild.premiumTier}\n`
: '';
let systemChannel =
guild.systemChannelId !== null
? `\n **System Channel**: <#${guild.systemChannelId}>\n`
: '';
let vanityUrl =
guild.vanityUrlCode !== null
? `\n **Vanity Url**: \`${guild.vanityUrlCode}\``
: '';
let description =
guild.description !== null
? `\n **Description**: \`${guild.description}\``
: '';
let widgetChannel =
guild.widgetChannelId !== null
? `<#${guild.widgetChannelId}>`
: 'No channel';
let widget =
guild.widgetEnabled === true
? '\n **Widget**: ' +
discord.decor.Emojis.WHITE_CHECK_MARK +
` ( ${widgetChannel} )`
: '';
let features = guild.features.length > 0 ? guild.features.join(', ') : 'None';
desc += ` **❯ **Information
<:rich_presence:735781410509684786>**ID**: \`${guild.id}\`
**Created**: ${tdiff} ago **[**\`${formattedDtCreation}\`**]**
<:owner:735780703903547443>**Owner**: <@!${guild.ownerId}>
<:voice:735780703928844319>**Voice Region**: \`${guild.region}\`
**Features**: \`${features}\`
**Max Presences**: ${guild.maxPresences}${boosts}${boostTier}${widget}${description}${preferredLocale}${vanityUrl}${systemChannel}`;
let chanStats = new Array();
let counts: any = {
text: 0,
category: 0,
voice: 0,
news: 0,
store: 0
};
let channels = await guild.getChannels();
channels.forEach(function(ch) {
if (ch.type === discord.GuildChannel.Type.GUILD_TEXT) counts.text++;
if (ch.type === discord.GuildChannel.Type.GUILD_VOICE) counts.voice++;
if (ch.type === discord.GuildChannel.Type.GUILD_STORE) counts.store++;
if (ch.type === discord.GuildChannel.Type.GUILD_CATEGORY) counts.category++;
if (ch.type === discord.GuildChannel.Type.GUILD_NEWS) counts.news++;
});
for (var k in counts) {
let obj = counts[k];
let emj = '';
if (k === 'text') emj = '<:channel:735780703983239218> ';
if (k === 'voice') emj = '<:voice:735780703928844319> ';
if (k === 'store') emj = '<:store:735780704130170880> ';
if (k === 'news') emj = '<:news:735780703530385470> ';
if (k === 'category') emj = '<:rich_presence:735781410509684786> ';
if (obj > 0)
chanStats.push(
'\n ' +
emj +
'**' +
k.substr(0, 1).toUpperCase() +
k.substr(1) +
'**: **' +
obj +
'**'
);
}
desc += '\n\n**❯ **Channels ⎯ ' + channels.length + chanStats.join('');
const roles = await guild.getRoles();
const emojis = await guild.getEmojis();
desc += `
**❯ **Other Counts
<:settings:735782884836638732> **Roles**: ${roles.length}
<:emoji_ghost:735782884862066789> **Emojis**: ${emojis.length}`;
let memberCounts: any = {
human: 0,
bot: 0,
presences: {
streaming: 0,
game: 0,
listening: 0,
watching: 0,
online: 0,
dnd: 0,
idle: 0,
offline: 0
}
};
for await (const member of guild.iterMembers()) {
let usr = member.user;
if (!usr.bot) {
memberCounts.human++;
} else {
memberCounts.bot++;
continue;
}
let pres = await member.getPresence();
if (
pres.activities.find((e) => {
return e.type === discord.Presence.ActivityType.STREAMING;
})
)
memberCounts.presences.streaming++;
if (
pres.activities.find((e) => {
return e.type === discord.Presence.ActivityType.LISTENING;
})
)
memberCounts.presences.listening++;
if (
pres.activities.find((e) => {
return e.type === discord.Presence.ActivityType.GAME;
})
)
memberCounts.presences.game++;
if (
pres.activities.find((e) => {
return e.type === discord.Presence.ActivityType.WATCHING;
})
)
memberCounts.presences.watching++;
memberCounts.presences[pres.status]++;
}
let prestext = ``;
let nolb = false;
for (let key in memberCounts.presences) {
let obj = memberCounts.presences[key];
let emj = '';
if (key === 'streaming') emj = '<:streaming:735793095597228034>';
if (key === 'game') emj = discord.decor.Emojis.VIDEO_GAME;
if (key === 'watching') emj = '<:watching:735793898051469354>';
if (key === 'listening') emj = '<:spotify:735788337897406535>';
if (key === 'online') emj = '<:status_online:735780704167919636>';
if (key === 'dnd') emj = '<:status_busy:735780703983239168>';
if (key === 'idle') emj = '<:status_away:735780703710478407>';
if (key === 'offline') emj = '<:status_offline:735780703802753076>';
if (obj > 0) {
if (
key !== 'streaming' &&
key !== 'listening' &&
key !== 'watching' &&
key !== 'game' &&
!prestext.includes('**⎯⎯⎯⎯⎯**') &&
!nolb
) {
if (prestext.length === 0) {
nolb = true;
} else {
prestext += '\n**⎯⎯⎯⎯⎯**'; // add linebreak
}
}
prestext += `\n ${emj} **-** ${obj}`;
}
}
let bottxt = `\n <:bot:735780703945490542> **-** ${memberCounts.bot}
**⎯⎯⎯⎯⎯**`;
if (memberCounts.bot <= 0) bottxt = '';
desc += `
**❯ **Members ⎯ ${guild.memberCount}${bottxt}${prestext}`;
embed.setDescription(desc);
let editer = await edmsg;
await editer.edit({ content: '', embed: embed });
});
commands.on(
'info',
(ctx) => ({ user: ctx.userOptional() }),
async (msg, { user }) => {
const loadingMsg = await msg.reply({
allowedMentions: {},
content: '<a:loading:735794724480483409>'
});
if (user === null) {
user = msg.author;
}
const emb = new discord.Embed();
emb.setAuthor({ name: user.getTag(), iconUrl: user.getAvatarUrl() });
let desc = `**❯ ${user.bot === false ? 'User' : 'Bot'} Information**
<:rich_presence:735781410509684786> **ID**: \`${user.id}\`
${discord.decor.Emojis.LINK} **Profile**: ${user.toMention()}`;
const dtCreation = new Date(decomposeSnowflake(user.id).timestamp);
const tdiff = getLongAgoFormat(Date.now() - dtCreation.getTime(), 2);
const formattedDtCreation = `${dtCreation.toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric'
})}`;
desc += `\n ${discord.decor.Emojis.CALENDAR_SPIRAL} **Created**: ${tdiff} ago **[**\`${formattedDtCreation}\`**]**`;
const guild = await msg.getGuild();
const member = await guild.getMember(user.id);
if (member !== null) {
// presences
const presence = await member.getPresence();
const statuses = presence.activities.map((pres) => {
const key = pres.type;
let emj = '';
if (pres.type === discord.Presence.ActivityType.STREAMING) {
emj = '<:streaming:735793095597228034>';
}
if (pres.type === discord.Presence.ActivityType.GAME) {
emj = discord.decor.Emojis.VIDEO_GAME;
}
if (pres.type === discord.Presence.ActivityType.WATCHING) {
emj = '<:watching:735793898051469354>';
}
if (pres.type === discord.Presence.ActivityType.LISTENING) {
emj = '<:spotify:735788337897406535>';
}
if (pres.type === discord.Presence.ActivityType.CUSTOM) {
let emjMention = '';
if (pres.emoji !== null) {
emjMention =
pres.emoji.id === null
? pres.emoji.name
: `<${pres.emoji.animated === true ? 'a' : ''}:${
pres.emoji.name
}:${pres.emoji.id}>`;
} else {
emjMention = discord.decor.Emojis.NOTEPAD_SPIRAL;
}
return `${emjMention}${
pres.state !== null ? ` \`${pres.state}\`` : ''
} (Custom Status)`;
}
return `${emj}${pres.name.length > 0 ? ` \`${pres.name}\`` : ''}`;
});
let emjStatus = '';
if (presence.status === 'online') {
emjStatus = '<:status_online:735780704167919636>';
}
if (presence.status === 'dnd') {
emjStatus = '<:status_busy:735780703983239168>';
}
if (presence.status === 'idle') {
emjStatus = '<:status_away:735780703710478407>';
}
if (presence.status === 'offline') {
emjStatus = '<:status_offline:735780703802753076>';
}
desc += `\n ${emjStatus} **Status**: ${presence.status
.substr(0, 1)
.toUpperCase()}${presence.status.substr(1).toLowerCase()}`;
if (statuses.length > 0) {
desc += `\n ${statuses.join('\n ')}`;
}
const roles = member.roles.map((rl) => `<@&${rl}>`).join(' ');
desc += '\n\n**❯ Member Information**';
const dtJoin = new Date(member.joinedAt);
const tdiffjoin = getLongAgoFormat(Date.now() - dtJoin.getTime(), 2);
const formattedDtJoin = `${dtJoin.toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric'
})}`;
desc += `\n ${discord.decor.Emojis.INBOX_TRAY} **Joined**: ${tdiffjoin} ago **[**\`${formattedDtJoin}\`**]**`;
if (member.nick && member.nick !== null && member.nick.length > 0) {
desc += `\n ${discord.decor.Emojis.NOTEPAD_SPIRAL} **Nickname**: \`${member.nick}\``;
}
if (member.premiumSince !== null) {
const boostDt = new Date(member.premiumSince);
const tdiffboost = getLongAgoFormat(Date.now() - boostDt.getTime(), 2);
const formattedDtBoost = `${boostDt.toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric'
})}`;
desc += `\n <:booster:735780703912067160> **Boosting since**: ${tdiffboost} ago **[**\`${formattedDtBoost}\`**]**`;
}
if (member.roles.length > 0) {
desc += `\n ${discord.decor.Emojis.SHIELD} **Roles** (${member.roles.length}): ${roles}`;
}
}
emb.setDescription(desc);
await loadingMsg.edit({ content: '', embed: emb });
}
);