Skip to content

Commit

Permalink
fix: add enabled flag
Browse files Browse the repository at this point in the history
  • Loading branch information
mezotv committed Jul 20, 2024
1 parent 723cc47 commit dc014be
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 55 deletions.
94 changes: 47 additions & 47 deletions src/events/guildMemberAdd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,59 +16,59 @@ const event: Event = {

const guildDb = await client.database.getGuild(member.guild.id, false);
if (!guildDb || !guildDb?.welcome) return;
const channel = (await member.guild.channels
.fetch(guildDb.welcomeChannel)
.catch((err: Error) => {
captureException(err);
})) as GuildTextBasedChannel;
const channel = (await member.guild.channels
.fetch(guildDb.welcomeChannel)
.catch((err: Error) => {
captureException(err);
})) as GuildTextBasedChannel;

if (!channel?.id) return;
if (!channel?.id) return;

if (
member.guild.members.me &&
!channel
?.permissionsFor(member.guild.members.me)
?.has([
PermissionFlagsBits.ViewChannel,
PermissionFlagsBits.SendMessages,
PermissionFlagsBits.EmbedLinks,
])
)
return;
if (
member.guild.members.me &&
!channel
?.permissionsFor(member.guild.members.me)
?.has([
PermissionFlagsBits.ViewChannel,
PermissionFlagsBits.SendMessages,
PermissionFlagsBits.EmbedLinks,
])
) return;

const premium = await client.premium.check(member?.guild.id);

const premium = await client.premium.check(member?.guild.id);
const General = await getQuestionsByType(
"wouldyourather",
guildDb,
guildDb?.language != null ? guildDb.language : "en_EN",
premium.result,
false,
);
const WhatYouDo = await getQuestionsByType(
"whatwouldyoudo",
guildDb,
guildDb?.language != null ? guildDb.language : "en_EN",
premium.result,
false,
);

const General = await getQuestionsByType(
"wouldyourather",
guildDb,
guildDb?.language != null ? guildDb.language : "en_EN",
premium.result,
);
const WhatYouDo = await getQuestionsByType(
"whatwouldyoudo",
guildDb,
guildDb?.language != null ? guildDb.language : "en_EN",
premium.result,
);
const randomMessage = Math.random() > 0.5 ? General : WhatYouDo;

const randomMessage = Math.random() > 0.5 ? General : WhatYouDo;

channel
.send({
content: `${client.translation.get(
guildDb?.language,
"Welcome.embed.title",
)} ${
guildDb.welcomePing
? `<@${member.user.id}>`
: `${member.user.username}`
}! ${randomMessage.question}`,
})
.catch((err: Error) => {
captureException(err);
});
return;
channel
.send({
content: `${client.translation.get(
guildDb?.language,
"Welcome.embed.title",
)} ${
guildDb.welcomePing
? `<@${member.user.id}>`
: `${member.user.username}`
}! ${randomMessage.question}`,
})
.catch((err: Error) => {
captureException(err);
});
return;
},
};

Expand Down
18 changes: 10 additions & 8 deletions src/util/Functions/jsonImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,13 @@ export async function getRandomTod(
guildDb: IGuildModel,
language: string,
premium: Boolean,
enabled: Boolean = true,
): Promise<QuestionResult> {
let result;

try {
const truth = await getQuestionsByType("truth", guildDb, language, premium);
const dare = await getQuestionsByType("dare", guildDb, language, premium);
const truth = await getQuestionsByType("truth", guildDb, language, premium, enabled);
const dare = await getQuestionsByType("dare", guildDb, language, premium, enabled);

result = Math.random() < 0.5 ? truth : dare;
} catch (error) {
Expand All @@ -115,6 +116,7 @@ export async function getQuestionsByType(
guildDb: IGuildModel,
language: string,
premium: Boolean,
enabled: Boolean = true,
): Promise<QuestionResult> {
if (!validTypes.includes(type)) {
return Promise.reject("Invalid type");
Expand All @@ -139,7 +141,7 @@ export async function getQuestionsByType(
guildID: guildDb.guildID,
});

if (!usedQuestions[0] && premium) {
if (!usedQuestions[0] && premium && enabled) {
await usedQuestionModel.create({
guildID: guildDb.guildID,
customTruthQuestions: [],
Expand Down Expand Up @@ -167,9 +169,9 @@ export async function getQuestionsByType(
}

let questionDatabase = await getDBQuestion(
premium ? usedQuestions[0][typeCheck[type]] : [],
premium && enabled ? usedQuestions[0][typeCheck[type]] : [],
);
if (!questionDatabase[0]?.id && premium) {
if (!questionDatabase[0]?.id && premium && enabled) {
await reset(type as Quest, guildDb.customTypes, guildDb.guildID, "db");
questionDatabase = await getDBQuestion([]);
}
Expand Down Expand Up @@ -198,10 +200,10 @@ export async function getQuestionsByType(
}

let newRandomCustomQuestion = await getRandomCustom(
premium ? usedQuestions[0][typeCheck["custom" + type]] : [],
premium && enabled ? usedQuestions[0][typeCheck["custom" + type]] : [],
);

if (!newRandomCustomQuestion[0]?.id && premium) {
if (!newRandomCustomQuestion[0]?.id && premium && enabled) {
await reset(
type as Quest,
guildDb.customTypes,
Expand Down Expand Up @@ -244,7 +246,7 @@ export async function getQuestionsByType(
break;
}

if (premium) {
if (premium && enabled) {
if (guildDb.customTypes === "custom") {
selectedModel = typeCheck["custom" + type];
} else if (guildDb.customTypes === "mixed") {
Expand Down

0 comments on commit dc014be

Please sign in to comment.