This commit is contained in:
Lukian LEIZOUR 2023-03-04 12:27:30 +01:00
parent 6781c7ff91
commit fcd80c5ac8
3 changed files with 43 additions and 4 deletions

24
app.js
View file

@ -9,7 +9,7 @@ const { rtag, r34 } = require('./libs/rule34');
const { addToLogs, isTrue, image_search, getHelp } = require('./libs/botTools');
const { rockPaperScissorsAgainstBot } = require('./libs/games');
const { generateImage, answerQuestion } = require('./libs/openAi');
const { addUserToDb, incrementQuota, usersInDb, getQuota, addConv, delConv } = require('./libs/mysql');
const { addUserToDb, incrementQuota, usersInDb, getQuota, addConv, delConv, getConvs } = require('./libs/mysql');
//bot initialization
const bot = new Telegraf(process.env.TELEGRAM);
@ -207,14 +207,32 @@ client.on('interactionCreate', async interaction => {
}
else if (interaction.commandName === 'addconv') {
console.log(await addConv(interaction.options.get('name').value));
interaction.reply('Conversation added to db');
if (!interaction.options.get('name').value.includes(" ")) {
console.log(await addConv(interaction.options.get('name').value));
interaction.reply('Conversation added to db');
} else {
interaction.reply('Conversation name cannot contain spaces');
}
}
else if (interaction.commandName === 'delconv') {
console.log(await delConv(interaction.options.get('name').value));
interaction.reply('Conversation deleted from db');
}
else if (interaction.commandName === 'listconvs') {
convs = await getConvs();
message = "";
if (convs.length == 0) {
message = "No conversations in the database";
} else {
convs.forEach(element => {
message += element + "\n";
});
}
interaction.reply(message);
}
});
//bot launch

View file

@ -95,4 +95,20 @@ function delConv (convName) {
});
}
module.exports = { addUserToDb, incrementQuota, usersInDb, getQuota, addConv, delConv };
function getConvs() {
return new Promise((resolve, reject) => {
connection.query('SELECT name FROM conversations', (error, results, fields) => {
if (error) {
reject(error);
} else {
convs = [];
results.forEach(element => {
convs.push(element.name);
});
resolve(convs);
}
});
});
}
module.exports = { addUserToDb, incrementQuota, usersInDb, getQuota, addConv, delConv, getConvs };

View file

@ -57,6 +57,11 @@ const commands = [
},
],
},
{
name : 'listconvs',
description : 'List all the conversations in the database',
},
];
const rest = new REST({ version: '10' }).setToken(process.env.DISCORD);