added two new commands
This commit is contained in:
parent
2901c12bb9
commit
8da6a759a6
12 changed files with 271 additions and 194 deletions
|
@ -1,21 +1,21 @@
|
|||
import { Events, Interaction } from "discord.js";
|
||||
|
||||
export default {
|
||||
name: Events.InteractionCreate,
|
||||
async execute(interaction: Interaction) {
|
||||
if (interaction.isChatInputCommand()) {
|
||||
const command = interaction.client.commands.get(interaction.commandName);
|
||||
name: Events.InteractionCreate,
|
||||
async execute(interaction: Interaction) {
|
||||
if (interaction.isChatInputCommand()) {
|
||||
const command = interaction.client.commands.get(interaction.commandName);
|
||||
|
||||
if (!command) {
|
||||
return console.error(`No command matching ${interaction.commandName} was found.`);
|
||||
}
|
||||
if (!command) {
|
||||
return console.error(`No command matching ${interaction.commandName} was found.`);
|
||||
}
|
||||
|
||||
try {
|
||||
await command.execute(interaction);
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
},
|
||||
try {
|
||||
await command.execute(interaction);
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -4,36 +4,36 @@ import { User, connectToDb, addUser, getUser, incrementQuota } from "../libs/mys
|
|||
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;
|
||||
name: Events.MessageCreate,
|
||||
async execute(message: Message) {
|
||||
if (!message.guildId && message.author.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);
|
||||
|
||||
if (!user[0]) {
|
||||
await addUser(connection, message.author.username, message.author.id);
|
||||
user = await getUser(connection, message.author.id);
|
||||
}
|
||||
if (!user[0]) {
|
||||
await addUser(connection, message.author.username, message.author.id);
|
||||
user = await getUser(connection, message.author.id);
|
||||
}
|
||||
|
||||
if (user[0].quota > 0.4) {
|
||||
message.reply("You have exceed your quota.")
|
||||
connection.end();
|
||||
return;
|
||||
}
|
||||
if (user[0].quota > 0.4) {
|
||||
message.reply("You have exceed your quota.")
|
||||
connection.end();
|
||||
return;
|
||||
}
|
||||
|
||||
const messages: MistralMessage[] = await getMessages(message, message.channelId, message.author.id);
|
||||
const messages: MistralMessage[] = await getMessages(message, message.channelId, message.author.id);
|
||||
|
||||
await message.channel.sendTyping();
|
||||
await message.channel.sendTyping();
|
||||
|
||||
const response: ReturnedValue = await getChatResponse(messages, Models.multi_tiny);
|
||||
const response: ReturnedValue = await getChatResponse(messages, Models.multi_tiny);
|
||||
|
||||
await incrementQuota(connection, message.author.id, InputPrice.multi_tiny * response.promptUsage + OutputPrice.multi_tiny * response.responseUsage);
|
||||
connection.end();
|
||||
await incrementQuota(connection, message.author.id, InputPrice.multi_tiny * response.promptUsage + OutputPrice.multi_tiny * response.responseUsage);
|
||||
connection.end();
|
||||
|
||||
message.reply(response.message);
|
||||
}
|
||||
},
|
||||
message.reply(response.message);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -2,19 +2,19 @@ import { Events, Client } from "discord.js";
|
|||
import { checkReset } from "../libs/quotaReset.js";
|
||||
|
||||
export default {
|
||||
name: Events.ClientReady,
|
||||
once: true,
|
||||
execute(client: Client) {
|
||||
console.log(`Ready! Logged in as ${client.user?.tag}`);
|
||||
|
||||
client.user?.setPresence({ activities: [{ name: '/ask | Version 3.0 !', type: 3 }] });
|
||||
name: Events.ClientReady,
|
||||
once: true,
|
||||
execute(client: Client) {
|
||||
console.log(`Ready! Logged in as ${client.user?.tag}`);
|
||||
|
||||
client.user?.setPresence({ activities: [{ name: '/ask | Version 3.0 !', type: 3 }] });
|
||||
|
||||
setInterval(async () => {
|
||||
await checkReset();
|
||||
}, 10 * 60 * 1000);
|
||||
setInterval(async () => {
|
||||
await checkReset();
|
||||
}, 1000); //10 * 60 *
|
||||
|
||||
setInterval(async () => {
|
||||
client.user?.setPresence({ activities: [{ name: '/ask | Version 3.0 !', type: 3 }] });
|
||||
}, 10 * 60 * 1000);
|
||||
},
|
||||
setInterval(async () => {
|
||||
client.user?.setPresence({ activities: [{ name: '/ask | Version 3.0 !', type: 3 }] });
|
||||
}, 10 * 60 * 1000);
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue