Skip to content

feat: add lookup command and manual verification fixes #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
259 changes: 259 additions & 0 deletions bun.lock

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
"name": "cybermonay-verify-site",
"module": "index.js",
"type": "module",
"scripts": {
"start": "bun run src/index.js",
"format": "prettier --write src/"
},
"devDependencies": {
"bun-types": "latest",
"prettier": "^3.2.5"
"prettier": "^3.5.1"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"scripts": {
"start": "bun run src/index.js",
"format": "prettier --write src/"
"typescript": "^5.4.5"
},
"dependencies": {
"@discordjs/core": "^1.1.1",
"discord.js": "^14.14.1",
"express": "^4.18.2",
"express-session": "^1.17.3",
"pg": "^8.11.3"
"@discordjs/core": "^2.0.1",
"discord.js": "^14.18.0",
"express": "^4.21.2",
"express-session": "^1.18.1",
"pg": "^8.13.3"
}
}
35 changes: 35 additions & 0 deletions src/commands/lookup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {
SlashCommandBuilder,
EmbedBuilder,
} from 'discord.js';
import { getIpData } from '../util/ip.js';

/** @type {import('./index.js').Command} */
export default {
data: new SlashCommandBuilder()
.setName('lookup')
.setDescription('Lookup an IP address')
.addStringOption((option) =>
option
.setName('ip')
.setDescription('The IP address to lookup')
.setRequired(true),
),

async execute(interaction) {
const ip = interaction.options.getString('ip');
const ipData = await getIpData(ip);
const embed = new EmbedBuilder()
.setTitle(`IP lookup of ${ip}`)
.setDescription(`
Country: ${ipData.country}
Timezone: ${ipData.timezone}
ISP: ${ipData.isp}
ORG: ${ipData.org}
AS: ${ipData.as}
AS Name: ${ipData.asname}
`)
.setColor('#57b9ff');
await interaction.editReply({ embeds: [embed], components: []});
},
};
29 changes: 17 additions & 12 deletions src/commands/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
PermissionFlagsBits,
ChatInputCommandInteraction,
} from 'discord.js';
import { grantRole } from '../util/discordManager.js';
import { memberRoles } from '../index.js';
import * as db from '../util/db.js';

/** @type {import('./index.js').Command} */
Expand All @@ -23,16 +25,7 @@ export default {
.setRequired(true),
),
async execute(interaction) {
const verifiedRole = interaction.guild.roles.cache.find(
(role) => role.id === process.env.ROLE_ID,
);
if (!verifiedRole) {
return interaction.reply({
content:
'The verified role could not be found. Please check the role ID in the environment variables.',
ephemeral: true,
});
}
const verifiedRoleNames = [];
const ip = interaction.options.getString('ip');

const targetMember = await interaction.guild.members.fetch(
Expand All @@ -47,12 +40,24 @@ export default {
ephemeral: true,
});
}
const formatter = new Intl.ListFormat('en', { style: 'long', type: 'conjunction' });
for (const role of memberRoles) {
const verifiedRole = interaction.guild.roles.cache.find((r) => r.id === role);
if (!verifiedRole) {
return interaction.reply({
content:
'The verified role could not be found. Please check the role ID in the environment variables.',
ephemeral: true,
});
}
verifiedRoleNames.push(verifiedRole.name);
}

await db.setData(targetMember.id, ip);
await targetMember.roles.add(verifiedRole);
await grantRole(guild, id, memberRoles);

return interaction.reply({
content: `${targetMember.id} has been verified and granted the ${verifiedRole.name} role.`,
content: `${targetMember.id} has been verified and granted the ${formatter.format(verifiedRoleNames)} role${verifiedRoleNames.length > 1 ? "s": ""}.`,
ephemeral: false,
});
},
Expand Down
9 changes: 2 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,9 @@ import session from 'express-session';
import crypto from 'crypto';
import * as db from './util/db.js';
import * as oauth from './util/oauth.js';
import { getIpData } from './util/ip.js';
import { checkRole, grantRole, logWebhook } from './util/discordManager.js';

async function getIpData(ip) {
const query = await fetch(`http://ip-api.com/json/${ip}?fields=16990208`);
const data = await query.json();
return data;
}

// Initialize the Discord client
const client = new Client({
intents: [
Expand All @@ -28,7 +23,7 @@ const client = new Client({
});

// Add your member roles to this array
const memberRoles = [process.env.ROLE_ID, process.env.ROLE_ID_2];
export const memberRoles = [process.env.ROLE_ID, process.env.ROLE_ID_2];

// Add your flagged alt account roles to this array. Comment this line out if you're not using it. Make sure to also comment out the grantRole function that grants this role.
const altRole = process.env.ALT_ROLE_ID;
Expand Down
5 changes: 5 additions & 0 deletions src/util/ip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export async function getIpData(ip) {
const query = await fetch(`http://ip-api.com/json/${ip}?fields=66842623`);
const data = await query.json();
return data;
}