Skip to content

Commit

Permalink
wow uh yes
Browse files Browse the repository at this point in the history
  • Loading branch information
MrSerge01 committed Nov 27, 2024
1 parent 482dc0b commit e6979c1
Show file tree
Hide file tree
Showing 14 changed files with 147 additions and 197 deletions.
9 changes: 4 additions & 5 deletions src/bot.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ActivityType, Client } from "discord.js";
import { Commands } from "./handlers/commands";
import { Events } from "./handlers/events";
import { registerCommands } from "./handlers/commands";
import { loadEvents } from "./handlers/events";
import { rescheduleUnbans } from "./utils/unbanScheduler";

const client = new Client({
Expand All @@ -12,15 +12,14 @@ const client = new Client({
"GuildMembers",
"GuildMessages",
"GuildEmojisAndStickers",
"GuildPresences",
"GuildBans",
"MessageContent"
]
});

client.on("ready", async () => {
await new Events(client).loadEvents();
await new Commands(client).registerCommands();
await loadEvents(client);
await registerCommands(client);
console.log("ちーっす!");
rescheduleUnbans(client);
});
Expand Down
6 changes: 3 additions & 3 deletions src/commands/Leaderboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ export default class Leaderboard {
else return b.xp - a.xp;
});

const totalPages = Math.ceil(leaderboardData.length / 5);
const totalPages = Math.ceil(leaderboardData.length / 6);
let page = interaction.options.getNumber("page") || 1;
page = Math.max(1, Math.min(page, totalPages));
const generateEmbed = async () => {
const start = (page - 1) * 5;
const end = start + 5;
const start = (page - 1) * 6;
const end = start + 6;
const pageData = leaderboardData.slice(start, end);

const embed = new EmbedBuilder()
Expand Down
9 changes: 4 additions & 5 deletions src/commands/moderation/Ban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,13 @@ export default class Ban {
}

try {
await modEmbed(
{ interaction, user, action: "Banned", duration, dm: true, dbAction: "BAN", expiresAt },
reason
);
await guild.members.ban(user.id, { reason: reason ?? undefined });
} catch (err) {
console.error("Failed to ban user:", err);
}

await modEmbed(
{ interaction, user, action: "Banned", duration, dm: true, dbAction: "BAN", expiresAt },
reason
);
}
}
10 changes: 7 additions & 3 deletions src/commands/moderation/Delwarn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ export default class Delwarn {
if (
await errorCheck(
PermissionsBitField.Flags.ModerateMembers,
{ interaction, user, action: "Remove a warn" },
{ interaction, user, action: "Remove a warning" },
{ allErrors: true, botError: false },
"Moderate Members"
)
)
return;

if (newWarns.length == warns.length)
return await errorEmbed(interaction, `There is no warn with the id of ${id}.`);
return await errorEmbed(interaction, `There is no warning with the id of ${id}.`);

const embed = new EmbedBuilder()
.setAuthor({ name: `• Removed a warning from ${name}`, iconURL: user.displayAvatarURL() })
Expand All @@ -65,6 +65,10 @@ export default class Delwarn {
const dmChannel = (await user.createDM().catch(() => null)) as DMChannel | null;
if (!dmChannel) return;
if (user.bot) return;
await dmChannel.send({ embeds: [embed.setTitle("Your warning has been removed.")] });
try {
await dmChannel.send({ embeds: [embed.setTitle("Your warning has been removed.")] });
} catch (e) {
console.log(e);
}
}
}
3 changes: 1 addition & 2 deletions src/commands/moderation/Kick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ export default class Kick {
);

const reason = interaction.options.getString("reason");
await modEmbed({ interaction, user, action: "Kicked", dm: true, dbAction: "KICK" }, reason);
await interaction.guild?.members.cache
.get(user.id)
?.kick(reason ?? undefined)
.catch(error => console.error(error));

await modEmbed({ interaction, user, action: "Kicked", dm: true, dbAction: "KICK" }, reason);
}
}
10 changes: 5 additions & 5 deletions src/commands/moderation/Mute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ export default class Mute {
Date.parse(new Date().toISOString()) + Date.parse(new Date(ms(duration)).toISOString())
).toISOString();

