Skip to content
This repository has been archived by the owner on Jul 15, 2024. It is now read-only.

Commit

Permalink
feat: multiple changes
Browse files Browse the repository at this point in the history
- Remove supporter role
- Fix button execution
- Type definitions in config
- Revamp /ping command
- Define config constants in ExtendedClient
  • Loading branch information
wdhdev committed Jul 29, 2023
1 parent 4e6f573 commit 46b9066
Show file tree
Hide file tree
Showing 19 changed files with 62 additions and 219 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "global-chat",
"version": "3.2.0",
"version": "3.2.1",
"description": "A Discord bot which connects many servers together using a text channel!",
"main": "dist/index.js",
"scripts": {
Expand Down
10 changes: 6 additions & 4 deletions src/classes/ExtendedClient.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { Client, Collection, Snowflake } from "discord.js";
import * as Sentry from "@sentry/node";

import config from "../config";

export default class extends Client {
public buttons: Collection<string, any>;
public commandIds: Collection<string, Snowflake>;
public commands: Collection<string, any>;
public config_channels: any;
public config_embeds: any;
public config_main: any;
public config_roles: any;
public config_channels: typeof config.channels;
public config_embeds: typeof config.embeds;
public config_main: typeof config.main;
public config_roles: typeof config.roles;
public contextCommands: Collection<string, any>;
public events: Collection<string, any>;
public logButtonError: Function;
Expand Down
9 changes: 2 additions & 7 deletions src/classes/Roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ export default class {
public mod: Boolean;
public donator: Boolean;
public verified: Boolean;
public supporter: Boolean;
public immunity: Boolean;

constructor(roles: Role[]) {
const validRoles = ["owner", "dev", "mod", "donator", "verified", "supporter", "immunity"];
const validRoles = ["owner", "dev", "mod", "donator", "verified", "immunity"];

for(const role of roles) {
if(!validRoles.includes(role)) throw new Error(`Invalid role: ${role}`);
Expand All @@ -19,7 +18,6 @@ export default class {
this.mod = roles.includes("mod");
this.donator = roles.includes("donator");
this.verified = roles.includes("verified");
this.supporter = roles.includes("supporter");
this.immunity = roles.includes("immunity");
}

Expand All @@ -31,7 +29,6 @@ export default class {
if(this.mod) roles.push("mod");
if(this.donator) roles.push("donator");
if(this.verified) roles.push("verified");
if(this.supporter) roles.push("supporter");
if(this.immunity) roles.push("immunity");

return roles;
Expand All @@ -44,7 +41,6 @@ export function roleProperCase(role: Role) {
if(role === "mod") return "Moderator";
if(role === "donator") return "Donator";
if(role === "verified") return "Verified";
if(role === "supporter") return "Supporter";
if(role === "immunity") return "Immunity";
}

Expand All @@ -54,8 +50,7 @@ export function roleWithEmoji(role: Role) {
if(role === "mod") return "🔨 Moderator";
if(role === "donator") return "💸 Donator";
if(role === "verified") return "✅ Verified";
if(role === "supporter") return "💖 Supporter";
if(role === "immunity") return "😇 Immunity";
}

export type Role = "owner" | "dev" | "mod" | "donator" | "verified" | "supporter" | "immunity";
export type Role = "owner" | "dev" | "mod" | "donator" | "verified" | "immunity";
31 changes: 1 addition & 30 deletions src/commands/dev/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import User from "../../models/User";

const command: Command = {
name: "admin",
description: "Admin Commands",
description: "Developer Commands",
options: [
{
type: 1,
Expand Down Expand Up @@ -427,35 +427,6 @@ const command: Command = {
return;
}

if(interaction.options.getSubcommand() === "supporters") {
const guild = await client.guilds.fetch(client.config_main.primaryGuild);
const members = await guild.members.fetch();
const boosters = members.filter((member: GuildMember) => member.premiumSinceTimestamp);

const users = [];

for(const [userId, guildMember] of boosters) {
users.push(userId);
}

if(!users.length) {
const error = new Discord.EmbedBuilder()
.setColor(client.config_embeds.error)
.setDescription(`${emoji.cross} There are no supporters!`)

await interaction.editReply({ embeds: [error] });
return;
}

const supporters = new Discord.EmbedBuilder()
.setColor(client.config_embeds.default)
.setTitle("💖 Supporters")
.setDescription(`<@${users.join(">, <@")}>`)

await interaction.editReply({ embeds: [supporters] });
return;
}

if(interaction.options.getSubcommand() === "unverify") {
const user = interaction.options.getUser("user");

Expand Down
16 changes: 2 additions & 14 deletions src/commands/info/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import ExtendedClient from "../../classes/ExtendedClient";
import { CommandInteraction, GuildMember } from "discord.js";

const bot = require("../../../package.json");
import { emojis as emoji } from "../../config";

import BlockedMessage from "../../models/BlockedMessage";
import GitHubUser from "../../models/GitHubUser";
import Message from "../../models/Message";
import User from "../../models/User";

Expand All @@ -31,33 +29,24 @@ const command: Command = {
.setDescription("A Discord bot which connects many servers together using a text channel!")
.addFields (
{ name: "📈 Version", value: bot.version, inline: true },
{ name: "🟢 Online Since", value: `<t:${(Date.now() - client.uptime).toString().slice(0, -3)}:f> (<t:${(Date.now() - client.uptime).toString().slice(0, -3)}:R>)`, inline: true }
{ name: "🟢 Online Since", value: `<t:${(Date.now() - client.uptime).toString().slice(0, -3)}:f>`, inline: true }
)

const developers = await User.find({ dev: true });
const moderators = await User.find({ mod: true });
const verified = await User.find({ verified: true });
const donators = await User.find({ donator: true });

const githubUsers = await GitHubUser.find();

const messages = await Message.find();
const blockedMessages = await BlockedMessage.find();

const guild = await client.guilds.fetch(client.config_main.primaryGuild);
const members = await guild.members.fetch();
const boosters = members.filter((member: GuildMember) => member.premiumSinceTimestamp);

const stat_guilds = `🗄️ ${client.guilds.cache.size} Guild${client.guilds.cache.size === 1 ? "" : "s"}`;
const stat_users = `👤 ${client.users.cache.size} User${client.users.cache.size === 1 ? "" : "s"}`;

const stat_developers = `💻 ${developers.length} Developer${developers.length === 1 ? "" : "s"}`;
const stat_moderators = `🔨 ${moderators.length} Moderator${moderators.length === 1 ? "" : "s"}`;
const stat_donators = `💸 ${donators.length} Donator${donators.length === 1 ? "" : "s"}`;
const stat_verified = `✅ ${verified.length} Verified User${verified.length === 1 ? "" : "s"}`;
const stat_supporters = `💖 ${boosters.size} Supporter${boosters.size === 1 ? "" : "s"}`;

const stat_github = `${emoji.github} ${githubUsers.length}`;

const stat_messages = `💬 ${messages.length} Message${messages.length === 1 ? "" : "s"}`;
const stat_blocked_messages = `⛔ ${blockedMessages.length} Blocked Message${messages.length === 1 ? "" : "s"}`;
Expand All @@ -67,8 +56,7 @@ const command: Command = {
.setTitle("Statistics")
.addFields (
{ name: "🤖 Bot", value: `${stat_guilds}\n${stat_users}`, inline: true },
{ name: "🎭 Roles", value: `${stat_developers}\n${stat_moderators}\n${stat_donators}\n${stat_verified}\n${stat_supporters}`, inline: true },
{ name: "🔗 Linked Accounts", value: `${stat_github}`, inline: true },
{ name: "🎭 Roles", value: `${stat_developers}\n${stat_moderators}\n${stat_donators}\n${stat_verified}`, inline: true },
{ name: "🌐 Global Chat", value: `${stat_messages}\n${stat_blocked_messages}`, inline: true }
)

Expand Down
27 changes: 10 additions & 17 deletions src/commands/info/ping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,47 +15,40 @@ const command: Command = {
enabled: true,
allowWhileBanned: false,
staffOnly: false,
deferReply: true,
ephemeral: true,
deferReply: false,
ephemeral: false,
async execute(interaction: CommandInteraction, client: ExtendedClient, Discord: any) {
try {
const pinging = new Discord.EmbedBuilder()
.setColor(client.config_embeds.default)
.setDescription(`${emoji.ping} Pinging...`)

const i = await interaction.editReply({ embeds: [pinging] });

const botLatency = i.createdTimestamp - interaction.createdTimestamp;
const botLatency = Date.now() - interaction.createdTimestamp;
const apiLatency = Math.round(client.ws.ping);

let botLatencyValue;
let apiLatencyValue;

if(botLatency >= 0 && botLatency <= 99) {
botLatencyValue = `🟢 ${botLatency}ms`;
botLatencyValue = `${emoji.connection_excellent} ${botLatency}ms`;
} else if(botLatency >= 100 && botLatency <= 199) {
botLatencyValue = `🟠 ${botLatency}ms`;
botLatencyValue = `${emoji.connection_good} ${botLatency}ms`;
} else {
botLatencyValue = `🔴 ${botLatency}ms`;
botLatencyValue = `${emoji.connection_bad} ${botLatency}ms`;
}

if(apiLatency >= 0 && apiLatency <= 99) {
apiLatencyValue = `🟢 ${apiLatency}ms`;
apiLatencyValue = `${emoji.connection_excellent} ${apiLatency}ms`;
} else if(apiLatency >= 100 && apiLatency <= 199) {
apiLatencyValue = `🟠 ${apiLatency}ms`;
apiLatencyValue = `${emoji.connection_good} ${apiLatency}ms`;
} else {
apiLatencyValue = `🔴 ${apiLatency}ms`;
apiLatencyValue = `${emoji.connection_bad} ${apiLatency}ms`;
}

const ping = new Discord.EmbedBuilder()
.setColor(client.config_embeds.default)
.setTitle("🏓 Pong!")
.addFields (
{ name: "Bot Latency", value: botLatencyValue, inline: true },
{ name: "API Latency", value: apiLatencyValue, inline: true }
)

await interaction.editReply({ embeds: [ping] });
await interaction.reply({ embeds: [ping] });
} catch(err) {
client.logCommandError(err, interaction, Discord);
}
Expand Down
13 changes: 2 additions & 11 deletions src/commands/mod/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CommandInteraction } from "discord.js";
import { emojis as emoji } from "../../config";
import { getInfractions } from "../../classes/Infraction";
import getRoles from "../../functions/roles/get";
import { Role } from "../../classes/Roles";

import BannedUser from "../../models/BannedUser";
import BlockedMessage from "../../models/BlockedMessage";
Expand Down Expand Up @@ -48,17 +49,7 @@ const command: Command = {
const banData = banned ? `🕰️ <t:${banInfo.timestamp.slice(0, -3)}> (<t:${banInfo.timestamp.slice(0, -3)}:R>)\n📜 ${banInfo.allowAppeal ? "Appealable" : "Not Appealable"}\n❓ ${banInfo.reason}\n🔨 <@${banInfo.mod}>` : null;

// Roles
const role = await getRoles(user.id, client);

const roles = [];

if(role.owner) roles.push("👑 Owner");
if(role.dev) roles.push("💻 Developer");
if(role.mod) roles.push("🔨 Moderator");
if(role.donator) roles.push("💸 Donator");
if(role.verified) roles.push("✅ Verified");
if(role.supporter) roles.push("💖 Supporter");
if(role.immunity) roles.push("😇 Immunity");
const roles: Role[] = (await getRoles(interaction.user.id, client)).get();

// Linked Accounts
const accounts = [];
Expand Down
13 changes: 2 additions & 11 deletions src/commands/user/me.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { CommandInteraction } from "discord.js";

import { emojis as emoji } from "../../config";
import getRoles from "../../functions/roles/get";
import { Role } from "../../classes/Roles";

import BlockedMessage from "../../models/BlockedMessage";
import GitHubUser from "../../models/GitHubUser";
Expand All @@ -25,17 +26,7 @@ const command: Command = {
async execute(interaction: CommandInteraction, client: ExtendedClient, Discord: any) {
try {
// Roles
const role = await getRoles(interaction.user.id, client);

const roles = [];

if(role.owner) roles.push("👑 Owner");
if(role.dev) roles.push("💻 Developer");
if(role.mod) roles.push("🔨 Moderator");
if(role.donator) roles.push("💸 Donator");
if(role.verified) roles.push("✅ Verified");
if(role.supporter) roles.push("💖 Supporter");
if(role.immunity) roles.push("😇 Immunity");
const roles: Role[] = (await getRoles(interaction.user.id, client)).get();

// Linked Accounts
const accounts = [];
Expand Down
12 changes: 2 additions & 10 deletions src/commands/user/my-roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ExtendedClient from "../../classes/ExtendedClient";
import { CommandInteraction } from "discord.js";

import getRoles from "../../functions/roles/get";
import { Role } from "../../classes/Roles";

const command: Command = {
name: "my-roles",
Expand All @@ -19,16 +20,7 @@ const command: Command = {
ephemeral: true,
async execute(interaction: CommandInteraction, client: ExtendedClient, Discord: any) {
try {
const role = await getRoles(interaction.user.id, client);

const roles = [];

if(role.owner) roles.push("👑 Owner");
if(role.dev) roles.push("💻 Developer");
if(role.mod) roles.push("🔨 Moderator");
if(role.donator) roles.push("💸 Donator");
if(role.verified) roles.push("✅ Verified");
if(role.supporter) roles.push("💖 Supporter");
const roles: Role[] = (await getRoles(interaction.user.id, client)).get();

const rolesEmbed = new Discord.EmbedBuilder()
.setColor(client.config_embeds.default)
Expand Down
34 changes: 17 additions & 17 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ColorResolvable } from "discord.js";
import { ColorResolvable, EmojiResolvable, RoleResolvable, Snowflake } from "discord.js";

const channels = {
const channels: { [key: string]: Snowflake } = {
appeals: "1083298359319736320",
blocked: "1078093240105975848",
logs: "1117236422164885514",
Expand All @@ -9,17 +9,21 @@ const channels = {
reports: "1067341548393615430"
}

const embeds = {
default: "#0096FF" as ColorResolvable,
error: "#E74C3C" as ColorResolvable,
github: "#171515" as ColorResolvable,
gray: "#80838D" as ColorResolvable,
green: "#57F287" as ColorResolvable,
red: "#ED4245" as ColorResolvable
const embeds: { [key: string]: ColorResolvable } = {
default: "#0096FF",
error: "#E74C3C",
github: "#171515",
gray: "#80838D",
green: "#57F287",
red: "#ED4245"
}

const emojis = {
const emojis: { [key: string]: EmojiResolvable } = {
connection_bad: "<:connection_bad:1134804962732429332>",
connection_good: "<:connection_good:1134804958793977928>",
connection_excellent: "<:connection_excellent:1134809429783617557>",
cross: "<:cross:1127043491642478592>",
developer: "<:developer:1134808090496208938>",
discord: "<:discord:1134618172625006742>",
github: "<:github:1129227804693774346>",
ping: "<a:ping:1127044182352072786>",
Expand All @@ -28,15 +32,11 @@ const emojis = {
}

const main = {
hasGuildOnlyCommands: [
"1067023529226293248" // Global Chat Support
],
owner: "853158265466257448", // williamharrison
primaryGuild: "1067023529226293248" // Global Chat Support
owner: "853158265466257448" as Snowflake, // williamharrison
primaryGuild: "1067023529226293248" as Snowflake // Global Chat Support
}

const roles = {
booster: "1115056722042703942",
const roles: { [key: string]: RoleResolvable } = {
dev: "1067023529305976898",
donator: "1127426331286712320",
mod: "1082167230357307402",
Expand Down
Loading

0 comments on commit 46b9066

Please sign in to comment.