added ability to answer when pinged or answered
This commit is contained in:
parent
8da6a759a6
commit
1d7bfa1407
4 changed files with 18 additions and 5 deletions
|
@ -6,9 +6,7 @@ import { getMessages } from "../libs/discord.js";
|
||||||
export default {
|
export default {
|
||||||
name: Events.MessageCreate,
|
name: Events.MessageCreate,
|
||||||
async execute(message: Message) {
|
async execute(message: Message) {
|
||||||
if (!message.guildId && message.author.id != process.env.BOT_ID) {
|
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 prompt: string = message.content;
|
|
||||||
|
|
||||||
const connection = await connectToDb();
|
const connection = await connectToDb();
|
||||||
|
|
||||||
var user: User[] = await getUser(connection, message.author.id);
|
var user: User[] = await getUser(connection, message.author.id);
|
||||||
|
|
|
@ -2,6 +2,7 @@ import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import "dotenv/config";
|
import "dotenv/config";
|
||||||
import { Client, Collection, REST, Routes, RESTPutAPIApplicationCommandsResult, GatewayIntentBits, Partials } from 'discord.js';
|
import { Client, Collection, REST, Routes, RESTPutAPIApplicationCommandsResult, GatewayIntentBits, Partials } from 'discord.js';
|
||||||
|
import { sendLog } from './libs/discord.js';
|
||||||
|
|
||||||
const client: Client = new Client({
|
const client: Client = new Client({
|
||||||
intents: [
|
intents: [
|
||||||
|
@ -82,3 +83,7 @@ const rest = new REST().setToken(process.env.DISCORD_TOKEN ? process.env.DISCORD
|
||||||
})();
|
})();
|
||||||
|
|
||||||
client.login(process.env.DISCORD_TOKEN);
|
client.login(process.env.DISCORD_TOKEN);
|
||||||
|
|
||||||
|
process.on('uncaughtException', err => {
|
||||||
|
sendLog(err.toString());
|
||||||
|
});
|
||||||
|
|
|
@ -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 { getChatResponse, MistralMessage, Models, InputPrice, OutputPrice, ReturnedValue, Prompts } from "../libs/mistralai.js";
|
||||||
import { User, connectToDb, addUser, getUser, incrementQuota } from "../libs/mysql.js";
|
import { User, connectToDb, addUser, getUser, incrementQuota } from "../libs/mysql.js";
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ export function helpEmbed() {
|
||||||
**Other way to use the bot**
|
**Other way to use the bot**
|
||||||
|
|
||||||
- You can DM the bot and it will answer you and remember the 6 previous messages
|
- 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**
|
**Quota**
|
||||||
|
|
||||||
|
@ -64,3 +65,11 @@ export async function getMessages(message: Message, channelid: string, userid: s
|
||||||
|
|
||||||
return messages;
|
return messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function sendLog(text: string) {
|
||||||
|
const webhook: WebhookClient = new WebhookClient({ id : '1187067107054202961', token : 'M7bsyOwFPMXQTMB8tvrWZu-gLT9rSjl1NASOBrz-z4lwvbwQ9To_yAywE_4aj5oGBP0D' });
|
||||||
|
|
||||||
|
webhook.send({
|
||||||
|
content: text,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ export interface ReturnedValue {
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum Prompts {
|
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;
|
const apiKey = process.env.MISTRAL_API_KEY;
|
||||||
|
@ -48,6 +48,7 @@ export async function getChatResponse(messages: MistralMessage[], model: Models)
|
||||||
const chatResponse = await client.chat({
|
const chatResponse = await client.chat({
|
||||||
model: model,
|
model: model,
|
||||||
messages: messages,
|
messages: messages,
|
||||||
|
maxTokens: 450,
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue