Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing the issue that users can react to old questions #62

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions commands/test/test-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const questions = [
{ question: 'Unternehmen sollen selbst entscheiden, ob sie ihren Beschäftigten das Arbeiten im Homeoffice erlauben.', tag: ['Arbeitsrecht', 'Digitalisierung'] },
];

const specificQuestionMessage = {} as { [key: string]: any}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this object is only stored in heap. therefore, it'd reset every time the bot re-deploys


const checkForFeedbackRequests = async () => {
const now = new Date();
const oneWeekAgo = new Date(now.getTime() - (7 * 24 * 60 * 60 * 1000));
Expand Down Expand Up @@ -108,7 +110,7 @@ export const sendTestButton = async () => {
const guild: Guild | undefined = client.guilds.cache.get(guildId);
if (!guild) throw new Error('Guild not found');

(guild.channels.cache.get("1135557183845711983") as TextChannel).send({ components: [actionRow] }); // Channel Id for #How-to-basics
(guild.channels.cache.get("1135557183845711983") as TextChannel).send({ components: [actionRow] }); // Channel Id for #How-to-basics; main sever: 1135557183845711983; test sever: 1159905209414332526
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(guild.channels.cache.get("1135557183845711983") as TextChannel).send({ components: [actionRow] }); // Channel Id for #How-to-basics; main sever: 1135557183845711983; test sever: 1159905209414332526
(guild.channels.cache.get("1135557183845711983") as TextChannel).send({ components: [actionRow] }); // Channel Id for #How-to-basics; main server: 1135557183845711983; test server: 1159905209414332526

};


Expand Down Expand Up @@ -175,6 +177,7 @@ export const sendQuestion = async (interaction: any) => {

if (currentQuestionIndex === 0) {
userResponses = [];
interaction.user.send("Bitte beantworte die folgenden Fragen. 🤗 Du kannst auf eine Frage immer nur einmal antworten: 😉")
}

if (currentQuestionIndex < questions.length) {
Expand All @@ -198,11 +201,13 @@ export const sendQuestion = async (interaction: any) => {
.setEmoji("👎"),
]);

interaction.user.send({
const questionMessage = await interaction.user.send({
embeds: [embed],
components: [builder]
});

specificQuestionMessage[interaction.user.id] = questionMessage;


// Update context for this user in the database
await db.db('contrabot').collection("users").updateOne(
Expand Down Expand Up @@ -289,6 +294,7 @@ export const sendQuestion = async (interaction: any) => {
}
}


async function conversationStarter(channelOfDestination: any, interaction: any, bestMatch: number[], user: number[]) {

// get all contrasting and similar answers
Expand Down Expand Up @@ -417,3 +423,4 @@ export const execute = async (interaction: any) => {
sendQuestion(interaction);
};

export { specificQuestionMessage }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw use individual exports instead of putting all exports at the end of the file

3 changes: 2 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dotenv/config'
import { Events } from 'discord.js';
import { sendQuestion, sendTestButton } from './commands/test/test-command';
import { sendQuestion, sendTestButton, specificQuestionMessage } from './commands/test/test-command';
import { sendSurveyQuestions, Feedbackquestions } from './startSurvey';
import * as fs from 'fs';
import path from 'path'
Expand Down Expand Up @@ -107,6 +107,7 @@ client.on(Events.InteractionCreate, async (interaction) => {
}
);

specificQuestionMessage[interaction.user.id].delete();
await interaction.deferUpdate();
sendQuestion(interaction);
}
Expand Down