Skip to content

Commit 718c5f7

Browse files
authored
Bugfix/schiltz3/deepsource (#28)
# Fix all deepsource issues - Replace any with generics - Move non-export functions to before use - Remove unused variables - Add missing `await`s - Correctly type `resolve` in `sleep` - Remove non-null assertion postfixes for strict null checking
2 parents 1f391bf + bdc1a1c commit 718c5f7

File tree

14 files changed

+68
-52
lines changed

14 files changed

+68
-52
lines changed

commands/owner/csClassPoll.ts

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,25 @@ import chalk from "chalk";
88
import { ICommand } from "wokcommands";
99
import { classModel, IClass } from "../../models/classModel";
1010
import { checkForRoles } from "../../rolesOps";
11+
import { sleep } from "../../util";
1112

13+
// Splits any size list into lists of at most `max_list_len`
14+
function split_list<T>(list: T[], max_list_len: number): T[][] {
15+
const class_chunks: T[][] = [];
16+
for (let i = 0; i < list.length; i += max_list_len) {
17+
class_chunks.push(list.slice(i, i + max_list_len));
18+
}
19+
return class_chunks;
20+
}
21+
22+
// consumes a Class and returns Message Selec tOption data
23+
function create_option_from_class(_class: IClass): MessageSelectOptionData {
24+
return {
25+
label: _class.CODE,
26+
value: _class.CODE,
27+
description: _class.TITLE,
28+
};
29+
}
1230
export default {
1331
name: "csClassPoll",
1432
category: "owner",
@@ -20,7 +38,11 @@ export default {
2038
ownerOnly: true,
2139

2240
callback: async ({ client, interaction: msgInt }) => {
23-
if (!checkForRoles(msgInt.guild!)) {
41+
if (msgInt.guild === null) {
42+
console.log(chalk.red("No guild"));
43+
return;
44+
}
45+
if (!(await checkForRoles(msgInt.guild))) {
2446
msgInt.reply(
2547
"Please run the `/ createRoles` command in this server to create the necessary roles for this poll!"
2648
);
@@ -30,7 +52,7 @@ export default {
3052
const classes = await classModel.find({}).sort({ CODE: 1 });
3153
const class_chunks = split_list(classes, 25);
3254

33-
let rows: MessageActionRow[] = [];
55+
const rows: MessageActionRow[] = [];
3456
for (let index = 0; index < class_chunks.length; index++) {
3557
const menu = new MessageSelectMenu();
3658
menu.setCustomId(`csClassPoll+${index}`);
@@ -63,12 +85,10 @@ export default {
6385

6486
msgInt.reply({ embeds: [infoEmbed], components: row_chunks[index] });
6587
} else {
66-
msgInt.channel!.send({ components: row_chunks[index] });
88+
msgInt.reply({ components: row_chunks[index] });
6789
}
68-
// await on a new promise that resolves itself after a delay of 200 ms
69-
await new Promise((resolve) => {
70-
setTimeout(resolve, 200);
71-
});
90+
91+
await sleep(200);
7292
}
7393

7494
// Log the command usage
@@ -83,21 +103,3 @@ export default {
83103
);
84104
},
85105
} as ICommand;
86-
87-
// Splits any size list into lists of at most `max_list_len`
88-
function split_list(list: Array<any>, max_list_len: number) {
89-
let class_chunks = [];
90-
for (let i = 0; i < list.length; i += max_list_len) {
91-
class_chunks.push(list.slice(i, i + max_list_len));
92-
}
93-
return class_chunks;
94-
}
95-
96-
// consumes a Class and returns Message Selec tOption data
97-
function create_option_from_class(_class: IClass): MessageSelectOptionData {
98-
return {
99-
label: _class.CODE,
100-
value: _class.CODE,
101-
description: _class.TITLE,
102-
};
103-
}

commands/owner/staffPoll.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,12 @@ export default {
5858
)
5959
);
6060

61+
if (msgInt.guild === null) {
62+
console.log(chalk.red("No guild"));
63+
return;
64+
}
6165
// Send the embed and message component rows
62-
if (!checkForRoles(msgInt.guild!)) {
66+
if (!(await checkForRoles(msgInt.guild))) {
6367
msgInt.reply(
6468
"Please run the `/createRoles` command in this server to create the necessary roles for this poll!"
6569
);

commands/owner/yearPoll.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,19 @@ export default {
6666
)
6767
);
6868

69+
if (msgInt.guild === null) {
70+
console.log(chalk.red("No guild"));
71+
return;
72+
}
6973
// Send the embed and message component rows
70-
if (!checkForRoles(msgInt.guild!)) {
71-
msgInt.reply({
74+
if (!(await checkForRoles(msgInt.guild))) {
75+
await msgInt.reply({
7276
content:
7377
"Please run the /createRoles command in this server to create the necessary roles for this poll!",
7478
ephemeral: true,
7579
});
7680
} else {
77-
msgInt.reply({ embeds: [infoEmbed], components: [row] });
81+
await msgInt.reply({ embeds: [infoEmbed], components: [row] });
7882
}
7983

8084
// Log the command usage

commands/user/github.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default {
3030
.setDescription(description)
3131
.setFooter({ text: footer, iconURL: footerIcon });
3232

33-
interaction.reply({ embeds: [Embed] });
33+
await interaction.reply({ embeds: [Embed] });
3434

3535
// Log the command usage
3636
console.log(

commands/user/help.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export default {
5353
.setDescription(description)
5454
.addFields(fields)
5555
.setFooter({ text: footer, iconURL: footerIcon });
56-
interaction.reply({ embeds: [Embed] });
56+
await interaction.reply({ embeds: [Embed] });
5757

5858
// Log the command usage
5959
console.log(

commands/user/ping.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default {
2626
.setFooter({ text: footer, iconURL: footerIcon });
2727

2828
// Return the embed
29-
interaction.reply({ embeds: [Embed] });
29+
await interaction.reply({ embeds: [Embed] });
3030

3131
// Log the command usage
3232
console.log(

commands/user/status.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default {
3030
.setDescription(description)
3131
.setFooter({ text: footer, iconURL: footerIcon });
3232

33-
interaction.reply({ embeds: [Embed] });
33+
await interaction.reply({ embeds: [Embed] });
3434

3535
// Log the command usage
3636
console.log(

commands/user/uptime.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import chalk from "chalk";
2-
import { MessageEmbed, TextChannel } from "discord.js";
2+
import { MessageEmbed } from "discord.js";
33
import { ICommand } from "wokcommands";
44

55
export default {
@@ -12,12 +12,8 @@ export default {
1212
requiredPermissions: ["SEND_MESSAGES"],
1313

1414
callback: async ({ client, interaction }) => {
15-
// Command information
16-
const id = interaction.user.id;
17-
const chan = interaction.channel as TextChannel;
18-
1915
// Computed values
20-
const time = client.uptime!;
16+
const time = client.uptime !== null ? client.uptime : 0;
2117
const days = Math.floor(time / 86400000);
2218
const hours = Math.floor(time / 3600000) % 24;
2319
const minutes = Math.floor(time / 60000) % 60;
@@ -38,7 +34,7 @@ export default {
3834
.setFooter({ text: footer, iconURL: footerIcon });
3935

4036
// Return the embed
41-
interaction.reply({ embeds: [Embed] });
37+
await interaction.reply({ embeds: [Embed] });
4238

4339
// Log the command usage
4440
console.log(

commands/user/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default {
2626
.setFooter({ text: footer, iconURL: footerIcon });
2727

2828
// Return the embed
29-
interaction.reply({ embeds: [Embed] });
29+
await interaction.reply({ embeds: [Embed] });
3030

3131
// Log the command usage
3232
console.log(

features/status-changer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Client } from "discord.js";
22

3-
export default async (client: Client) => {
3+
export default (client: Client) => {
44
const statusOptions = [
55
`/help | Ping: ${client.ws.ping}ms`,
66
`V.${process.env.VERSION}`,

0 commit comments

Comments
 (0)