This repository has been archived by the owner on Mar 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
messages.ts
357 lines (346 loc) · 11.6 KB
/
messages.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
//#region Imports
import { MessageOptions, EmbedField, MessageSelectMenu, MessageEmbed } from "discord.js";
import { M2D_LogUtils } from "./log";
import { M2D_EErrorTypes, M2D_GeneralUtils, M2D_IEmbedOptions, M2D_IError } from "./utils";
//#endregion
//#region Types
interface M2D_IMessages {
[key: string]: M2D_IEmbedOptions;
};
//#region Error types
const enum M2D_EMessagesErrorSubtypes {
InsertsReplacesMismatch = "INSERTS_REPLACES_MISMATCH",
NoReplacesProvided = "NO_REPLACES_PROVIDED",
MessageNotFound = "MESSAGE_NOT_FOUND"
};
interface M2D_IMessagesInsertsReplacesMismatchError extends M2D_IError {
data: {
strings: string[];
insertsCount: number;
replacesCount: number;
}
};
interface M2D_IMessagesNoReplacesProvidedError extends M2D_IError {
data: {
messageKey: string;
}
};
interface M2D_IMessagesMessageNotFoundError extends M2D_IError {
data: {
messageKey: string;
}
};
type M2D_MessagesError = M2D_IMessagesInsertsReplacesMismatchError |
M2D_IMessagesNoReplacesProvidedError |
M2D_IMessagesMessageNotFoundError;
//#endregion
//#endregion
const M2D_MESSAGES: M2D_IMessages = {
"clientInvokingCommandError": {
type: "error",
title: `Błąd!`,
description: `Wystąpił błąd podczas **wykonywania komendy** \`%s\`.\n\n**Oznaczenie błędu**: \`%s\`\n**Dane o błędzie**: \`%s\``
},
"clientServerLeave": {
type: "info",
title: `Opuszczenie serwera`,
description: `Muzyk2D **opuści ten serwer** za **%s sekund**.\n\nPowód: %s`
},
"commandsHelpShowCommandsFromCategory": {
type: "info",
title: `Informacje o komendach z kategorii "%s"`,
description: `%s`
},
"commandsHelpNoCategoryProvided": {
type: `error`,
title: `Nie podano kategorii!`,
description: `Nie podano żadnej kategorii, z której miałyby zostać wyświetlone komendy.\n**Oto lista dostępnych kategorii**:\n\`\`\`%s\`\`\``
},
"commandsStatus": {
type: `info`,
title: `Muzyk2D - status`,
description: `**Połączenie z kanałem głosowym**:\n**Status**:%s\n**Nazwa kanału**:%s\n\n**Playlista**:\n**Status**:%s\n**Wielkość**:%s\n**Obecna pozycja**:%s\n\n**Odtwarzanie**:\n**Status**:%s\n**Tryb odtwarzania**:%s\n\n**Ogólne**:\n**Wersja**:%s`
},
"configKeyNotFound": {
type: `error`,
title: `Nie znaleziono klucza konfiguracji!`,
description: `Nie znaleziono \`%s\` na liście kluczy konfiguracji!`
},
"configKeyNotOverridable": {
type: `error`,
title: `Podany klucz konfiguracji nie jest modyfikowalny`,
description: `\`%s\` jest kluczem konfiguracji, którego **nie można modyfikować na poziomie serwerowym**!`
},
"configKeyOverriden": {
type: `success`,
title: `Pomyślnie zmieniono wartość klucza konfiguracji!`,
description: `Pomyślnie **zmieniono wartość klucza** \`%s\` na \`%s\`!`
},
"configKeyOverrideDeleted": {
type: `success`,
title: `Przywrócono klucz konfiguracji do wartości domyślnej!`,
description: `Pomyślnie **przywrócono klucz konfiguracji** \`%s\` **do wartości domyślnej**!`
},
"configKeyPrint": {
type: `info`,
title: `Informacje o kluczu konfiguracji`,
description: `**Nazwa**: \`%s\`\n**Wartość**: \`%s\``
},
"configOverridableKeys": {
type: `info`,
title: `Modyfikowalne klucze konfiguracji`,
description: `**Lista modyfikowalnych kluczy konfiguracji**:\n\n%s`
},
"configOverrides": {
type: `info`,
title: `Konfiguracja dla serwera **%s**`,
description: `%s`
},
"configPrint": {
type: `info`,
title: `Konfiguracja`,
description: `%s`
},
"generalScheduleShutdown": {
type: "info",
title: "Zaplanowano wyłączenie",
description: `Za %s sekund nastąpi **planowe wyłączenie Muzyka2D**\n\n**Powód**:\n%s`
},
"generalStartupMessage": {
type: `info`,
title: `Muzyk2D został aktywowany!`,
description: `Wszystkie moduły zostały poprawnie zainicjalizowane!\n\n**Wersja**: \`%s\`\nby %s%s`
},
"generalDevMessage": {
type: "info",
title: "Wiadomość od dewelopera",
description: `Deweloper wysłał następującą wiadomość:\n%s`
},
"playbackDownloadingStream": {
type: "info",
title: `Pobieranie strumienia...`,
description: `Muzyk2D rozpoczął proces pobierania strumienia z YouTube.\n\n**W przeciągu %s sekund powinno rozpocząć się odtwarzanie utworu.**`
},
"playbackStreamDownloadTimedOut": {
type: "error",
title: `Nie udało się pobrać strumienia!`,
description: `Nie udało się pobrać strumienia z YouTube w wyznaczonym czasie.`
},
"playbackStreamDownloadError": {
type: "error",
title: `Nie udało się pobrać strumienia!`,
description: `Podczas pobierania strumienia z YouTube wystąpił błąd. Spróbuj ponownie.`
},
"playbackStarted": {
type: "success",
title: `Rozpoczęto odtwarzanie!`,
description: `Rozpoczęło się odtwarzanie "%s" (%s) z pozycji \`%s\`.`
},
"playbackPaused": {
type: "success",
title: `Zapauzowano!`,
description: `Pomyślnie **zapauzowano odtwarzanie**!`
},
"playbackIdling": {
type: "info",
title: `Brak pracy`,
description: `Odtwarzacz przeszedł w stan braku pracy. Jeśli utrzyma się w takim stanie przez %s sekund, odtwarzanie zostanie **zniszczone**.`
},
"playbackTimedOut": {
type: "info",
title: `Odtwarzanie zniszczone!`,
description: `Odtworzenie było zapauzowane/zastopowane przez zbyt długi czas, dlatego też zostało ono **zniszczone**. Aby odtworzyć utwór jeszcze raz, skorzystaj z komendy \`odtwórz\`.`
},
"playbackUnpaused": {
type: "success",
title: `Odpauzowano!`,
description: `Pomyślnie **odpauzowano odtwarzanie**!`
},
"playbackStopped": {
type: "success",
title: `Zastopowano!`,
description: `Pomyślnie **zastopowano odtwarzanie**!`
},
"playbackSongSkipped": {
type: "success",
title: `Przewinięto pozycję!`,
description: `Pomyślnie **przewinięto do następnej pozycji na playliście**!`
},
"playbackSwitchedMode": {
type: "success",
title: "Przełączono tryb!",
description: `Zmieniono tryb odtwarzania na **%s**`
},
"playlistAddedEntry": {
type: "success",
title: "Dodano wpis do playlisty!",
description: `Pomyślnie **dodano nowy wpis do playlisty**!`
},
"playlistDeletedEntry": {
type: "success",
title: "Usunięto wpis!",
description: `Pomyślnie **usunięto wpis o ID** \`%s\` **z playlisty**!`
},
"playlistFlushedPlaylist": {
type: "success",
title: `Wyczyszczono playlistę!`,
description: `Pomyślnie **wyczyszczono playlistę**!`
},
"playlistEmptyPlaylist": {
type: "error",
title: `Playlista`,
description: `Playlista jest **pusta**!`
},
"playlistShowPlaylist": {
type: "info",
title: `Playlista`,
description: "%s"
},
"voiceUserNotInVoiceChannel": {
title: "Błąd!",
description: `**Nie znajdujesz się na żadnym kanale głosowym**, więc Muzyk2D **nie wie, gdzie ma dołączyć**!`,
type: "error"
},
"voiceUserNotInTheSameVoiceChannel": {
type: "error",
title: "Błąd!",
description: `**Nie znajdujesz się na tym samym kanale głosowym, co Muzyk2D**, więc nie możesz w tym momencie wywołać tej komendy!`
},
"voiceClientNotInVoiceChannel": {
type: "error",
title: "Błąd!",
description: `Muzyk2D **nie znajduje się obecnie na żadnym kanale głosowym**!`
},
"voiceClientAlreadyInVoiceChannel": {
title: "Błąd!",
description: `Muzyk2D **już znajduje się na kanale głosowym**!`,
type: "error"
},
"voiceConnectedToVoiceChannel": {
type: "success",
title: "Dołączono!",
description: `Pomyślnie dołączono na kanał **%s**!`
},
"voiceDisconnectedFromVoiceChannel": {
type: "success",
title: "Odłączono!",
description: `Pomyślnie odłączono z kanału głosowego!`
},
"voiceTooFewVCMembersDetected": {
type: `info`,
title: `Wykryto zbyt niską liczbę członków na kanale!`,
description: `W związku z tym, po upływie %s sekund, nastąpi automatyczne rozłączenie z kanału.`
},
"voiceTooFewVCMembersTimeoutFinished": {
type: `info`,
title: `Zbyt niska liczba członków na kanale utrzymała się przez zbyt długi czas!`,
description: `Nastąpiło automatyczne rozłączenie z kanału.`
},
"youtubeAPIWrongUrl": {
type: "error",
title: "Niepoprawny URL!",
description: `Podany URL (\`%s\`) nie jest **prawidłowym linkiem do wideo na YouTube**!`
}
};
const M2D_MessagesUtils = {
countInserts: (str: string) => (str.match(/%s/g) || []).length,
replaceInserts: (str: string, ...replaces: string[]) => new Promise<string>((res, rej) => {
if(M2D_MessagesUtils.countInserts(str) === 0) res(str);
else if(M2D_MessagesUtils.countInserts(str) !== replaces.length) rej({
type: M2D_EErrorTypes.Messages,
subtype: M2D_EMessagesErrorSubtypes.InsertsReplacesMismatch,
data: {
strings: [str],
insertsCount: M2D_MessagesUtils.countInserts(str),
replacesCount: replaces.length
}
} as M2D_IMessagesInsertsReplacesMismatchError);
else {
let outStr = str;
for(const v of replaces) {
outStr = outStr.replace(/%s/, v);
}
res(outStr);
}
}),
getMessage: (key: string, replaces?: string[], thumbnailUrl?: string, imageUrl?: string, fields?: EmbedField[]) => new Promise<MessageEmbed>((res, rej) => {
if(M2D_MESSAGES[key]) {
const message = { ...M2D_MESSAGES[key] };
const titleInsertsCount = (message.title) ? M2D_MessagesUtils.countInserts(message.title) : 0;
const descInsertsCount = M2D_MessagesUtils.countInserts(message.description);
const titleReplaces: string[] = [];
const descReplaces: string[] = [];
if(titleInsertsCount + descInsertsCount > 0) {
if(replaces) {
if(replaces.length === (titleInsertsCount + descInsertsCount)) {
for(let i = 0; i < (titleInsertsCount + descInsertsCount); i++) {
if(i < titleInsertsCount) {
titleReplaces.push(replaces[i]);
} else {
descReplaces.push(replaces[i]);
}
}
M2D_MessagesUtils.replaceInserts(message.description, ...descReplaces)
.then((repDesc: string) => {
if(message.title) {
return M2D_MessagesUtils.replaceInserts(message.title, ...titleReplaces)
.then((repTitle: string) => {
message.title = repTitle;
message.description = repDesc;
})
} else {
message.description = repDesc;
return Promise.resolve();
}
})
.then(() => {
if(thumbnailUrl) message.thumbnailURL = thumbnailUrl;
if(imageUrl) message.imageURL = imageUrl;
if(fields) message.fields = fields;
return Promise.resolve(M2D_GeneralUtils.embedBuilder(message));
})
.then((val) => res(val))
.catch((err) => rej(err));
} else rej({
type: M2D_EErrorTypes.Messages,
subtype: M2D_EMessagesErrorSubtypes.InsertsReplacesMismatch,
data: {
strings: (message.title) ? [message.title, message.description] : [message.description],
insertsCount: titleInsertsCount + descInsertsCount,
replacesCount: replaces.length
}
} as M2D_IMessagesInsertsReplacesMismatchError);
} else rej({
type: M2D_EErrorTypes.Messages,
subtype: M2D_EMessagesErrorSubtypes.NoReplacesProvided,
data: {
messageKey: key
}
} as M2D_IMessagesNoReplacesProvidedError);
} else {
if(thumbnailUrl) message.thumbnailURL = thumbnailUrl;
if(imageUrl) message.imageURL = imageUrl;
if(fields) message.fields = fields;
res(M2D_GeneralUtils.embedBuilder(message));
}
} else rej({
type: M2D_EErrorTypes.Messages,
subtype: M2D_EMessagesErrorSubtypes.MessageNotFound,
data: {
messageKey: key
}
} as M2D_IMessagesMessageNotFoundError);
})
};
//#region Exports
export type {
M2D_IMessagesInsertsReplacesMismatchError,
M2D_IMessagesNoReplacesProvidedError,
M2D_IMessagesMessageNotFoundError,
M2D_MessagesError
};
export {
M2D_EMessagesErrorSubtypes,
M2D_MessagesUtils
};
//#endregion