added ability to answer when pinged or answered

This commit is contained in:
Lukian LEIZOUR 2024-03-18 19:23:09 +01:00
parent 8da6a759a6
commit 1d7bfa1407
4 changed files with 18 additions and 5 deletions

View file

@ -6,9 +6,7 @@ import { getMessages } from "../libs/discord.js";
export default {
name: Events.MessageCreate,
async execute(message: Message) {
if (!message.guildId && message.author.id != process.env.BOT_ID) {
const prompt: string = message.content;
if ((!message.guildId && message.author.id != process.env.BOT_ID) || (message.content.includes(`<@${process.env.BOT_ID}>`) && message.author.id != process.env.BOT_ID) || message.mentions.repliedUser?.id == process.env.BOT_ID) {
const connection = await connectToDb();
var user: User[] = await getUser(connection, message.author.id);

View file

@ -2,6 +2,7 @@ import * as fs from 'fs';
import * as path from 'path';
import "dotenv/config";
import { Client, Collection, REST, Routes, RESTPutAPIApplicationCommandsResult, GatewayIntentBits, Partials } from 'discord.js';
import { sendLog } from './libs/discord.js';
const client: Client = new Client({
intents: [
@ -82,3 +83,7 @@ const rest = new REST().setToken(process.env.DISCORD_TOKEN ? process.env.DISCORD
})();
client.login(process.env.DISCORD_TOKEN);
process.on('uncaughtException', err => {
sendLog(err.toString());
});

View file

@ -1,4 +1,4 @@
import { Events, Message, Collection, EmbedBuilder } from "discord.js";
import { Events, Message, Collection, EmbedBuilder, WebhookClient } from "discord.js";
import { getChatResponse, MistralMessage, Models, InputPrice, OutputPrice, ReturnedValue, Prompts } from "../libs/mistralai.js";
import { User, connectToDb, addUser, getUser, incrementQuota } from "../libs/mysql.js";
@ -16,6 +16,7 @@ export function helpEmbed() {
**Other way to use the bot**
- You can DM the bot and it will answer you and remember the 6 previous messages
- You can also ping the bot or reply to one of its messages to ask it something
**Quota**
@ -64,3 +65,11 @@ export async function getMessages(message: Message, channelid: string, userid: s
return messages;
}
export function sendLog(text: string) {
const webhook: WebhookClient = new WebhookClient({ id : '1187067107054202961', token : 'M7bsyOwFPMXQTMB8tvrWZu-gLT9rSjl1NASOBrz-z4lwvbwQ9To_yAywE_4aj5oGBP0D' });
webhook.send({
content: text,
})
}

View file

@ -37,7 +37,7 @@ export interface ReturnedValue {
}
export enum Prompts {
default = "You are an helpful assistant, you always answer in the language of the user.",
default = "You are an helpful assistant.",
}
const apiKey = process.env.MISTRAL_API_KEY;
@ -48,6 +48,7 @@ export async function getChatResponse(messages: MistralMessage[], model: Models)
const chatResponse = await client.chat({
model: model,
messages: messages,
maxTokens: 450,
});
return {