-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/Transconlang/dictionary-dis…
- Loading branch information
Showing
3 changed files
with
34 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { refreshCachedLangSpec } from '@/lib/kumilinwa/refreshCache'; | ||
import { ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js'; | ||
|
||
export const data = new SlashCommandBuilder() | ||
.setName('recache') | ||
.setDescription('Refresh the cached language specification'); | ||
|
||
export async function execute(interaction: ChatInputCommandInteraction) { | ||
await interaction.deferReply(); | ||
await refreshCachedLangSpec(); | ||
await interaction.editReply('Refreshed the language specification cache!'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { LangSpecURL } from '@/config'; | ||
import Jsoning from 'jsoning'; | ||
import { logger } from '../misc/logger'; | ||
import { writeFile } from 'fs/promises'; | ||
import { dirname, join } from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
const Dirname = join(dirname(fileURLToPath(import.meta.url))); | ||
|
||
export async function refreshCachedLangSpec() { | ||
const data = await fetch(LangSpecURL).then(res => res.json()); | ||
await writeFile(join(Dirname, 'langspec.cache.json'), JSON.stringify(data)); | ||
await new Jsoning(join('..', '..', '..', 'stats.tmp.db.json')).set( | ||
'langSpecCacheAge', | ||
Date.now() | ||
); | ||
logger.debug('Cached language specification.'); | ||
} |