Update eslintrc.json to also make it consider typings

note that I've marked Promises awaiting as a warn,
because I don't want to be bothered with it for now.

I also edited all files to accomodate with the new rules.

I should also think find a way to type-safely import Commands directory,
another time
This commit is contained in:
Wroclaw 2023-07-30 22:28:13 +02:00
parent c4676175ff
commit 7225739527
9 changed files with 35 additions and 23 deletions

View file

@ -134,9 +134,9 @@ function canReplyToRequest(request: apiRequest) {
export async function queueRequest(request: apiRequest) {
if (!request.channelId) {
if (request instanceof DiscordApi.Message)
request.reply("request does not have channelId");
await request.reply("request does not have channelId");
else if (request.isRepliable())
request.reply("request does not have channelId");
await request.reply("request does not have channelId");
console.log("There was incoming execution without channelId set, ignoring");
console.log(request);
return;
@ -148,7 +148,7 @@ export async function queueRequest(request: apiRequest) {
if (userLimit !== false && userLimit.remaining <= 0) {
if (request instanceof DiscordApi.Message) {
request.react("🛑").catch(/*it's okay*/);
request.react("🛑").catch(() => { /* NOTE: We send an informaton about limit reached in DM */ });
if (!request.author.dmChannel) await request.author.createDM();
request.author.dmChannel?.send({
embeds: [{
@ -157,13 +157,13 @@ export async function queueRequest(request: apiRequest) {
"You've used up your message limit for today,\n" +
`${userLimit.limit} requests in last 24 hours`,
}]
});
}).catch(() => {/* GRACEFAIL: */});
}
else if (request.isRepliable()) {
request.reply({
content: `You've used up your message limit for today, ${userLimit.limit} requests in last 24 hours`,
ephemeral: true,
});
}).catch(() => { /* Impossible to get there unless connection lost*/ });
}
return;
}
@ -172,7 +172,7 @@ export async function queueRequest(request: apiRequest) {
request.channelId,
() => { return []; },
);
const shouldStart = messagesForChannel.length == 0;
const shouldStart = messagesForChannel.length === 0;
messagesForChannel.push(request as request);
if (shouldStart)
executeFromQueue(request.channelId);
@ -191,7 +191,7 @@ function logUsedTokens(
) {
const usage = answer.data.usage;
const functionName = answer.data.choices[0].message?.function_call?.name;
if (usage != undefined) {
if (usage !== undefined) {
const channelName: string = !message.channel.isDMBased() ? `${message.channel.name} (${message.guild?.name})` : `@${getAuthor(message).tag}`;
console.log(`Used ${usage.total_tokens} (${usage.prompt_tokens} + ${usage.completion_tokens}) tokens for ${getAuthor(message).tag} (${getAuthor(message).id}) in #${channelName}${functionName ? " [Function: " + functionName + "]" : ""}`);
@ -231,7 +231,7 @@ async function executeFromQueue(channel: string) {
messages = messages.filter(m => message.createdTimestamp - m.createdTimestamp < config.limits.time );
messages.forEach(m => Moderation.checkMessage(m));
messages.forEach(m => { Moderation.checkMessage(m); });
if (message instanceof DiscordApi.Message) {
message.channel.sendTyping();
@ -269,7 +269,7 @@ async function executeFromQueue(channel: string) {
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*/);
}
else {
@ -293,7 +293,7 @@ async function executeFromQueue(channel: string) {
} catch (e) {
console.error(`Error ocurred while handling chat completion request (${(e as object).constructor.name}):`);
console.error(e);
if (OpenAImessages.length != 0) {
if (OpenAImessages.length !== 0) {
console.error("Messages:");
console.error(OpenAImessages);
}
@ -319,7 +319,7 @@ async function executeFromQueue(channel: string) {
}
channelQueue.shift();
if (channelQueue.length == 0)
if (channelQueue.length === 0)
channelsRunning.delete(channel);
else
executeFromQueue(channel);