nuno ревизій цього gist 3 weeks ago. До ревизії
1 file changed, 64 insertions
gistfile1.txt(файл створено)
| @@ -0,0 +1,64 @@ | |||
| 1 | + | import path from "path"; | |
| 2 | + | import { BotConfig, Nation } from "../types"; | |
| 3 | + | import { Store } from "@systems/store"; | |
| 4 | + | import { Paths } from "@helpers/paths"; | |
| 5 | + | ||
| 6 | + | ||
| 7 | + | // Function instead of const so env vars are read lazily at call time | |
| 8 | + | function getDefaults(): Required<BotConfig> { | |
| 9 | + | return { | |
| 10 | + | officerRoles: ["Ice King"], | |
| 11 | + | configRoles: ["Ice King"], | |
| 12 | + | tagRoles: ["Ice King", "Ice", "Rebellion"], | |
| 13 | + | lockMessage: "🔒 This poll has been locked.", | |
| 14 | + | confirmYesMessage: "⚔️ TG is confirmed for tonight!", | |
| 15 | + | confirmNoMessage: "❌ TG is cancelled for tonight.", | |
| 16 | + | pollChannelId: process.env.POLL_CHANNEL_ID ?? "", | |
| 17 | + | resultsChannelId: process.env.RESULTS_CHANNEL_ID ?? "", | |
| 18 | + | scoreChannelId: process.env.SCORE_CHANNEL_ID ?? "", | |
| 19 | + | slots: [ | |
| 20 | + | { tgHour: 20, pollOpens: "10:00", closesAfter: 35, active: true }, | |
| 21 | + | ], | |
| 22 | + | scoreWindowHours: 2, | |
| 23 | + | tgDurationMinutes: 35, | |
| 24 | + | nationSource: Nation.Procyon, | |
| 25 | + | wRankPostOnReset: false, | |
| 26 | + | wRankGoal: 7, | |
| 27 | + | wRankYellowColor: "#BA7517", | |
| 28 | + | wRankGrayColor: "#888888", | |
| 29 | + | deltaUpColor: "#A32D2D", | |
| 30 | + | deltaDownColor: "#185FA5", | |
| 31 | + | stormBringerColor: "#185FA5", | |
| 32 | + | luminousBringerColor: "#8B4CB8", | |
| 33 | + | showClassInMessages: false, | |
| 34 | + | showLevelInMessages: false, | |
| 35 | + | charDisplayFormat: "{wrank} {class} {level} {name}", | |
| 36 | + | showNationTotalsInHeader: false, | |
| 37 | + | showNoInNationField: false, | |
| 38 | + | borrowRequestExpiryMs: 0, // 0 = never expire | |
| 39 | + | conflictReclaimBehavior: "revert", | |
| 40 | + | }; | |
| 41 | + | } | |
| 42 | + | ||
| 43 | + | let _cfg: BotConfig = {}; | |
| 44 | + | ||
| 45 | + | export function loadConfig(): void { | |
| 46 | + | _cfg = Store.readOrDefault(Paths.data("config.json"), {}); | |
| 47 | + | } | |
| 48 | + | export function saveConfig(): void { | |
| 49 | + | Store.write(Paths.data("config.json"), _cfg); | |
| 50 | + | } | |
| 51 | + | ||
| 52 | + | export function cfg<K extends keyof BotConfig>(key: K): Required<BotConfig>[K] { | |
| 53 | + | return (_cfg[key] !== undefined ? _cfg[key] : getDefaults()[key]) as Required<BotConfig>[K]; | |
| 54 | + | } | |
| 55 | + | ||
| 56 | + | export function setCfg<K extends keyof BotConfig>(key: K, value: BotConfig[K]): void { | |
| 57 | + | _cfg[key] = value; | |
| 58 | + | saveConfig(); | |
| 59 | + | } | |
| 60 | + | ||
| 61 | + | export function resetCfg<K extends keyof BotConfig>(key: K): void { | |
| 62 | + | delete _cfg[key]; | |
| 63 | + | saveConfig(); | |
| 64 | + | } | |
Новіше
Пізніше