Skip to content

Commit 83264d9

Browse files
committed
refactory js to ts in lib/database
1 parent a42d43c commit 83264d9

21 files changed

+387
-183
lines changed

commands/admin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { SlashCommandBuilder } = require("@discordjs/builders");
2-
const { Permissions } = require("discord.js");
2+
const { PermissionFlagsBits } = require("discord.js");
33

44
const COMMAND_KICKUNVERIFIED = "kickunverified";
55
const COMMAND_MIGRATE = "migratecourses";
@@ -52,7 +52,7 @@ module.exports = {
5252
),
5353
async execute(interaction) {
5454
try {
55-
if (!interaction.member.permissions.has(Permissions.FLAGS.ADMINISTRATOR)) {
55+
if (!interaction.member.permissions.has(PermissionFlagsBits.ADMINISTRATOR)) {
5656
return await interaction.reply({
5757
content: "You do not have permission to execute this command.",
5858
ephemeral: true,

commands/reactforrole.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { SlashCommandBuilder } = require("@discordjs/builders");
2-
const { Permissions, MessageEmbed } = require("discord.js");
2+
const { PermissionFlagsBits, EmbedBuilder } = require("discord.js");
33

44
module.exports = {
55
data: new SlashCommandBuilder()
@@ -27,7 +27,7 @@ module.exports = {
2727

2828
async execute(interaction) {
2929
// Only admin users should be able to execute this command
30-
if (!interaction.member.permissions.has(Permissions.FLAGS.ADMINISTRATOR)) {
30+
if (!interaction.member.permissions.has(PermissionFlagsBits.ADMINISTRATOR)) {
3131
return await interaction.reply({
3232
content: "You do not have permission to execute this command.",
3333
ephemeral: true,
@@ -144,7 +144,7 @@ module.exports = {
144144

145145
// Notify user that they used the command
146146
const botName = sentMessage.author.username;
147-
const notification = new MessageEmbed()
147+
const notification = new EmbedBuilder()
148148
.setColor("#7cd699")
149149
.setTitle("React For Role Command Used!")
150150
.setAuthor(botName, "https://avatars.githubusercontent.com/u/164179?s=200&v=4")

events/cb_ready.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

events/cb_ready.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Client } from "discord.js";
2+
import { CarrotboardStorage } from "../lib/carrotboard";
3+
4+
export const ready = {
5+
name: "ready",
6+
once: true,
7+
execute(client: Client) {
8+
const cbStorage = new CarrotboardStorage(client);
9+
global.cbStorage = cbStorage;
10+
},
11+
};

events/faq_ready.js renamed to events/faq_ready.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// @ts-check
2-
const { DBFaq } = require("../lib/database/faq");
2+
import { DBFaq } from "../lib/database/faq";
33
/* eslint-disable */
44

5-
module.exports = {
5+
export const ready = {
66
name: "ready",
77
once: true,
88
async execute() {
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
const { DBlog } = require("../lib/database/dblog");
1+
import { DBlog } from "../lib/database/dblog";
22

33
module.exports = {
44
name: "ready",
55
once: true,
6-
execute(client) {
7-
const guilds = client.guilds.cache.map((guild) => guild.id);
6+
execute(client: any) {
7+
const guilds = client.guilds.cache.map((guild: any) => guild.id);
88
const logDB = new DBlog();
99
global.logDB = logDB;
1010

@@ -17,11 +17,11 @@ module.exports = {
1717
const channels_arr = [...channels.values()];
1818
const channels_filtered = channels_arr.filter((c) => c.type === "GUILD_TEXT");
1919

20-
for (const m in channels_filtered) {
21-
// console.log(channels_filtered[m].id, channels_filtered[m].name);
22-
logDB.channel_add(channels_filtered[m].id, channels_filtered[m].name, g.id);
20+
for (const channel of channels_filtered) {
21+
// console.log(channel.id, channel.name);
22+
logDB.channel_add(channel.id, channel.name, g.id);
2323
}
2424
}
2525
})();
2626
},
27-
};
27+
};
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
const { DBReactRole } = require("../lib/database/dbreactrole");
2-
/* eslint-disable */
1+
import { DBReactRole } from "../lib/database/dbreactrole";
32

4-
module.exports = {
3+
export const ready = {
54
name: "ready",
65
once: true,
7-
async execute() {
6+
async execute(): Promise<void> {
87
const reactRoles = new DBReactRole();
98
global.reactRoles = reactRoles;
109
},
11-
};
10+
};

events/schedulepost_ready.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

events/schedulepost_ready.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { DBReactRole } from "../lib/database/dbreactrole";
2+
3+
export const ready = {
4+
name: "ready",
5+
once: true,
6+
async execute(): Promise<void> {
7+
const reactRoles = new DBReactRole();
8+
global.reactRoles = reactRoles;
9+
},
10+
};
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
const { DBstandup } = require("../lib/database/dbstandup");
1+
import { DBstandup } from "../lib/database/dbstandup";
22

3-
module.exports = {
3+
export const ready = {
44
name: "ready",
55
once: true,
6-
execute() {
6+
execute(): void {
77
const standupDBGlobal = new DBstandup();
88
global.standupDBGlobal = standupDBGlobal;
99
},
10-
};
10+
};

lib/carrotboard/index.js renamed to lib/carrotboard/index.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
// @ts-check
21
/* eslint-disable */
32
// const { Embed } = require("@discordjs/builders");
43
const { MessageEmbed } = require("discord.js");
54
const { DBcarrotboard } = require("../database/dbcarrotboard");
6-
const fs = require("fs");
5+
import fs from 'fs';
76
const YAML = require("yaml");
87

9-
class CarrotboardStorage {
8+
export class CarrotboardStorage {
109
pin = "📌";
1110
maxMsgLen = 50;
1211
rowsPerPage = 5;
1312

1413
/** @protected @type {Client} */
1514
_client;
15+
config: CarrotboardConfig;
16+
db: any;
1617

1718
/** @param {Client} client */
18-
constructor(client) {
19+
constructor(client:any) {
1920
this.config = new CarrotboardConfig();
2021
this.db = new DBcarrotboard();
2122
this._client = client;
@@ -26,7 +27,7 @@ class CarrotboardStorage {
2627
* @param {Number} CBID
2728
* @param {String} emoji
2829
*/
29-
async sendCBAlert(messageReaction, CBID, emoji) {
30+
async sendCBAlert(messageReaction:any, CBID:any, emoji:any) {
3031
// get the alert channel and check it
3132
let alertChannel;
3233
try {
@@ -122,7 +123,7 @@ class CarrotboardStorage {
122123
} else {
123124
entries = await this.db.get_all(this.config.minimum);
124125
}
125-
entries.sort((a, b) => Number(b["count"]) - Number(a["count"]));
126+
entries.sort((a:any, b:any) => Number(b["count"]) - Number(a["count"]));
126127

127128
// generate the leaderboard
128129
const embedPages = [];
@@ -403,7 +404,7 @@ class CarrotboardConfig {
403404
* Returns the first emoji seen in the message, or null sometimes
404405
* @param {String} messageStr
405406
*/
406-
function extractOneEmoji(messageStr) {
407+
function extractOneEmoji(messageStr:String) {
407408
if (messageStr.length == 0) {
408409
return null;
409410
}

0 commit comments

Comments
 (0)