await interaction.guild?.members.cache
.get(user.id)
?.edit({ communicationDisabledUntil: time, reason: reason ?? undefined })
.catch(error => console.error(error));

await modEmbed(
{ interaction, user, action: "Muted", duration, dm: true, dbAction: "MUTE" },
reason,
true
);

await interaction.guild?.members.cache
.get(user.id)
?.edit({ communicationDisabledUntil: time, reason: reason ?? undefined })
.catch(error => console.error(error));
}
}
2 changes: 1 addition & 1 deletion src/commands/moderation/Unban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default class Unban {
"The user was never banned."
);

await guild.members.unban(id, reason ?? undefined).catch(error => console.error(error));
await modEmbed({ interaction, user: target, action: "Unbanned" }, reason);
await guild.members.unban(id, reason ?? undefined).catch(error => console.error(error));
}
}
2 changes: 1 addition & 1 deletion src/commands/moderation/Unmute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class Unmute {
"The user was never muted."
);

await target.edit({ communicationDisabledUntil: null }).catch(error => console.error(error));
await modEmbed({ interaction, user, action: "Unmuted" });
await target.edit({ communicationDisabledUntil: null }).catch(error => console.error(error));
}
}
16 changes: 10 additions & 6 deletions src/events/guildCreate.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { EmbedBuilder, type DMChannel } from "discord.js";
import { Commands } from "../handlers/commands";
import { commands } from "../handlers/commands";
import { genColor } from "../utils/colorGen";
import { randomise } from "../utils/randomise";
import { Event } from "../utils/types";

export default (async function run(guild) {
const dmChannel = (await (await guild.fetchOwner()).createDM().catch(() => null)) as
| DMChannel
| undefined;
const owner = await guild.fetchOwner();
if (owner.user.bot) return;

const dmChannel = (await owner.createDM().catch(() => null)) as DMChannel | undefined;
let emojis = ["💖", "💝", "💓", "💗", "💘", "💟", "💕", "💞"];
if (Math.round(Math.random() * 100) <= 5) emojis = ["⌨️", "💻", "🖥️"];

Expand All @@ -29,6 +29,10 @@ export default (async function run(guild) {
.setThumbnail(client.user.displayAvatarURL())
.setColor(genColor(200));

await new Commands(client).registerCommandsForGuild(guild);
if (dmChannel) await dmChannel.send({ embeds: [embed] });
await guild.commands.set(commands.map(command => command.data));
try {
if (dmChannel) await dmChannel.send({ embeds: [embed] });
} catch (e) {
console.log(e);
}
} as Event<"guildCreate">);
6 changes: 5 additions & 1 deletion src/events/guildMemberAdd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,9 @@ export default (async function run(member) {
if (user.bot) return;

replace(member, getSetting(guildID, "welcome", "dm_text") as string, embed);
await dmChannel.send({ embeds: [embed] }).catch(() => null);
try {
await dmChannel.send({ embeds: [embed] }).catch(() => null);
} catch (e) {
return console.log(e);
}
} as Event<"guildMemberAdd">);
16 changes: 10 additions & 6 deletions src/events/interactionCreate.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { Commands } from "../handlers/commands";
import { commands, subCommands } from "../handlers/commands";
import { Event } from "../utils/types";

export default (async function run(interaction) {
if (!interaction.isChatInputCommand() && !interaction.isAutocomplete()) return;
const command = await new Commands(interaction.client).getCommand(
interaction.commandName,
interaction.options
);
if (!command) return;
let command;
const subCommand = subCommands.filter(
subCommand => subCommand.data.name == interaction.options.getSubcommand(false)
)[0];

if (!subCommand)
command = commands.filter(command => command.data.name == interaction.commandName)[0];
else command = subCommand;

if (!command) return;
if (interaction.isChatInputCommand()) command.run(interaction);
if (command.autocomplete) command.autocomplete(interaction);
} as Event<"interactionCreate">);
Loading

0 comments on commit e6979c1

Please sign in to comment.