commit
This commit is contained in:
parent
6781c7ff91
commit
fcd80c5ac8
3 changed files with 43 additions and 4 deletions
24
app.js
24
app.js
|
@ -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
|
||||
|
|
|
@ -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 };
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue