Skip to content

Commit

Permalink
Remake the question queue system (#577)
Browse files Browse the repository at this point in the history
* start queue remake

* fix: minor fixes and additions

* fix; make sure questions are cleared and added

* fix: saving point for files

* this sucks

* add: non-repetitive questions

* fix: ts ignore welcomer

* fix: add enabled flag

* fix: remove nodemon

* fix: no custom questions issue

---------

Co-authored-by: ForGetFulSkyBro <forgetfulskybro9@gmail.com>
  • Loading branch information
mezotv and forgetfulskybro authored Jul 20, 2024
1 parent f8c11f8 commit 601c263
Show file tree
Hide file tree
Showing 20 changed files with 341 additions and 297 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,18 @@ Follow the Angular commit message format. See [here](https://github.com/angular/

You can run the below scripts with `pnpm <script>`.

| Script | Description |
| -------------- | -------------------------------------------------------------------- |
| `start` | Runs the code in production mode |
| `dev` | Runs the code using nodemon in dev mode |
| `format` | Formats the code. |

| Script | Description |
| -------- | -------------------------------- |
| `start` | Runs the code in production mode |
| `dev` | Runs the code in dev mode |
| `format` | Formats the code. |

### Discord logs

Logs are also sent to Discord to allow for easier and more accessible debugging, as not everyone will have access to the host system, especially in production. The channels for the different log levels are defined in the `.env` file.

# Docker deployment

For a guide regarding the deployment on our production server go to [this link](https://github.com/Would-You-Bot/config)

# Project Details
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
"@types/express": "^4.17.21",
"@types/uuid": "^10.0.0",
"copyfiles": "^2.4.1",
"nodemon": "3.0.1",
"prettier": "^3.2.5",
"typescript": "^5.4.5"
}
Expand Down
10 changes: 6 additions & 4 deletions src/buttons/gamesActivities/dare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ const button: Button = {
}
}
}

const premium = await client.premium.check(interaction?.guildId);

const userDb = await UserModel.findOne({
userID: interaction.user?.id,
});
Expand All @@ -58,6 +61,7 @@ const button: Button = {
: userDb?.language
? userDb.language
: "en_EN",
premium.result,
);

