Skip to content

Commit 2999da0

Browse files
committed
[Update] Big updateeeeee
1 parent 063b98c commit 2999da0

File tree

11 files changed

+533
-71
lines changed

11 files changed

+533
-71
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Bot-Discord-CTF-VKU
2-
Automated discord bot for CTF competition at VKU university
32

3+
Automated discord bot for CTF competition at VKU university
44

55
You can add it and test on your own server at: [Add bot](https://discord.com/api/oauth2/authorize?client_id=1158269680289591369&permissions=8&scope=bot)

command/ctf.command.ts

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { CacheType, Client, GuildMember, Interaction } from "discord.js"
2-
import { checkFlag, deleteChallenge, getAllChallenge, saveFlag, updateURLChall } from "../controller/flag.controller";
3-
import { getInfoHacker, updateLevelAllUser } from "../controller/player.controller";
2+
import { checkFlag, deleteChallenge, getAllChallenge, saveFlag, scoreBoard, updateURLChall } from "../controller/flag.controller";
3+
import { createTeam, getInfoHacker, leaveTeam, updateLevelAllUser } from "../controller/player.controller";
4+
import { addChallengeContest, createContest, joinContest, listContests, scoreBoardContest } from "../controller/contest.controller";
5+
import { joinTeam } from "../controller/player.controller";
6+
import { createEmbed } from "../feature/component";
47

58
const adminPassword = process.env.ADMIN_PASSWORD;
69

@@ -21,7 +24,7 @@ const CTFCommand = {
2124
break;
2225
case "challenge":
2326
const password = options.getString("password");
24-
if (password == adminPassword) {
27+
if (password === adminPassword) {
2528
await saveFlag(options.getString("id"),
2629
options.getString("author"),
2730
options.getString("chall"),
@@ -34,6 +37,9 @@ const CTFCommand = {
3437
options.getString("category"),
3538
interaction
3639
);
40+
if (options.getString("idContest")) {
41+
await addChallengeContest(options.getString("idcontest"), options.getString("id"), interaction);
42+
}
3743
} else {
3844
await interaction.reply("[!] Bạn không phải là admin để thực hiện tính năng này!!");
3945
}
@@ -56,6 +62,61 @@ const CTFCommand = {
5662
case "update":
5763
await updateLevelAllUser(options.getString("password") == adminPassword, interaction);
5864
break;
65+
case "scoreboard":
66+
await scoreBoard(interaction);
67+
break;
68+
case "createcontest":
69+
const idContest = Math.random().toString(36).substring(2, 10);
70+
await createContest(idContest, options.getString("name"), options.getString("description"), options.getBoolean("status"), options.getString("start"), options.getString("endt"), interaction);
71+
break;
72+
case "leavecontest":
73+
await leaveTeam(user, interaction);
74+
break;
75+
case "listcontest":
76+
await listContests(interaction);
77+
break;
78+
case "joincontest":
79+
await joinContest(options.getString("id"), user, interaction);
80+
break;
81+
case "scoreboardcontest":
82+
await scoreBoardContest(options.getString("id"), interaction);
83+
break;
84+
case "jointeam":
85+
await joinTeam(user, options.getString("idteam"), interaction);
86+
break;
87+
case "createteam":
88+
const nameTeam = options.getString("name");
89+
if (nameTeam) {
90+
await createTeam(user, nameTeam, options.getString("description") ?? "", interaction);
91+
} else {
92+
await interaction.reply("Bạn chưa nhập tên team!");
93+
}
94+
break;
95+
case "leaveteam":
96+
await leaveTeam(user, interaction);
97+
break;
98+
case "help":
99+
const embed = createEmbed("Help", "```" +
100+
"***Feature:***\n" +
101+
"1. /ping: Kiểm tra bot có hoạt động hay không\n" +
102+
"2. /flag: Kiểm tra flag\n" +
103+
"3. /infohacker: Xem thông tin hacker\n" +
104+
"4. /listchall: Xem danh sách thử thách\n" +
105+
"5. /rmchall: Xóa thử thách\n" +
106+
"6. /updatechall: Cập nhật thử thách\n" +
107+
"7. /update: Cập nhật level cho tất cả người chơi\n" +
108+
"8. /scoreboard: Xem bảng xếp hạng\n" +
109+
"9. /createcontest: Tạo contest\n" +
110+
"10. /leavecontest: Rời contest\n" +
111+
"11. /listcontest: Xem danh sách contest\n" +
112+
"12. /joincontest: Tham gia contest\n" +
113+
"13. /scoreboardcontest: Xem bảng xếp hạng contest\n" +
114+
"14. /jointeam: Tham gia team\n" +
115+
"15. /createteam: Tạo team\n" +
116+
"16. /leaveteam: Rời team\n" +
117+
"```");
118+
await interaction.reply({ embeds: [embed] });
119+
break;
59120
}
60121
})
61122
}

command/slash.deploy.ts

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ const serverCommands: Array<RESTPostAPIChatInputApplicationCommandsJSONBody> = [
1414
new SlashCommandBuilder().setName("flag").setDescription("Check flag!")
1515
.addStringOption(option => option.setName('flag').setDescription("Check your flag").setRequired(true)),
1616
new SlashCommandBuilder().setName("listchall").setDescription("View all challenge (Normal or admin)")
17-
.addStringOption(option => option.setName("category").setDescription("Type category"))
17+
.addStringOption(option => option.setName("category").addChoices(
18+
{ name: 'Binary Exploitation', value: 'Binary Exploitation' } as APIApplicationCommandOptionChoice<string>,
19+
{ name: 'Cryptography', value: 'Cryptography' } as APIApplicationCommandOptionChoice<string>,
20+
{ name: 'Forensics', value: 'Forensics' } as APIApplicationCommandOptionChoice<string>,
21+
{ name: 'Miscellaneous', value: 'Miscellaneous' } as APIApplicationCommandOptionChoice<string>,
22+
{ name: 'Reverse Engineering', value: 'Reverse Engineering' } as APIApplicationCommandOptionChoice<string>,
23+
{ name: 'Web Exploitation', value: 'Web Exploitation' } as APIApplicationCommandOptionChoice<string>,
24+
).setDescription("Type category"))
1825
.addStringOption(option => option.setName("password").setDescription("Type password to verify")),
1926
new SlashCommandBuilder().setName("challenge").setDescription("Add new flag!")
2027
.addStringOption(option => option.setName('id').setDescription("Add new flag!").setRequired(true))
@@ -25,8 +32,16 @@ const serverCommands: Array<RESTPostAPIChatInputApplicationCommandsJSONBody> = [
2532
.addStringOption(option => option.setName('flag').setDescription("Add new flag!").setRequired(true))
2633
.addBooleanOption(option => option.setName('public').setDescription("Add new flag!").setRequired(true))
2734
.addNumberOption(option => option.setName('point').setDescription("Add new flag!").setRequired(true))
28-
.addStringOption(option => option.setName('category').setDescription("Add category").setRequired(true))
35+
.addStringOption(option => option.setName('category').setDescription("Add category").addChoices(
36+
{ name: 'Binary Exploitation', value: 'Binary Exploitation' } as APIApplicationCommandOptionChoice<string>,
37+
{ name: 'Cryptography', value: 'Cryptography' } as APIApplicationCommandOptionChoice<string>,
38+
{ name: 'Forensics', value: 'Forensics' } as APIApplicationCommandOptionChoice<string>,
39+
{ name: 'Miscellaneous', value: 'Miscellaneous' } as APIApplicationCommandOptionChoice<string>,
40+
{ name: 'Reverse Engineering', value: 'Reverse Engineering' } as APIApplicationCommandOptionChoice<string>,
41+
{ name: 'Web Exploitation', value: 'Web Exploitation' } as APIApplicationCommandOptionChoice<string>,
42+
).setRequired(true))
2943
.addStringOption(option => option.setName('url').setDescription("Add category").setRequired(true))
44+
.addStringOption(option => option.setName('idcontest').setDescription("Contest Challenge (No if not)").setRequired(true))
3045
.addStringOption(option => option.setName('password').setDescription("Admin password").setRequired(true)),
3146
new SlashCommandBuilder().setName("rmchall").setDescription("Admin delete challenge")
3247
.addStringOption(option => option.setName("id").setDescription("Id challenge").setRequired(true))
@@ -35,7 +50,37 @@ const serverCommands: Array<RESTPostAPIChatInputApplicationCommandsJSONBody> = [
3550
.addStringOption(option => option.setName("id").setDescription("ID challenge").setRequired(true))
3651
.addStringOption(option => option.setName("url").setDescription("Url challenge").setRequired(true))
3752
.addBooleanOption(option => option.setName("status").setDescription("Status challenge").setRequired(true))
53+
.addStringOption(option => option.setName("password").setDescription("Admin password").setRequired(true)),
54+
new SlashCommandBuilder().setName("createcontest").setDescription("Admin create contest")
3855
.addStringOption(option => option.setName("password").setDescription("Admin password").setRequired(true))
56+
.addStringOption(option => option.setName("name").setDescription("Contest name").setRequired(true))
57+
.addStringOption(option => option.setName("description").setDescription("Contest description").setRequired(true))
58+
.addStringOption(option => option.setName("start").setDescription("Contest start time").setRequired(true))
59+
.addStringOption(option => option.setName("endt").setDescription("Contest end time").setRequired(true))
60+
.addBooleanOption(option => option.setName("status").setDescription("Contest status").setRequired(true)),
61+
new SlashCommandBuilder().setName("listcontest").setDescription("View all contest (Normal or admin)")
62+
.addStringOption(option => option.setName("password").setDescription("Type password to verify")),
63+
new SlashCommandBuilder().setName("rmcontest").setDescription("Admin delete contest")
64+
.addStringOption(option => option.setName("id").setDescription("Id contest").setRequired(true))
65+
.addStringOption(option => option.setName("password").setDescription("Admin password").setRequired(true)),
66+
new SlashCommandBuilder().setName("updatecontest").setDescription("Admin update contest")
67+
.addStringOption(option => option.setName("id").setDescription("ID contest").setRequired(true))
68+
.addStringOption(option => option.setName("name").setDescription("Contest name").setRequired(true))
69+
.addStringOption(option => option.setName("description").setDescription("Contest description").setRequired(true))
70+
.addStringOption(option => option.setName("start").setDescription("Contest start time").setRequired(true))
71+
.addStringOption(option => option.setName("endt").setDescription("Contest end time").setRequired(true))
72+
.addBooleanOption(option => option.setName("status").setDescription("Contest status").setRequired(true))
73+
.addStringOption(option => option.setName("password").setDescription("Admin password").setRequired(true)),
74+
new SlashCommandBuilder().setName("infocontest").setDescription("View contest information!")
75+
.addStringOption(option => option.setName("id").setDescription("Contest ID").setRequired(true)),
76+
new SlashCommandBuilder().setName("joincontest").setDescription("Join contest!")
77+
.addStringOption(option => option.setName("id").setDescription("Contest ID").setRequired(true)),
78+
new SlashCommandBuilder().setName("leavecontest").setDescription("Leave contest!")
79+
.addStringOption(option => option.setName("id").setDescription("Contest ID").setRequired(true)),
80+
new SlashCommandBuilder().setName("help").setDescription("View help!"),
81+
new SlashCommandBuilder().setName("scoreboardcontest").setDescription("View scoreboard contest!")
82+
.addStringOption(option => option.setName("id").setDescription("Contest ID").setRequired(true)),
83+
3984

4085
].map(command => command.toJSON());
4186

@@ -44,6 +89,14 @@ const UserCommands: Array<RESTPostAPIChatInputApplicationCommandsJSONBody> = [
4489
.addUserOption(option => option.setName("hacker").setDescription("Select hacker to view")),
4590
new SlashCommandBuilder().setName("update").setDescription("Admin update system!")
4691
.addStringOption(option => option.setName("password").setDescription("Admin password").setRequired(true)),
92+
new SlashCommandBuilder().setName("scoreboard").setDescription("View scoreboard!"),
93+
new SlashCommandBuilder().setName("jointeam").setDescription("Join team!")
94+
.addStringOption(option => option.setName("idteam").setDescription("Team ID").setRequired(true)),
95+
new SlashCommandBuilder().setName("createteam").setDescription("Create team!")
96+
.addStringOption(option => option.setName("name").setDescription("Team name").setRequired(true))
97+
.addStringOption(option => option.setName("description").setDescription("Team description").setRequired(true)),
98+
new SlashCommandBuilder().setName("leaveteam").setDescription("Leave team!")
99+
47100
].map(command => command.toJSON());
48101

49102
export const registerSlashCommand = (guildId: string) => {

connect.db.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const connectDB = async () => {
77
await mongoose.connect(process.env.MONGODB_URL ?? "");
88
console.log("[+] Connect database successfully");
99
} catch (err) {
10+
console.log(err);
1011
console.log(colors.red("[!] Cannot connect to database"));
1112
}
1213
}

0 commit comments

Comments
 (0)