Skip to content

Commit e0b4148

Browse files
authored
Merge pull request #65 from Chiissu/dev
0.3.1... the quickest patch ever
2 parents 41d6b82 + 3074898 commit e0b4148

37 files changed

+350
-342
lines changed

bun.lock

Lines changed: 95 additions & 166 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker-compose.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ services:
66
volumes:
77
- ./data.db:/app/data.db
88
- ./.env:/app/.env
9-

package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"The Sokora team",
66
"The GitHub contributors"
77
],
8-
"version": "0.3",
8+
"version": "0.3.1",
99
"main": "./src/index.ts",
1010
"type": "module",
1111
"scripts": {
@@ -19,15 +19,14 @@
1919
"@top-gg/sdk": "^3.1.6",
2020
"chart.js": "^4.5.0",
2121
"chartjs-node-canvas": "^5.0.0",
22-
"discord.js": "^14.21.0",
22+
"discord.js": "^14.22.1",
23+
"enhanced-ms": "^4.1.0",
2324
"mathjs": "^14.6.0",
24-
"ms": "^2.1.3",
25-
"node-vibrant": "^3.2.1-alpha.1",
26-
"sharp": "^0.33.5"
25+
"node-vibrant": "^4.0.3",
26+
"sharp": "^0.34.3"
2727
},
2828
"devDependencies": {
2929
"@eslint/js": "^9.33.0",
30-
"@types/ms": "^0.7.34",
3130
"@typescript-eslint/eslint-plugin": "^8.40.0",
3231
"@typescript-eslint/parser": "^8.40.0",
3332
"bun-types": "^1.2.20",

src/bot.ts

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { Api } from "@top-gg/sdk";
22
import { Chart, registerables } from "chart.js";
3-
import { getUserSettingsTable } from "database/userSettings";
3+
import { getUserSettingsTable, setUserSetting } from "database/userSettings";
44
import { ActivityType, Client, Partials } from "discord.js";
5+
import { errorEmbed } from "embeds/errorEmbed";
6+
import ms from "enhanced-ms";
57
import { registerGuildCommands } from "handlers/commands";
68
import { loadAuditEvents, loadEasterEggs, loadEvents } from "handlers/events";
7-
import ms from "ms";
89
import { rescheduleUnbans } from "utils/unbanScheduler";
910

1011
export const client = new Client({
@@ -13,6 +14,7 @@ export const client = new Client({
1314
},
1415
partials: [Partials.Message, Partials.Reaction, Partials.User],
1516
intents: [
17+
"DirectMessages",
1618
"Guilds",
1719
"GuildMembers",
1820
"GuildMessages",
@@ -24,32 +26,48 @@ export const client = new Client({
2426
],
2527
});
2628

27-
export const subscribedUsers = new Set(
28-
(await getUserSettingsTable("topgg", "remind"))?.filter(i => i.value == "1").map(i => i.userID),
29-
);
29+
client.once("clientReady", async () => {
30+
if (process.env.TOPGG_TOKEN)
31+
setInterval(async () => {
32+
const topgg = new Api(process.env.TOPGG_TOKEN!);
33+
try {
34+
await topgg.postStats({
35+
serverCount: (await client.guilds.fetch()).size,
36+
});
37+
console.log("Posted statistics to top.gg!");
38+
} catch (error) {
39+
console.error(`Failed to start top.gg autoposter: ${error}`);
40+
}
3041

31-
client.once("ready", async () => {
32-
if (process.env.TOPGG_TOKEN) {
33-
const topgg = new Api(process.env.TOPGG_TOKEN!);
34-
try {
35-
await topgg.postStats({
36-
serverCount: (await client.guilds.fetch()).size,
37-
});
38-
console.log("Posted statistics to top.gg!");
39-
} catch (error) {
40-
console.error(`Failed to start top.gg autoposter: ${error}`);
41-
}
42+
const users = client.users;
43+
const subscribedUsers = new Set(
44+
(await getUserSettingsTable("topgg", "remind"))
45+
?.filter(i => i.value == "1")
46+
.map(i => i.userID),
47+
);
4248

43-
setInterval(async () => {
4449
for (const user of subscribedUsers) {
45-
if (await topgg.hasVoted(user)) continue;
46-
await client.users.send(
47-
JSON.parse(user),
48-
"Reminder that **you can vote for Sokora** on [top.gg](https://top.gg/bot/873918300726394960/vote) - go vote!!",
49-
);
50+
try {
51+
if (await topgg.hasVoted(user)) continue;
52+
const dmChannel = await (await users.fetch(JSON.parse(user))).createDM();
53+
if (!dmChannel || !dmChannel.isSendable()) continue;
54+
55+
await dmChannel.send(
56+
"Reminder that **you can vote for Sokora** on [top.gg](https://top.gg/bot/873918300726394960/vote) - go vote!!",
57+
);
58+
} catch (error) {
59+
await errorEmbed({
60+
client,
61+
error,
62+
title: "top.gg reminding error.",
63+
log: true,
64+
forward: true,
65+
fileName: "bot.ts",
66+
});
67+
await setUserSetting(user, "topgg", "remind", false);
68+
}
5069
}
51-
}, ms("3h"));
52-
}
70+
}, ms("6h"));
5371

5472
await Promise.all([
5573
loadEvents(client),

src/commands/about.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,5 @@ export async function run(interaction: ChatInputCommandInteraction) {
6767
.setStyle(ButtonStyle.Link),
6868
);
6969

70-
await interaction.reply({ embeds: [embed], components: [row] });
70+
await interaction.reply({ embeds: [embed], components: [row], flags: "Ephemeral" });
7171
}

src/commands/changelog.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ export async function run(interaction: ChatInputCommandInteraction) {
2222
.setFooter({ text: replace("(madeWith)") })
2323
.setColor(await colorize({ user, avatar, hue: 270 }));
2424

25-
await interaction.reply({ embeds: [embed] });
25+
await interaction.reply({ embeds: [embed], flags: "Ephemeral" });
2626
}

src/commands/credits.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ export async function run(interaction: ChatInputCommandInteraction) {
2828
.setFooter({ text: replace("(madeWith)") })
2929
.setColor(await colorize({ user, avatar, hue: 270 }));
3030

31-
await interaction.reply({ embeds: [embed] });
31+
await interaction.reply({ embeds: [embed], flags: "Ephemeral" });
3232
}

src/commands/help/variables.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,5 @@ export async function run(interaction: ChatInputCommandInteraction) {
5858
},
5959
]);
6060

61-
await interaction.reply({ embeds: [embed] });
61+
await interaction.reply({ embeds: [embed], flags: "Ephemeral" });
6262
}

src/commands/moderation/ban.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { getSetting } from "database/settings";
22
import { SlashCommandSubcommandBuilder, type ChatInputCommandInteraction } from "discord.js";
33
import { errorEmbed } from "embeds/errorEmbed";
44
import { errorCheck, modEmbed } from "embeds/modEmbed";
5-
import ms from "ms";
5+
import ms from "enhanced-ms";
66
import { scheduleUnban } from "utils/unbanScheduler";
77

88
export const data = new SlashCommandSubcommandBuilder()
@@ -66,7 +66,7 @@ export async function run(interaction: ChatInputCommandInteraction) {
6666
interaction,
6767
user,
6868
action: "Banned",
69-
duration,
69+
duration: duration ? ms(duration) : undefined,
7070
dm: true,
7171
dbAction: "BAN",
7272
expiresAt: duration ? ms(duration) : undefined,

src/commands/moderation/cases.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
type ChatInputCommandInteraction,
1818
} from "discord.js";
1919
import { errorEmbed } from "embeds/errorEmbed";
20-
import ms from "ms";
20+
import ms from "enhanced-ms";
2121
import { client } from "src/bot";
2222
import { capitalize } from "utils/capitalize";
2323
import { genColor } from "utils/colorGen";
@@ -62,8 +62,7 @@ async function generateEmbed(params: {
6262
];
6363

6464
if (!user) val.unshift(`**User**: <@${c.user}>`);
65-
if (c.expiresAt)
66-
val.push(`**Duration**: ${ms(ms(Number(c.expiresAt).toString()), { long: true })}`);
65+
if (c.expiresAt) val.push(`**Duration**: ${ms(Number(c.expiresAt), "fullPrecision")}`);
6766

6867
return {
6968
name: `${actionsEmojis[c.type as ModType]}${capitalize(c.type.toLowerCase())} #${c.id}`,

0 commit comments

Comments
 (0)