parent
cf3102cbc5
commit
5a116b0531
4 changed files with 17 additions and 15 deletions
|
@ -38,7 +38,7 @@ export default class MyLimit extends Command implements Command {
|
||||||
const nthUseInLimitTimestamp = await nthUseInLimitTimestampPromise;
|
const nthUseInLimitTimestamp = await nthUseInLimitTimestampPromise;
|
||||||
|
|
||||||
if (userLimit === false || nthUseInLimitTimestamp === false) {
|
if (userLimit === false || nthUseInLimitTimestamp === false) {
|
||||||
interaction.reply({
|
await interaction.reply({
|
||||||
embeds: [{
|
embeds: [{
|
||||||
author: { name: interaction.user.username, icon_url: interaction.user.displayAvatarURL({ size: 128 }) },
|
author: { name: interaction.user.username, icon_url: interaction.user.displayAvatarURL({ size: 128 }) },
|
||||||
description: "User is a VIP, so there is no limit",
|
description: "User is a VIP, so there is no limit",
|
||||||
|
@ -48,7 +48,7 @@ export default class MyLimit extends Command implements Command {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
interaction.reply({
|
await interaction.reply({
|
||||||
embeds: [{
|
embeds: [{
|
||||||
author: { name: interaction.user.username, icon_url: interaction.user.displayAvatarURL({ size: 128 }) },
|
author: { name: interaction.user.username, icon_url: interaction.user.displayAvatarURL({ size: 128 }) },
|
||||||
fields: [
|
fields: [
|
||||||
|
|
|
@ -157,7 +157,7 @@ export async function queueRequest(request: apiRequest) {
|
||||||
"You've used up your message limit for today,\n" +
|
"You've used up your message limit for today,\n" +
|
||||||
`${userLimit.limit} requests in last 24 hours`,
|
`${userLimit.limit} requests in last 24 hours`,
|
||||||
}]
|
}]
|
||||||
}).catch(() => {/* GRACEFAIL: */});
|
}).catch(() => {/* FIXME: What should the bot do in this case to inform of limit reached?*/});
|
||||||
}
|
}
|
||||||
else if (request.isRepliable()) {
|
else if (request.isRepliable()) {
|
||||||
request.reply({
|
request.reply({
|
||||||
|
@ -175,7 +175,7 @@ export async function queueRequest(request: apiRequest) {
|
||||||
const shouldStart = messagesForChannel.length === 0;
|
const shouldStart = messagesForChannel.length === 0;
|
||||||
messagesForChannel.push(request as request);
|
messagesForChannel.push(request as request);
|
||||||
if (shouldStart)
|
if (shouldStart)
|
||||||
executeFromQueue(request.channelId);
|
void executeFromQueue(request.channelId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -234,10 +234,10 @@ async function executeFromQueue(channel: string) {
|
||||||
messages.forEach(m => { Moderation.checkMessage(m); });
|
messages.forEach(m => { Moderation.checkMessage(m); });
|
||||||
|
|
||||||
if (message instanceof DiscordApi.Message) {
|
if (message instanceof DiscordApi.Message) {
|
||||||
message.channel.sendTyping();
|
await message.channel.sendTyping();
|
||||||
}
|
}
|
||||||
else if (message.isRepliable()) {
|
else if (message.isRepliable()) {
|
||||||
message.deferReply();
|
await message.deferReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
OpenAImessages = toOpenAIMessages(messages);
|
OpenAImessages = toOpenAIMessages(messages);
|
||||||
|
@ -270,7 +270,7 @@ async function executeFromQueue(channel: string) {
|
||||||
const answerContent = answer.data.choices[0].message?.content;
|
const answerContent = answer.data.choices[0].message?.content;
|
||||||
|
|
||||||
if (answerContent === undefined || answerContent === "") {
|
if (answerContent === undefined || answerContent === "") {
|
||||||
if (message instanceof DiscordApi.Message) message.react("😶").catch(/*it's okay*/);
|
if (message instanceof DiscordApi.Message) message.react("😶").catch(() => {/* GRACEFAIL: It's okay if the bot won't reply */});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const answerMessagesContent :string[] = [""];
|
const answerMessagesContent :string[] = [""];
|
||||||
|
@ -286,8 +286,7 @@ async function executeFromQueue(channel: string) {
|
||||||
for (const i of answerMessagesContent) {
|
for (const i of answerMessagesContent) {
|
||||||
const response = requestReply(message, {content: i}, {allowedMentions: { repliedUser: false }});
|
const response = requestReply(message, {content: i}, {allowedMentions: { repliedUser: false }});
|
||||||
|
|
||||||
response.then(rval => Moderation.checkMessage(rval));
|
await response.then(rval => Moderation.checkMessage(rval));
|
||||||
await response;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -305,7 +304,7 @@ async function executeFromQueue(channel: string) {
|
||||||
}
|
}
|
||||||
else errorText = "";
|
else errorText = "";
|
||||||
|
|
||||||
requestReply(
|
await requestReply(
|
||||||
message,
|
message,
|
||||||
{
|
{
|
||||||
embeds: [{
|
embeds: [{
|
||||||
|
@ -322,5 +321,5 @@ async function executeFromQueue(channel: string) {
|
||||||
if (channelQueue.length === 0)
|
if (channelQueue.length === 0)
|
||||||
channelsRunning.delete(channel);
|
channelsRunning.delete(channel);
|
||||||
else
|
else
|
||||||
executeFromQueue(channel);
|
return executeFromQueue(channel);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ discord.on("messageCreate", message => {
|
||||||
if (message.author.bot) return;
|
if (message.author.bot) return;
|
||||||
if (!message.mentions.has(message.client.user)) return;
|
if (!message.mentions.has(message.client.user)) return;
|
||||||
|
|
||||||
queueRequest(message);
|
return queueRequest(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (require.main === module) discord.login(config.tokens.Discord);
|
if (require.main === module) void discord.login(config.tokens.Discord);
|
||||||
|
|
|
@ -36,7 +36,7 @@ export default class CommandManager {
|
||||||
color: 0xff0000,
|
color: 0xff0000,
|
||||||
description: `Failed to perform interaction:\n\`${e}\``,
|
description: `Failed to perform interaction:\n\`${e}\``,
|
||||||
}]
|
}]
|
||||||
}).catch(() => {/* GRACEFAIL: We're still logging the issue that happened to the console */});
|
}).catch(() => {/* NOTE: We're still logging the issue that happened to the console */});
|
||||||
console.error(`Failed to perform interaction: ${interaction.commandName}`);
|
console.error(`Failed to perform interaction: ${interaction.commandName}`);
|
||||||
console.error(e);
|
console.error(e);
|
||||||
});
|
});
|
||||||
|
@ -46,7 +46,10 @@ export default class CommandManager {
|
||||||
const foundCommand = this.commands.find((command) => command.name === interaction.commandName );
|
const foundCommand = this.commands.find((command) => command.name === interaction.commandName );
|
||||||
if (!foundCommand) throw new Error(`Unknown command received (${interaction.commandName}). Did you forgot to push updated commands?`);
|
if (!foundCommand) throw new Error(`Unknown command received (${interaction.commandName}). Did you forgot to push updated commands?`);
|
||||||
if (!foundCommand.autocomplete) return;
|
if (!foundCommand.autocomplete) return;
|
||||||
foundCommand.autocomplete(interaction);
|
foundCommand.autocomplete(interaction).catch(e => {
|
||||||
|
console.error(`Failed to perform autocomplete interaction: ${interaction.commandName}`);
|
||||||
|
console.error(e);
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue