Skip to content

Commit

Permalink
style: Improve code.
Browse files Browse the repository at this point in the history
  • Loading branch information
vxern committed Sep 21, 2024
1 parent 8abd3b4 commit 8b69341
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 36 deletions.
4 changes: 3 additions & 1 deletion migrations/20240720193152_flatten-guild-documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ async function up(database: DatabaseStore): Promise<void> {
}

// This block is executed when the migration is rolled back.
function down(_: DatabaseStore): void {}
function down(_: DatabaseStore): void {
// Irreversible.
}

export { up, down };
6 changes: 4 additions & 2 deletions scripts/load/sentence-pairs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ for (const [locale, contents] of contentsAll) {
}

const lemmaUseKey = constants.keys.redis.lemmaUseIndex({ locale, lemma: data.segment });
(lemmaUseIndexes[lemmaUseKey] ??= []).push(sentenceId);
lemmaUseIndexes[lemmaUseKey] ??= [];
lemmaUseIndexes[lemmaUseKey].push(sentenceId);

const lemmaFormKey = constants.keys.redis.lemmaFormIndex({ locale, lemma: data.segment.toLowerCase() });
(lemmaFormIndexes[lemmaFormKey] ??= []).push(data.segment);
lemmaFormIndexes[lemmaFormKey] ??= [];
lemmaFormIndexes[lemmaFormKey].push(data.segment);
}

sentencePairs[constants.keys.redis.sentencePair({ locale, sentenceId })] = JSON.stringify(record);
Expand Down
4 changes: 2 additions & 2 deletions source/constants/licences/bsd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
\* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
\\* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
\* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.`,
\\* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.`,
`THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.`,
]);
4 changes: 2 additions & 2 deletions source/constants/patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ const patterns = Object.freeze({
userDisplay: /^.*?\(?(\d{16,20})\)?$/,
/** Used for matching YouTube video/playlist links, e.g. https://www.youtube.com/watch?v=zNbCbYbaE3Y */
youtubeUrl:
/^(?:https?:)?(?:\/\/)?(?:youtu\.be\/|(?:www\.|m\.)?youtube\.com\/(?:watch|v|embed)(?:\.php)?(?:\?.*v=|\/))([a-zA-Z0-9\_-]{7,15})(?:[\?&][a-zA-Z0-9\_-]+=[a-zA-Z0-9\_-]+)*$/,
/^(?:https?:)?(?:\/\/)?(?:youtu\.be\/|(?:www\.|m\.)?youtube\.com\/(?:watch|v|embed)(?:\.php)?(?:\?.*v=|\/))([a-zA-Z\d_-]{7,15})(?:[?&][a-zA-Z\d_-]+=[a-zA-Z\d_-]+)*$/,
/** Used for matching against role indicators in nicknames, e.g. Logos﹘EA・WA */
roleIndicators: new RegExp(
`^(.+)${special.sigils.divider}([^${special.sigils.separator}]{2,4}(?:${special.sigils.separator}[^${special.sigils.separator}]{2,4})*)$`,
),
/** Used for matching short time expressions, e.g. 22:51:09 */
conciseTimeExpression: /^(?:(?:(0?[0-9]|1[0-9]|2[0-4]):)?(?:(0?[0-9]|[1-5][0-9]|60):))?(0?[0-9]|[1-5][0-9]|60)$/,
conciseTimeExpression: /^(?:(?:(0?\d|1\d|2[0-4]):)?(?:(0?\d|[1-5]\d|60):))?(0?\d|[1-5]\d|60)$/,
/** Used for matching a full word and nothing else around. */
wholeWord: (word: string, { caseSensitive }: { caseSensitive: boolean }) =>
new RegExp(`(?<=^|\\p{Z}|\\p{P})${word}(?=\\p{Z}|\\p{P}|$)`, `gu${caseSensitive ? "" : "i"}`),
Expand Down
10 changes: 6 additions & 4 deletions source/library/adapters/databases/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,12 @@ abstract class DocumentSession {
);
}

const resultsUnsorted = await Promise.all(promises).then((results) => results.flat());
const resultsSorted = resultsUnsorted.sort(([_, a], [__, b]) => a - b);

return resultsSorted.map(([rawDocument, _]) => instantiateModel(this.database, rawDocument));
return Promise.all(promises).then((results) =>
results
.flat()
.toSorted(([_, a], [__, b]) => a - b)
.map(([rawDocument, _]) => instantiateModel(this.database, rawDocument)),
);
}