const dareEmbed = new DefaultGameEmbed(
Expand All @@ -71,8 +75,6 @@ const button: Button = {
const row2 = new ActionRowBuilder<MessageActionRowComponentBuilder>();
let components: ActionRowBuilder<MessageActionRowComponentBuilder>[];

const premium = await client.premium.check(interaction?.guildId);

const randomValue = Math.round(Math.random() * 15);

if (!premium.result && randomValue < 3) {
Expand All @@ -86,7 +88,7 @@ const button: Button = {
),
]);
components = [row, row2];
} else if (!premium.result && randomValue >= 3 && randomValue < 7) {
} else if (!premium.result && randomValue >= 3 && randomValue < 5) {
row2.addComponents([
new ButtonBuilder()
.setLabel("Premium")
Expand All @@ -108,7 +110,7 @@ const button: Button = {
? { content: DARE.question }
: {
content:
!premium.result && randomValue >= 3 && randomValue < 6
!premium.result && randomValue >= 3 && randomValue < 5
? client.translation.get(guildDb?.language, "Premium.message")
: undefined,
embeds: [dareEmbed],
Expand Down
4 changes: 2 additions & 2 deletions src/buttons/gamesActivities/higher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ const button: Button = {
"https://discord.com/oauth2/authorize?client_id=981649513427111957&permissions=275415247936&scope=bot%20applications.commands",
),
]);
} else if (!premium.result && randomValue >= 3 && randomValue < 6) {
} else if (!premium.result && randomValue >= 3 && randomValue < 5) {
mainRow.addComponents([
new ButtonBuilder()
.setLabel("Premium")
Expand All @@ -203,7 +203,7 @@ const button: Button = {
gameImage.build(game?.score || 0, client).then((image) => {
interaction.editReply({
content:
!premium.result && randomValue >= 3 && randomValue < 6
!premium.result && randomValue >= 3 && randomValue < 5
? client.translation.get(guildDb?.language, "Premium.message")
: undefined,
embeds: [loseEmbed],
Expand Down
4 changes: 2 additions & 2 deletions src/buttons/gamesActivities/lower.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ const button: Button = {
"https://discord.com/oauth2/authorize?client_id=981649513427111957&permissions=275415247936&scope=bot%20applications.commands",
),
]);
} else if (!premium.result && randomValue >= 3 && randomValue < 6) {
} else if (!premium.result && randomValue >= 3 && randomValue < 5) {
mainRow.addComponents([
new ButtonBuilder()
.setLabel("Premium")
Expand All @@ -203,7 +203,7 @@ const button: Button = {
gameImage.build(game?.score || 0, client).then((image) => {
interaction.editReply({
content:
!premium.result && randomValue >= 3 && randomValue < 6
!premium.result && randomValue >= 3 && randomValue < 5
? client.translation.get(guildDb?.language, "Premium.message")
: undefined,
embeds: [loseEmbed],
Expand Down
10 changes: 6 additions & 4 deletions src/buttons/gamesActivities/neverhaveiever.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ const button: Button = {
}
}
}

const premium = await client.premium.check(interaction?.guildId);

const userDb = await UserModel.findOne({
userID: interaction.user?.id,
});
Expand All @@ -58,6 +61,7 @@ const button: Button = {
: userDb?.language
? userDb.language
: "en_EN",
premium.result,
);

const nhieEmbed = new DefaultGameEmbed(
Expand All @@ -71,8 +75,6 @@ const button: Button = {

const randomValue = Math.round(Math.random() * 15);

const premium = await client.premium.check(interaction?.guildId);

if (!premium.result && randomValue < 3) {
mainRow.addComponents([
new ButtonBuilder()
Expand All @@ -83,7 +85,7 @@ const button: Button = {
"https://discord.com/oauth2/authorize?client_id=981649513427111957&permissions=275415247936&scope=bot%20applications.commands",
),
]);
} else if (!premium.result && randomValue >= 3 && randomValue < 6) {
} else if (!premium.result && randomValue >= 3 && randomValue < 5) {
mainRow.addComponents([
new ButtonBuilder()
.setLabel("Premium")
Expand Down Expand Up @@ -117,7 +119,7 @@ const button: Button = {
? { content: NHIE.question, fetchReply: true }
: {
content:
!premium.result && randomValue >= 3 && randomValue < 6
!premium.result && randomValue >= 3 && randomValue < 5
? client.translation.get(guildDb?.language, "Premium.message")
: undefined,
embeds: [nhieEmbed],
Expand Down
9 changes: 5 additions & 4 deletions src/buttons/gamesActivities/random.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ const button: Button = {
}
}

const premium = await client.premium.check(interaction?.guildId);

const userDb = await UserModel.findOne({
userID: interaction.user?.id,
});
Expand All @@ -59,6 +61,7 @@ const button: Button = {
: userDb?.language
? userDb.language
: "en_EN",
premium.result,
);

const randomEmbed = new DefaultGameEmbed(
Expand All @@ -72,8 +75,6 @@ const button: Button = {
const row2 = new ActionRowBuilder<MessageActionRowComponentBuilder>();
let components = [];

const premium = await client.premium.check(interaction?.guildId);

const randomValue = Math.round(Math.random() * 15);

if (!premium.result && randomValue < 3) {
Expand All @@ -87,7 +88,7 @@ const button: Button = {
),
]);
components = [row, row2];
} else if (!premium.result && randomValue >= 3 && randomValue < 7) {
} else if (!premium.result && randomValue >= 3 && randomValue < 5) {
row2.addComponents([
new ButtonBuilder()
.setLabel("Premium")
Expand All @@ -109,7 +110,7 @@ const button: Button = {
? { content: RANDOM.question }
: {
content:
!premium.result && randomValue >= 3 && randomValue < 6
!premium.result && randomValue >= 3 && randomValue < 5
? client.translation.get(guildDb?.language, "Premium.message")
: undefined,
embeds: [randomEmbed],
Expand Down
9 changes: 5 additions & 4 deletions src/buttons/gamesActivities/truth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ const button: Button = {
}
}

const premium = await client.premium.check(interaction?.guildId);

const userDb = await UserModel.findOne({
userID: interaction.user?.id,
});
Expand All @@ -61,6 +63,7 @@ const button: Button = {
: userDb?.language
? userDb.language
: "en_EN",
premium.result,
);

const truthEmbed = new DefaultGameEmbed(
Expand All @@ -74,8 +77,6 @@ const button: Button = {
const row2 = new ActionRowBuilder<MessageActionRowComponentBuilder>();
let components: ActionRowBuilder<MessageActionRowComponentBuilder>[];

const premium = await client.premium.check(interaction?.guildId);

const randomValue = Math.round(Math.random() * 15);

if (!premium.result && randomValue < 3) {
Expand All @@ -89,7 +90,7 @@ const button: Button = {
),
]);
components = [row, row2];
} else if (!premium.result && randomValue >= 3 && randomValue < 7) {
} else if (!premium.result && randomValue >= 3 && randomValue < 5) {
row2.addComponents([
new ButtonBuilder()
.setLabel("Premium")
Expand All @@ -111,7 +112,7 @@ const button: Button = {
? { content: TRUTH.question }
: {
content:
!premium.result && randomValue >= 3 && randomValue < 6
!premium.result && randomValue >= 3 && randomValue < 5
? client.translation.get(guildDb?.language, "Premium.message")
: undefined,
embeds: [truthEmbed],
Expand Down
9 changes: 5 additions & 4 deletions src/buttons/gamesActivities/wouldyourather.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ const button: Button = {
}
}

const premium = await client.premium.check(interaction?.guildId);

const userDb = await UserModel.findOne({
userID: interaction.user?.id,
});
Expand All @@ -61,6 +63,7 @@ const button: Button = {
: userDb?.language
? userDb.language
: "en_EN",
premium.result,
);

const ratherEmbed = new DefaultGameEmbed(
Expand All @@ -83,8 +86,6 @@ const button: Button = {

const randomValue = Math.round(Math.random() * 15);

const premium = await client.premium.check(interaction?.guildId);

if (!premium.result && randomValue < 3) {
mainRow.addComponents([
new ButtonBuilder()
Expand All @@ -95,7 +96,7 @@ const button: Button = {
"https://discord.com/oauth2/authorize?client_id=981649513427111957&permissions=275415247936&scope=bot%20applications.commands",
),
]);
} else if (!premium.result && randomValue >= 3 && randomValue < 6) {
} else if (!premium.result && randomValue >= 3 && randomValue < 5) {
mainRow.addComponents([
new ButtonBuilder()
.setLabel("Premium")
Expand Down Expand Up @@ -129,7 +130,7 @@ const button: Button = {
? { content: WYR.question, fetchReply: true }
: {
content:
!premium.result && randomValue >= 3 && randomValue < 6
!premium.result && randomValue >= 3 && randomValue < 5
? client.translation.get(guildDb?.language, "Premium.message")
: undefined,
embeds: [ratherEmbed],
Expand Down
9 changes: 5 additions & 4 deletions src/buttons/gamesActivities/wwyd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ const button: Button = {
}
}

const premium = await client.premium.check(interaction?.guildId);

const userDb = await UserModel.findOne({
userID: interaction.user?.id,
});
Expand All @@ -61,6 +63,7 @@ const button: Button = {
: userDb?.language
? userDb.language
: "en_EN",
premium.result,
);

const wwydEmbed = new DefaultGameEmbed(
Expand All @@ -74,8 +77,6 @@ const button: Button = {

const randomValue = Math.round(Math.random() * 15);

const premium = await client.premium.check(interaction?.guildId);

if (!premium.result && randomValue < 3) {
row.addComponents([
new ButtonBuilder()
Expand All @@ -86,7 +87,7 @@ const button: Button = {
"https://discord.com/oauth2/authorize?client_id=981649513427111957&permissions=275415247936&scope=bot%20applications.commands",
),
]);
} else if (!premium.result && randomValue >= 3 && randomValue < 6) {
} else if (!premium.result && randomValue >= 3 && randomValue < 5) {
row.addComponents([
new ButtonBuilder()
.setLabel("Premium")
Expand All @@ -108,7 +109,7 @@ const button: Button = {
? { content: WWYD.question, fetchReply: true }
: {
content:
!premium.result && randomValue >= 3 && randomValue < 6
!premium.result && randomValue >= 3 && randomValue < 5
? client.translation.get(guildDb?.language, "Premium.message")
: undefined,
embeds: [wwydEmbed],
Expand Down
6 changes: 3 additions & 3 deletions src/commands/game/dare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const command: ChatInputCommand = {
* @param {guildModel} guildDb
*/
execute: async (interaction, client, guildDb) => {
const premium = await client.premium.check(interaction?.guildId);
const userDb = await UserModel.findOne({
userID: interaction.user?.id,
});
Expand All @@ -44,6 +45,7 @@ const command: ChatInputCommand = {
: userDb?.language
? userDb.language
: "en_EN",
premium.result,
);

const dareEmbed = new DefaultGameEmbed(
Expand All @@ -57,8 +59,6 @@ const command: ChatInputCommand = {
const row2 = new ActionRowBuilder<MessageActionRowComponentBuilder>();
let components = [];

const premium = await client.premium.check(interaction?.guildId);

const randomValue = Math.round(Math.random() * 15);

if (!premium.result && randomValue < 3) {
Expand All @@ -72,7 +72,7 @@ const command: ChatInputCommand = {
),
]);
components = [row, row2];
} else if (!premium.result && randomValue >= 3 && randomValue < 7) {
} else if (!premium.result && randomValue >= 3 && randomValue < 5) {
row2.addComponents([
new ButtonBuilder()
.setLabel("Premium")
Expand Down
Loading

0 comments on commit 601c263

Please sign in to comment.