Skip to content

Commit

Permalink
improve: schemas for levels
Browse files Browse the repository at this point in the history
  • Loading branch information
maamokun committed Jun 24, 2024
1 parent 87d23d6 commit fe9a04a
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 34 deletions.
Binary file modified bun.lockb
Binary file not shown.
40 changes: 21 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
{
"name": "mikanbot-project",
"module": "index.ts",
"type": "module",
"scripts": {
"format": "biome format --write ."
},
"devDependencies": {
"@types/bun": "latest",
"prisma": "5.15.1"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"dependencies": {
"@biomejs/biome": "^1.8.2",
"@prisma/client": "^5.15.1",
"discord.js": "^14.15.3",
"elysia": "^1.0.25"
}
"name": "mikanbot-project",
"module": "index.ts",
"type": "module",
"scripts": {
"format": "biome format --write ."
},
"devDependencies": {
"@types/bun": "latest",
"prisma": "5.15.1"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"dependencies": {
"@biomejs/biome": "^1.8.2",
"@prisma/client": "^5.15.1",
"canvafy": "^7.1.0",
"discord.js": "^14.15.3",
"elysia": "^1.0.25",
"quick.db": "^9.1.7"
}
}
17 changes: 17 additions & 0 deletions prisma/migrations/20240624082848_new/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
Warnings:
- Added the required column `levelCard` to the `User` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "User" ADD COLUMN "levelCard" TEXT NOT NULL;

-- CreateTable
CREATE TABLE "guildLvl" (
"id" TEXT NOT NULL,
"level" INTEGER NOT NULL,
"xp" INTEGER NOT NULL,

CONSTRAINT "guildLvl_pkey" PRIMARY KEY ("id")
);
8 changes: 8 additions & 0 deletions prisma/migrations/20240624083257_new2/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:
- Added the required column `rankColor` to the `User` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "User" ADD COLUMN "rankColor" TEXT NOT NULL;
8 changes: 8 additions & 0 deletions prisma/migrations/20240624084700_new3/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:
- Added the required column `mdUID` to the `User` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "User" ADD COLUMN "mdUID" TEXT NOT NULL;
9 changes: 9 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ model User {
id String @id
premium Boolean @default(false)
premiumUntil DateTime?
levelCard String
rankColor String
mdUID String
}

model guildLvl {
id String @id
level Int
xp Int
}

model server {
Expand Down
23 changes: 23 additions & 0 deletions src/commands/premping.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { CommandInteraction } from "discord.js";

export default {
name: "premping",
description: "Ping but its premium!",
cooldown: 0,
isPremium: true,
botPermissions: [],
userPermissions: [],
validations: [],
slashCommand: {
enabled: true,
options: [],
},
interactionRun: async (interaction: CommandInteraction) => {
const ping = Math.abs(Math.round(interaction.client.ws.ping));
await interaction.reply("Loading...");
const roundtrip = Math.abs(Date.now() - interaction.createdTimestamp);
interaction.editReply(
`API Latency: ${ping}ms\nRoundtrip: ${roundtrip}ms`,
);
},
};
38 changes: 24 additions & 14 deletions src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,48 @@ export function deployCommands() {
try {
console.log("Started refreshing application (/) commands.");

const commands = [];
const commandFiles = fs
.readdirSync("./src/commands")
.filter((file) => file.endsWith(".ts"));

for (const file of commandFiles) {
const command = await import(
path.resolve(`./src/commands/${file}`)
);
commands.push(command.default);
}
const commands = await Promise.all(
commandFiles.map(async (file) => {
const command = await import(
path.resolve(`./src/commands/${file}`)
);
return command.default;
}),
);

const commandDataArray = [];

for (const command of commands) {
if (command.slashCommand.enabled) {
console.log(`Registering ${command.name} command`);
console.log(
`Preparing ${command.name} command for registration`,
);

const commandData = {
name: command.name,
description: command.description,
options: command.slashCommand.options,
};

await rest.put(
Routes.applicationCommands(process.env.BOT_ID || ""),
{ body: [commandData] },
);
commandDataArray.push(commandData);
}
}

console.log("Successfully reloaded application (/) commands.");
console.log(`Registering all commands`);

await rest.put(
Routes.applicationCommands(process.env.BOT_ID || ""),
{ body: commandDataArray },
);
} catch (error) {
console.error(error);
console.error(
"An error occurred while refreshing application commands:",
error,
);
}
})();
}
25 changes: 24 additions & 1 deletion src/handlers/command.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,36 @@
import type { CommandInteraction } from "discord.js";
import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

export async function handleCommand(interaction: CommandInteraction) {
try {
const userDb = await prisma.user.findUnique({
where: {
id: interaction.user.id,
},
});

if (!userDb) {
await prisma.user.create({
data: {
id: interaction.user.id,
premium: false,
},
});
}

const premium = userDb?.premium;
const commandModule = await import(
`./commands/${interaction.commandName}.ts`
`../commands/${interaction.commandName}.ts`
);
const command = commandModule.default;
if (!command.slashCommand.enabled)
return interaction.reply("This command is not enabled!");
if (command.isPremium && !premium)
return interaction.reply(
"This command is only available for premium users!",
);
if (command.slashCommand.enabled) command.interactionRun(interaction);
} catch (error) {
console.error(error);
Expand Down
3 changes: 3 additions & 0 deletions src/handlers/lvl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();
9 changes: 9 additions & 0 deletions src/handlers/ratelimit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { QuickDB, MemoryDriver } = require("quick.db");
const memoryDriver = new MemoryDriver();
const db = new QuickDB({ driver: memoryDriver });

export default function setRatelimit (type, time, user) {
if(type == "msg") {

}
}
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ client.on("interactionCreate", async (interaction) => {
await handleCommand(interaction);
});

client.on("messageCreate", async (message) => {
if (message.author.bot) return;


client.login(process.env.BOT_TOKEN);

0 comments on commit fe9a04a

Please sign in to comment.