async dispose(): Promise<void> {
Expand Down
4 changes: 0 additions & 4 deletions source/library/adapters/databases/couchdb/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ class CouchDBAdapter extends DatabaseAdapter {
});
}

async setup(): Promise<void> {}

async teardown(): Promise<void> {}

conventionsFor({
document,
data,
Expand Down
4 changes: 2 additions & 2 deletions source/library/adapters/databases/ravendb/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ class RavenDBAdapter extends DatabaseAdapter {
});
}

setup(): void {
async setup(): Promise<void> {
this.#database.initialize();
}

teardown(): void {
async teardown(): Promise<void> {
this.#database.dispose();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,18 @@ class CorrectionComposer extends ModalComposer<CorrectionFormData, ValidationErr

getErrorMessage(
submission: Logos.Interaction,
{ error }: { error: ValidationError },
_: { error: ValidationError },
): Discord.CamelizedDiscordEmbed | undefined {
switch (error) {
case "texts-not-different": {
const strings = constants.contexts.correctionTextsNotDifferent({
localise: this.client.localise,
locale: submission.locale,
});
const strings = constants.contexts.correctionTextsNotDifferent({
localise: this.client.localise,
locale: submission.locale,
});

return {
title: strings.title,
description: strings.description,
color: constants.colours.warning,
};
}
}
return {
title: strings.title,
description: strings.description,
color: constants.colours.warning,
};
}
}

Expand Down
7 changes: 3 additions & 4 deletions source/library/commands/handlers/recognise.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { list } from "logos:constants/formatting";
import type { DetectionLanguage } from "logos:constants/languages/detection";
import type { Client } from "logos/client";
import { RecognitionSourceNotice } from "logos/commands/components/source-notices/recognition-notice";

Expand Down Expand Up @@ -66,7 +65,7 @@ async function handleRecogniseLanguage(
await sourceNotice.register();

if (detectedLanguages.likely.length === 1 && detectedLanguages.possible.length === 0) {
const language = detectedLanguages.likely.at(0) as DetectionLanguage | undefined;
const language = detectedLanguages.likely.at(0);
if (language === undefined) {
throw new Error("Detected language unexpectedly undefined.");
}
Expand Down Expand Up @@ -96,7 +95,7 @@ async function handleRecogniseLanguage(
const fields: Discord.CamelizedDiscordEmbedField[] = [];

if (detectedLanguages.likely.length === 1) {
const language = detectedLanguages.likely.at(0) as DetectionLanguage | undefined;
const language = detectedLanguages.likely.at(0);
if (language === undefined) {
throw new Error("Likely detected language unexpectedly undefined.");
}
Expand Down Expand Up @@ -126,7 +125,7 @@ async function handleRecogniseLanguage(
}

if (detectedLanguages.possible.length === 1) {
const language = detectedLanguages.possible.at(0) as DetectionLanguage | undefined;
const language = detectedLanguages.possible.at(0);
if (language === undefined) {
throw new Error("Possible detected language unexpectedly undefined.");
}
Expand Down
4 changes: 3 additions & 1 deletion source/library/services/lavalink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class ClientConnector extends shoukaku.Connector {
return this.client.bot.id.toString();
}

listen(_: shoukaku.NodeOption[]): void {}
listen(_: shoukaku.NodeOption[]): void {
// Do nothing.
}

sendPacket(shardId: number, payload: Discord.ShardSocketRequest, important: boolean): void {
const shard = this.client.bot.gateway.shards.get(shardId);
Expand Down

0 comments on commit 8b69341

Please sign in to comment.