Skip to content

Instantly share code, notes, and snippets.

@apos37
Created August 12, 2022 21:24
Show Gist options
  • Save apos37/5be8604993d9d709f4667ad07ca55402 to your computer and use it in GitHub Desktop.
Save apos37/5be8604993d9d709f4667ad07ca55402 to your computer and use it in GitHub Desktop.
Pylon Bot Commands for User Public Flags
import { commands } from './command_group';
import { WELCOME_CHANNEL_ID } from './ids';
/**
* Get user's publicFlags
*/
function getFlagsOld(publicFlags) {
const flags = Array(
[1, 1 << 0, 'DISCORD_EMPLOYEE', 'Discord Employee', true],
[2, 1 << 1, 'DISCORD_PARTNER', 'Discord Partner', true],
[4, 1 << 2, 'HYPESQUAD_EVENTS', 'HypeSquad Events', true],
[8, 1 << 3, 'BUG_HUNTER_LEVEL_1', 'Bug Hunter Level 1', true],
[16, 1 << 4, 'MFA_SMS', 'SMS recovery for 2FA enabled', false],
[32, 1 << 5, 'PREMIUM_PROMO_DISMISSED', 'Dismissed Nitro promotion', false],
[64, 1 << 6, 'HOUSE_BRAVERY', 'HypeSquad Online House Bravery', true],
[
128,
1 << 7,
'HOUSE_BRILLIANCE',
'HypeSquad Online House Brilliance',
true,
],
[256, 1 << 8, 'HOUSE_BALANCE', 'HypeSquad Online House Balance', true],
[512, 1 << 9, 'EARLY_SUPPORTER', 'Early Supporter', true],
[1024, 1 << 10, 'TEAM_PSEUDO_USER', 'Team User', true],
[
2048,
1 << 11,
'INTERNAL_APPLICATION',
'Relates to partner/verification applications.',
false,
],
[4096, 1 << 12, 'SYSTEM', 'System User', true],
[
8192,
1 << 13,
'HAS_UNREAD_URGENT_MESSAGES',
'Has an unread system message',
false,
],
[16384, 1 << 14, 'BUG_HUNTER_LEVEL_2', 'Bug Hunter Level 2', true],
[
32768,
1 << 15,
'UNDERAGE_DELETED',
'Pending deletion for being underage in DOB prompt',
false,
],
[65536, 1 << 16, 'VERIFIED_BOT', 'Verified Bot', true],
[
131072,
1 << 17,
'VERIFIED_BOT_DEVELOPER',
'Early Verified Bot Developer',
true,
],
[
262144,
1 << 18,
'CERTIFIED_MODERATOR',
'Discord Certified Moderator',
true,
],
[
524288,
1 << 19,
'BOT_HTTP_INTERACTIONS',
'Bot has set an interactions endpoint url',
true,
],
[1048576, 1 << 20, 'SPAMMER', 'User is disabled for being a spammer', true],
[2097152, 1 << 21, 'DISABLE_PREMIUM', 'Disables Nitro Features', false],
[
4194304,
1 << 22,
'UNKNOWN_FLAG_22',
'This flag is currently not known but is potentially used.',
false,
],
[
8388608,
1 << 23,
'UNKNOWN_FLAG_23',
'This flag is currently not known but is potentially used.',
false,
],
[
16777216,
1 << 24,
'UNKNOWN_FLAG_24',
'This flag is currently not known but is potentially used.',
false,
],
[
33554432,
1 << 25,
'UNKNOWN_FLAG_25',
'This flag is currently not known but is potentially used.',
false,
],
[
67108864,
1 << 26,
'UNKNOWN_FLAG_26',
'This flag is currently not known but is potentially used.',
false,
],
[
134217728,
1 << 27,
'UNKNOWN_FLAG_27',
'This flag is currently not known but is potentially used.',
false,
],
[
268435456,
1 << 28,
'UNKNOWN_FLAG_28',
'This flag is currently not known but is potentially used.',
false,
],
[
536870912,
1 << 29,
'UNKNOWN_FLAG_29',
'This flag is currently not known but is potentially used.',
false,
],
[
1073741824,
1 << 30,
'UNKNOWN_FLAG_30',
'This flag is currently not known but is potentially used.',
false,
],
[
2147483648,
1 << 31,
'UNKNOWN_FLAG_31',
'This flag is currently not known but is potentially used.',
false,
],
[
4294967296,
1 << 32,
'UNKNOWN_FLAG_32',
'This flag is currently not known but is potentially used.',
false,
],
[
8589934592,
1 << 33,
'UNKNOWN_FLAG_33',
'This flag is currently not known but is potentially used.',
false,
],
[
17179869184,
1 << 34,
'UNKNOWN_FLAG_34',
'This flag is currently not known but is potentially used.',
false,
],
[
34359738368,
1 << 35,
'UNKNOWN_FLAG_35',
'This flag is currently not known but is potentially used.',
false,
],
[
68719476736,
1 << 36,
'UNKNOWN_FLAG_36',
'This flag is currently not known but is potentially used.',
false,
],
[
137438953472,
1 << 37,
'PREMIUM_DISCRIMINATOR',
'User has a premium discriminator.',
false,
],
[
274877906944,
1 << 38,
'USED_DESKTOP_CLIENT',
'User has used the desktop client.',
false,
],
[
549755813888,
1 << 39,
'USED_WEB_CLIENT',
'User has used the web client.',
false,
],
[
1099511627776,
1 << 40,
'USED_MOBILE_CLIENT',
'User has used the mobile client.',
false,
],
[
2199023255552,
1 << 41,
'DISABLED',
'User is currently temporarily or permanently disabled.',
false,
],
[
4398046511104,
1 << 42,
'UNKNOWN_FLAG_42',
'This flag is currently not known but is potentially used.',
false,
],
[
8796093022208,
1 << 43,
'VERIFIED_EMAIL',
'User has a verified email.',
false,
],
[
17592186044416,
1 << 44,
'QUARANTINED',
'User account is quarantined.',
false,
]
);
// Find them
let flagsFound = Array();
for (let f = 0; f < flags.length; f++) {
// console.log(flags[f][1]);
if (publicFlags & flags[f][1]) {
flagsFound.push(flags[f]);
}
}
// Or else return nothing
return flagsFound;
}
function getFlags(publicFlags) {
const flags = Array(
[1, 1 << 0, 'DISCORD_EMPLOYEE', 'Discord Employee', true],
[2, 1 << 1, 'DISCORD_PARTNER', 'Discord Partner', true],
[4, 1 << 2, 'HYPESQUAD_EVENTS', 'HypeSquad Events', true],
[8, 1 << 3, 'BUG_HUNTER_LEVEL_1', 'Bug Hunter Level 1', true],
[16, 1 << 4, 'MFA_SMS', 'SMS recovery for 2FA enabled', false],
[32, 1 << 5, 'PREMIUM_PROMO_DISMISSED', 'Dismissed Nitro promotion', false],
[64, 1 << 6, 'HOUSE_BRAVERY', 'HypeSquad Online House Bravery', true],
[
128,
1 << 7,
'HOUSE_BRILLIANCE',
'HypeSquad Online House Brilliance',
true,
],
[256, 1 << 8, 'HOUSE_BALANCE', 'HypeSquad Online House Balance', true],
[512, 1 << 9, 'EARLY_SUPPORTER', 'Early Supporter', true],
[1024, 1 << 10, 'TEAM_PSEUDO_USER', 'Team User', true],
[
2048,
1 << 11,
'INTERNAL_APPLICATION',
'Relates to partner/verification applications.',
false,
],
[4096, 1 << 12, 'SYSTEM', 'System User', true],
[
8192,
1 << 13,
'HAS_UNREAD_URGENT_MESSAGES',
'Has an unread system message',
false,
],
[16384, 1 << 14, 'BUG_HUNTER_LEVEL_2', 'Bug Hunter Level 2', true],
[
32768,
1 << 15,
'UNDERAGE_DELETED',
'Pending deletion for being underage in DOB prompt',
false,
],
[65536, 1 << 16, 'VERIFIED_BOT', 'Verified Bot', true],
[
131072,
1 << 17,
'VERIFIED_BOT_DEVELOPER',
'Early Verified Bot Developer',
true,
],
[
262144,
1 << 18,
'CERTIFIED_MODERATOR',
'Discord Certified Moderator',
true,
],
[
524288,
1 << 19,
'BOT_HTTP_INTERACTIONS',
'Bot has set an interactions endpoint url',
true,
],
[
1048576,
Math.pow(2, 20),
'SPAMMER',
'User is disabled for being a spammer',
true,
],
[
2097152,
Math.pow(2, 21),
'DISABLE_PREMIUM',
'Disables Nitro Features',
false,
],
[
4194304,
1 << 22,
'UNKNOWN_FLAG_22',
'This flag is currently not known but is potentially used.',
false,
],
[
8388608,
1 << 23,
'UNKNOWN_FLAG_23',
'This flag is currently not known but is potentially used.',
false,
],
[
16777216,
1 << 24,
'UNKNOWN_FLAG_24',
'This flag is currently not known but is potentially used.',
false,
],
[
33554432,
1 << 25,
'UNKNOWN_FLAG_25',
'This flag is currently not known but is potentially used.',
false,
],
[
67108864,
1 << 26,
'UNKNOWN_FLAG_26',
'This flag is currently not known but is potentially used.',
false,
],
[
134217728,
1 << 27,
'UNKNOWN_FLAG_27',
'This flag is currently not known but is potentially used.',
false,
],
[
268435456,
1 << 28,
'UNKNOWN_FLAG_28',
'This flag is currently not known but is potentially used.',
false,
],
[
536870912,
1 << 29,
'UNKNOWN_FLAG_29',
'This flag is currently not known but is potentially used.',
false,
],
[
1073741824,
1 << 30,
'UNKNOWN_FLAG_30',
'This flag is currently not known but is potentially used.',
false,
],
[
2147483648,
1 << 31,
'UNKNOWN_FLAG_31',
'This flag is currently not known but is potentially used.',
false,
],
[
4294967296,
1 << 32,
'UNKNOWN_FLAG_32',
'This flag is currently not known but is potentially used.',
false,
],
[
8589934592,
1 << 33,
'UNKNOWN_FLAG_33',
'This flag is currently not known but is potentially used.',
false,
],
[
17179869184,
1 << 34,
'UNKNOWN_FLAG_34',
'This flag is currently not known but is potentially used.',
false,
],
[
34359738368,
1 << 35,
'UNKNOWN_FLAG_35',
'This flag is currently not known but is potentially used.',
false,
],
[
68719476736,
1 << 36,
'UNKNOWN_FLAG_36',
'This flag is currently not known but is potentially used.',
false,
],
[
137438953472,
Math.pow(2, 37),
'PREMIUM_DISCRIMINATOR',
'User has a premium discriminator.',
false,
],
[
274877906944,
Math.pow(2, 38),
'USED_DESKTOP_CLIENT',
'User has used the desktop client.',
false,
],
[
549755813888,
Math.pow(2, 39),
'USED_WEB_CLIENT',
'User has used the web client.',
false,
],
[
1099511627776,
Math.pow(2, 40),
'USED_MOBILE_CLIENT',
'User has used the mobile client.',
false,
],
[
2199023255552,
Math.pow(2, 41),
'DISABLED',
'User is currently temporarily or permanently disabled.',
false,
],
[
4398046511104,
1 << 42,
'UNKNOWN_FLAG_42',
'This flag is currently not known but is potentially used.',
false,
],
[
8796093022208,
Math.pow(2, 43),
'VERIFIED_EMAIL',
'User has a verified email.',
false,
],
[
17592186044416,
1 << 44,
'QUARANTINED',
'User account is quarantined.',
false,
]
);
// Find them
let flagsFound = Array();
for (let f = 0; f < flags.length; f++) {
// console.log(flags[f][1]);
if (publicFlags & flags[f][1]) {
flagsFound.push(flags[f]);
}
}
// Or else return nothing
return flagsFound;
}
/**
* Get user flags
*/
commands.raw({ name: 'pflags', aliases: ['plags'] }, async (message) => {
// Get the user
const _mentions = message.mentions;
const _msg = message.content.replace('!pflags', '').replaceAll(' ', '');
var _userID = '';
if (_mentions[0]) {
_userID = _mentions[0].id;
} else if (_msg != '') {
_userID = message.content.replace('!pflags', '').replaceAll(' ', '');
}
// Get single user
if (_userID != '') {
// Get the user
const user = await discord.getUser(_userID);
console.log(user);
// Get their nickname
const name = user?.username;
// Get avatar
const avatar = user?.getAvatarUrl();
// Get their flags
const publicFlags = user?.publicFlags;
const flags = getFlags(publicFlags);
// Store flags here
var flagsFound = Array();
// Iterate
flags.forEach((f) => {
var item = '**' + f[0] + '** - ' + f[2] + ': ' + f[3];
flagsFound.push(item);
});
// Message
var msg = '';
if (flagsFound.length > 0) {
msg = flagsFound.join('\n\n');
} else {
msg = 'None.';
}
// Reply
message.reply(
new discord.Embed({
title: `${name} has the following publicFlags:`,
color: (Math.random() * 0xffffff) | 0,
description: msg + '\n',
})
.setTimestamp(new Date().toISOString())
.setThumbnail({ url: avatar })
);
} else {
// Only continue if the channel exists
const channel = await discord.getGuildTextChannel(WELCOME_CHANNEL_ID);
if (!channel) {
return;
}
// Only continue if the guild exists
const guild = await discord.getGuild(channel.guildId);
if (!guild) {
return;
}
// Start counts
var count_users = 0;
var count_flags = 0;
// Get all users
var users = [];
for await (const member of guild.iterMembers()) {
// Skip bots
if (!member.user.bot) {
// Get their nickname
let nick = '';
if (member.nick) {
nick = member.nick;
} else {
nick = member.user.username;
}
// Get flags
if (member.user.publicFlags && member.user.publicFlags != 0) {
// Get their flags
const publicFlags = member.user.publicFlags;
const flags = getFlags(publicFlags);
// Store flags here
var flagsFound = Array();
// Iterate
flags.forEach((f) => {
var item = '> **' + f[0] + '** - ' + f[2] + ': ' + f[3];
flagsFound.push(item);
});
// Count it, too
count_flags++;
// Add to name
nick =
'**' +
nick +
': **\nID: ' +
member.user.id +
'\n' +
flagsFound.join('\n') +
'\n';
// Add the user
users.push(nick);
}
// Count the user
count_users++;
}
}
// Sort alphabetically
users.sort((b, a) => a.localeCompare(b));
// Include s in users
let s = 's';
let has = 'have';
if (count_flags == 1) {
s = '';
has = 'has';
}
// Reply
message.reply(
new discord.Embed({
title: `User Flags`,
color: (Math.random() * 0xffffff) | 0,
description: users.join('\n') + '\n** **',
footer: {
text:
'There are ' +
count_users +
' users total. ' +
count_flags +
' user' +
s +
' ' +
has +
' a public flag.',
},
}).setTimestamp(new Date().toISOString())
);
}
});
/**
* Check spammers in server
*/
commands.raw('spammers', async (message) => {
const channel = await discord.getGuildTextChannel(WELCOME_CHANNEL_ID);
if (!channel) {
return;
}
const guild = await discord.getGuild(channel.guildId);
if (!guild) {
return;
}
// Get the users
var users = [];
var count_spammers = 0;
for await (const member of guild.iterMembers()) {
// Skip bots
if (!member.user.bot) {
// Get flags
if (member.user.publicFlags && member.user.publicFlags & (1 << 20)) {
// if (member.user.publicFlags && member.user.publicFlags == 1048576) {
// Get their nickname
let nick = '';
if (member.nick) {
nick = member.nick;
} else {
nick = member.user.username;
}
// Add the user
users.push(nick);
// Count it
count_spammers++;
}
}
}
// Sort alphabetically
users.sort((b, a) => a.localeCompare(b));
// Include s in users
let s = 's';
let are = 'are';
if (count_spammers == 1) {
s = '';
are = 'is';
}
// Reply
message.reply(
new discord.Embed({
title: `Spammers`,
color: (Math.random() * 0xffffff) | 0,
description: users.join('\n') + '\n\n** **',
footer: {
text:
'There ' +
are +
' ' +
count_spammers +
' spammer' +
s +
' on this server. They are disabled by Discord for being a spammer.',
},
}).setTimestamp(new Date().toISOString())
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment