chz-telegram-bot 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/build.ps1 +34 -0
  2. package/bun.lock +506 -0
  3. package/dist/entities/actions/commandAction.js +79 -0
  4. package/dist/entities/actions/scheduledAction.js +65 -0
  5. package/dist/entities/bot.js +75 -0
  6. package/dist/entities/cachedStateFactory.js +9 -0
  7. package/dist/entities/commandTriggerCheckResult.js +22 -0
  8. package/dist/entities/context/chatContext.js +30 -0
  9. package/dist/entities/context/messageContext.js +46 -0
  10. package/dist/entities/incomingMessage.js +20 -0
  11. package/dist/entities/responses/imageMessage.js +11 -0
  12. package/dist/entities/responses/reaction.js +11 -0
  13. package/dist/entities/responses/textMessage.js +11 -0
  14. package/dist/entities/responses/videoMessage.js +11 -0
  15. package/dist/entities/states/actionStateBase.js +8 -0
  16. package/dist/entities/states/potuzhnoState.js +13 -0
  17. package/dist/entities/taskRecord.js +10 -0
  18. package/dist/entities/transactionResult.js +9 -0
  19. package/dist/helpers/builders/commandActionBuilder.js +61 -0
  20. package/dist/helpers/builders/scheduledActionBuilder.js +42 -0
  21. package/dist/helpers/escapeMarkdown.js +17 -0
  22. package/dist/helpers/getWeek.js +12 -0
  23. package/dist/helpers/noop.js +13 -0
  24. package/dist/helpers/randomInt.js +8 -0
  25. package/dist/helpers/reverseMap.js +6 -0
  26. package/dist/helpers/timeConvertions.js +14 -0
  27. package/dist/helpers/toArray.js +6 -0
  28. package/dist/index.js +33 -0
  29. package/dist/services/logger.js +17 -0
  30. package/dist/services/storage.js +79 -0
  31. package/dist/services/taskScheduler.js +37 -0
  32. package/dist/services/telegramApi.js +94 -0
  33. package/dist/types/actionState.js +2 -0
  34. package/dist/types/actionWithState.js +2 -0
  35. package/dist/types/cachedValueAccessor.js +2 -0
  36. package/dist/types/commandCondition.js +2 -0
  37. package/dist/types/daysOfTheWeek.js +13 -0
  38. package/dist/types/handlers.js +2 -0
  39. package/dist/types/replyMessage.js +2 -0
  40. package/dist/types/scheduledItem.js +2 -0
  41. package/dist/types/timeValues.js +2 -0
  42. package/entities/actions/commandAction.ts +143 -0
  43. package/entities/actions/scheduledAction.ts +121 -0
  44. package/entities/bot.ts +143 -0
  45. package/entities/cachedStateFactory.ts +14 -0
  46. package/entities/commandTriggerCheckResult.ts +30 -0
  47. package/entities/context/chatContext.ts +57 -0
  48. package/entities/context/messageContext.ts +94 -0
  49. package/entities/incomingMessage.ts +27 -0
  50. package/entities/responses/imageMessage.ts +21 -0
  51. package/entities/responses/reaction.ts +20 -0
  52. package/entities/responses/textMessage.ts +20 -0
  53. package/entities/responses/videoMessage.ts +21 -0
  54. package/entities/states/actionStateBase.ts +5 -0
  55. package/entities/states/potuzhnoState.ts +5 -0
  56. package/entities/taskRecord.ts +13 -0
  57. package/entities/transactionResult.ts +11 -0
  58. package/eslint.config.js +10 -0
  59. package/helpers/builders/commandActionBuilder.ts +88 -0
  60. package/helpers/builders/scheduledActionBuilder.ts +67 -0
  61. package/helpers/escapeMarkdown.ts +12 -0
  62. package/helpers/getWeek.ts +8 -0
  63. package/helpers/noop.ts +13 -0
  64. package/helpers/randomInt.ts +7 -0
  65. package/helpers/reverseMap.ts +3 -0
  66. package/helpers/timeConvertions.ts +13 -0
  67. package/helpers/toArray.ts +3 -0
  68. package/index.ts +47 -0
  69. package/package.json +30 -0
  70. package/services/logger.ts +30 -0
  71. package/services/storage.ts +111 -0
  72. package/services/taskScheduler.ts +66 -0
  73. package/services/telegramApi.ts +172 -0
  74. package/tsconfig.json +110 -0
  75. package/types/actionState.ts +3 -0
  76. package/types/actionWithState.ts +6 -0
  77. package/types/cachedValueAccessor.ts +1 -0
  78. package/types/commandCondition.ts +6 -0
  79. package/types/daysOfTheWeek.ts +9 -0
  80. package/types/handlers.ts +14 -0
  81. package/types/replyMessage.ts +6 -0
  82. package/types/scheduledItem.ts +6 -0
  83. package/types/timeValues.ts +29 -0
@@ -0,0 +1,13 @@
1
+ /* eslint-disable @typescript-eslint/no-unused-vars */
2
+ class Noop {
3
+ static async true<T1>(arg1: T1) {
4
+ return true;
5
+ }
6
+ static async false<T1>(arg1: T1) {
7
+ return false;
8
+ }
9
+ static async call<T1, T2>(arg1: T1, arg2: T2): Promise<void>;
10
+ static async call<T1>(arg1: T1) {}
11
+ }
12
+
13
+ export default Noop;
@@ -0,0 +1,7 @@
1
+ export default function randomInteger(x1: number, x2: number): number {
2
+ const range = x2 - x1 + 1;
3
+
4
+ const random = Math.floor(Math.random() * range);
5
+
6
+ return random + x1;
7
+ }
@@ -0,0 +1,3 @@
1
+ export function reverseMap<K, V>(map: Map<K, V>): Map<V, K> {
2
+ return new Map(Array.from(map, ([key, value]) => [value, key]));
3
+ }
@@ -0,0 +1,13 @@
1
+ import { Hours, Milliseconds, Seconds } from '../types/timeValues';
2
+
3
+ export function secondsToMilliseconds(value: Seconds): Milliseconds {
4
+ return (value * 1000) as Milliseconds;
5
+ }
6
+
7
+ export function hoursToMilliseconds(value: Hours): Milliseconds {
8
+ return (value * 60 * 60 * 1000) as Milliseconds;
9
+ }
10
+
11
+ export function hoursToSeconds(value: Hours): Seconds {
12
+ return (value * 60 * 60) as Seconds;
13
+ }
@@ -0,0 +1,3 @@
1
+ export default function toArray<TType>(value: TType | TType[]) {
2
+ return Array.isArray(value) ? value : [value];
3
+ }
package/index.ts ADDED
@@ -0,0 +1,47 @@
1
+ import { readFile } from 'fs/promises';
2
+ import BotInstance from './entities/bot.js';
3
+ import taskScheduler from './services/taskScheduler.js';
4
+ import { setTimeout } from 'timers/promises';
5
+ import { Seconds } from './types/timeValues.js';
6
+ import { secondsToMilliseconds } from './helpers/timeConvertions.js';
7
+ import storage from './services/storage.js';
8
+ import logger from './services/logger.js';
9
+ import CommandAction from './entities/actions/commandAction.js';
10
+ import IActionState from './types/actionState.js';
11
+ import ScheduledAction from './entities/actions/scheduledAction.js';
12
+
13
+ const bots: BotInstance[] = [];
14
+
15
+ function log(text: string) {
16
+ logger.logWithTraceId('ALL BOTS', 'System:Bot', 'System', text);
17
+ }
18
+
19
+ async function startBot(
20
+ name: string,
21
+ tokenFile: string,
22
+ commands: CommandAction<IActionState>[],
23
+ scheduled: ScheduledAction[],
24
+ chats: Map<string, number>
25
+ ) {
26
+ const token = await readFile(tokenFile, 'utf8');
27
+ const bot = new BotInstance(name, token, commands, scheduled, chats);
28
+ bots.push(bot);
29
+
30
+ return bot;
31
+ }
32
+
33
+ async function stopBots(reason: string) {
34
+ log(`Recieved termination code: ${reason}`);
35
+ taskScheduler.stopAll();
36
+ log('Acquiring storage semaphore...');
37
+ await storage.semaphoreInstance.acquire();
38
+
39
+ log('Stopping bots...');
40
+ for (const bot of bots) {
41
+ bot.stop(reason);
42
+ }
43
+
44
+ process.exit(0);
45
+ }
46
+
47
+ export { startBot, stopBots };
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "chz-telegram-bot",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "dependencies": {
6
+ "async-sema": "^3.1.1",
7
+ "markdown-escape": "^2.0.0",
8
+ "moment": "^2.29.4",
9
+ "telegraf": "^4.16.3"
10
+ },
11
+ "main": "dist/index.js",
12
+ "types": "dist/index.d.ts",
13
+ "devDependencies": {
14
+ "@eslint/js": "^9.10.0",
15
+ "@types/markdown-escape": "^1.1.3",
16
+ "@types/node": "^22.5.5",
17
+ "eslint": "^9.10.0",
18
+ "typescript": "^5.6.2",
19
+ "typescript-eslint": "^8.5.0"
20
+ },
21
+ "scripts": {
22
+ "build": "tsc",
23
+ "lint": "npx eslint && tsc --noEmit"
24
+ },
25
+ "overrides": {
26
+ "telegraf": {
27
+ "node-fetch": "3.3.2"
28
+ }
29
+ }
30
+ }
@@ -0,0 +1,30 @@
1
+ class Logger {
2
+ logWithTraceId(
3
+ botName: string,
4
+ traceId: string | number,
5
+ chatName: string,
6
+ text: string
7
+ ) {
8
+ console.log(JSON.stringify({ botName, traceId, chatName, text }));
9
+ }
10
+
11
+ errorWithTraceId<TData>(
12
+ botName: string,
13
+ traceId: string | number,
14
+ chatName: string,
15
+ errorObj: string | Error,
16
+ extraData?: TData | undefined
17
+ ) {
18
+ console.error(
19
+ JSON.stringify({
20
+ botName,
21
+ traceId,
22
+ chatName,
23
+ errorObj,
24
+ extraData
25
+ })
26
+ );
27
+ }
28
+ }
29
+
30
+ export default new Logger();
@@ -0,0 +1,111 @@
1
+ import { existsSync } from 'fs';
2
+ import { dirname } from 'path';
3
+ import TransactionResult from '../entities/transactionResult';
4
+ import { mkdir, readFile, writeFile } from 'fs/promises';
5
+ import ActionStateBase from '../entities/states/actionStateBase';
6
+ import IActionState from '../types/actionState';
7
+ import IActionWithState from '../types/actionWithState';
8
+ import { Sema as Semaphore } from 'async-sema';
9
+
10
+ class Storage {
11
+ static semaphore = new Semaphore(1);
12
+ cache: Map<string, Record<number, ActionStateBase>>;
13
+
14
+ get semaphoreInstance() {
15
+ return Storage.semaphore;
16
+ }
17
+
18
+ constructor() {
19
+ this.cache = new Map<string, Record<number, ActionStateBase>>();
20
+ }
21
+
22
+ private async lock<TType>(action: () => Promise<TType>) {
23
+ await this.semaphoreInstance.acquire();
24
+
25
+ try {
26
+ return await action();
27
+ } finally {
28
+ this.semaphoreInstance.release();
29
+ }
30
+ }
31
+
32
+ private async loadInternal(key: string) {
33
+ if (!this.cache.has(key)) {
34
+ const targetPath = this.buidPathFromKey(key);
35
+ if (!existsSync(targetPath)) {
36
+ return {};
37
+ }
38
+
39
+ const fileContent = await readFile(targetPath, 'utf8');
40
+
41
+ if (fileContent) {
42
+ const data = JSON.parse(fileContent);
43
+
44
+ this.cache.set(key, data);
45
+ }
46
+ }
47
+
48
+ return this.cache.get(key) ?? {};
49
+ }
50
+
51
+ private async save(data: Record<number, ActionStateBase>, key: string) {
52
+ this.cache.delete(key);
53
+
54
+ const targetPath = this.buidPathFromKey(key);
55
+ const folderName = dirname(targetPath);
56
+
57
+ if (!existsSync(folderName)) {
58
+ await mkdir(folderName, { recursive: true });
59
+ }
60
+
61
+ await writeFile(targetPath, JSON.stringify(data), { flag: 'w+' });
62
+ }
63
+
64
+ private buidPathFromKey(key: string) {
65
+ return 'storage/' + key.replaceAll(':', '/') + '.json';
66
+ }
67
+
68
+ async load(key: string) {
69
+ return await this.lock(async () => {
70
+ return this.loadInternal(key);
71
+ });
72
+ }
73
+
74
+ async saveMetadata(actions: IActionWithState[], botName: string) {
75
+ return await this.lock(async () => {
76
+ const targetPath = this.buidPathFromKey(`Metadata-${botName}`);
77
+
78
+ await writeFile(targetPath, JSON.stringify(actions), {
79
+ flag: 'w+'
80
+ });
81
+ });
82
+ }
83
+
84
+ async getActionState<TActionState extends IActionState>(
85
+ entity: IActionWithState,
86
+ chatId: number
87
+ ) {
88
+ return await this.lock(async () => {
89
+ const data = await this.loadInternal(entity.key);
90
+
91
+ return (data[chatId] as TActionState) ?? entity.stateConstructor();
92
+ });
93
+ }
94
+
95
+ async commitTransactionForAction(
96
+ action: IActionWithState,
97
+ chatId: number,
98
+ transactionResult: TransactionResult
99
+ ) {
100
+ await this.lock(async () => {
101
+ const data = await this.loadInternal(action.key);
102
+
103
+ if (transactionResult.shouldUpdate) {
104
+ data[chatId] = transactionResult.data;
105
+ await this.save(data, action.key);
106
+ }
107
+ });
108
+ }
109
+ }
110
+
111
+ export default new Storage();
@@ -0,0 +1,66 @@
1
+ import TaskRecord from '../entities/taskRecord';
2
+ import { secondsToMilliseconds } from '../helpers/timeConvertions';
3
+ import { Milliseconds, Seconds } from '../types/timeValues';
4
+ import logger from './logger';
5
+
6
+ class TaskScheduler {
7
+ activeTasks: TaskRecord[] = [];
8
+
9
+ stopAll() {
10
+ this.activeTasks.forEach((task) => {
11
+ clearInterval(task.taskId);
12
+ });
13
+ }
14
+
15
+ createTask(
16
+ name: string,
17
+ action: () => void,
18
+ interval: Milliseconds,
19
+ executeRightAway: boolean,
20
+ ownerName: string
21
+ ) {
22
+ executeRightAway = executeRightAway ?? false;
23
+ const taskId = setInterval(action, interval);
24
+ const task = new TaskRecord(name, taskId, interval);
25
+
26
+ if (executeRightAway) {
27
+ setTimeout(action, secondsToMilliseconds(1 as Seconds));
28
+ }
29
+
30
+ logger.logWithTraceId(
31
+ ownerName,
32
+ `System:TaskScheduler-${ownerName}-${name}`,
33
+ 'System',
34
+ `Created task [${taskId}]${name}, that will run every ${interval}ms.`
35
+ );
36
+
37
+ this.activeTasks.push(task);
38
+ }
39
+
40
+ createOnetimeTask(
41
+ name: string,
42
+ action: () => void,
43
+ delay: Milliseconds,
44
+ ownerName: string
45
+ ) {
46
+ const actionWrapper = () => {
47
+ logger.logWithTraceId(
48
+ ownerName,
49
+ `System:TaskScheduler-${ownerName}-${name}`,
50
+ 'System',
51
+ `Executing delayed oneshot [${taskId}]${name}`
52
+ );
53
+ action();
54
+ };
55
+ const taskId = setTimeout(actionWrapper, delay);
56
+
57
+ logger.logWithTraceId(
58
+ ownerName,
59
+ `System:TaskScheduler-${ownerName}-${name}`,
60
+ 'System',
61
+ `Created oneshot task [${taskId}]${name}, that will run in ${delay}ms.`
62
+ );
63
+ }
64
+ }
65
+
66
+ export default new TaskScheduler();
@@ -0,0 +1,172 @@
1
+ import MessageContext from '../entities/context/messageContext';
2
+ import ChatContext from '../entities/context/chatContext';
3
+ import ImageMessage from '../entities/responses/imageMessage';
4
+ import TextMessage from '../entities/responses/textMessage';
5
+ import VideoMessage from '../entities/responses/videoMessage';
6
+ import taskScheduler from './taskScheduler';
7
+ import logger from './logger';
8
+ import { Telegraf } from 'telegraf';
9
+ import IReplyMessage from '../types/replyMessage';
10
+ import IncomingMessage from '../entities/incomingMessage';
11
+ import { Milliseconds } from '../types/timeValues';
12
+ import Reaction from '../entities/responses/reaction';
13
+ import { InputFile } from 'telegraf/types';
14
+ import { reverseMap } from '../helpers/reverseMap';
15
+
16
+ export default class TelegramApiService {
17
+ botName: string;
18
+ telegraf: Telegraf;
19
+ chats: Map<number, string>;
20
+ messageQueue: Array<IReplyMessage<unknown> | Reaction> = [];
21
+
22
+ constructor(
23
+ botName: string,
24
+ telegraf: Telegraf,
25
+ chats: Map<string, number>
26
+ ) {
27
+ this.telegraf = telegraf;
28
+ this.botName = botName;
29
+ this.chats = reverseMap(chats);
30
+
31
+ taskScheduler.createTask(
32
+ 'MessageSending',
33
+ () => {
34
+ this.dequeueResponse();
35
+ },
36
+ 100 as Milliseconds,
37
+ false,
38
+ this.botName
39
+ );
40
+ }
41
+
42
+ private async dequeueResponse() {
43
+ const message = this.messageQueue.pop();
44
+
45
+ if (!message) return;
46
+
47
+ try {
48
+ await this.processResponse(message);
49
+ } catch (error) {
50
+ logger.errorWithTraceId(
51
+ this.botName,
52
+ message.traceId,
53
+ this.chats.get(message.chatId)!,
54
+ error as string | Error,
55
+ message
56
+ );
57
+ }
58
+ }
59
+
60
+ private async processResponse<TType>(
61
+ response: IReplyMessage<TType> | Reaction
62
+ ) {
63
+ if ('emoji' in response) {
64
+ this.telegraf.telegram.setMessageReaction(
65
+ response.chatId,
66
+ response.messageId,
67
+ [
68
+ {
69
+ type: 'emoji',
70
+ emoji: response.emoji
71
+ }
72
+ ],
73
+ true
74
+ );
75
+
76
+ return;
77
+ }
78
+
79
+ switch (response.constructor) {
80
+ case TextMessage:
81
+ await this.telegraf.telegram.sendMessage(
82
+ response.chatId,
83
+ response.content as string,
84
+ {
85
+ reply_to_message_id: response.replyId,
86
+ parse_mode: 'MarkdownV2',
87
+ disable_web_page_preview: true
88
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
89
+ } as any
90
+ );
91
+ break;
92
+ case ImageMessage:
93
+ await this.telegraf.telegram.sendPhoto(
94
+ response.chatId,
95
+ response.content as InputFile,
96
+ response.replyId
97
+ ? // eslint-disable-next-line @typescript-eslint/no-explicit-any
98
+ ({ reply_to_message_id: response.replyId } as any)
99
+ : undefined
100
+ );
101
+ break;
102
+ case VideoMessage:
103
+ await this.telegraf.telegram.sendVideo(
104
+ response.chatId,
105
+ response.content as InputFile,
106
+ response.replyId
107
+ ? // eslint-disable-next-line @typescript-eslint/no-explicit-any
108
+ ({ reply_to_message_id: response.replyId } as any)
109
+ : undefined
110
+ );
111
+ break;
112
+ default:
113
+ logger.errorWithTraceId(
114
+ this.botName,
115
+ response.traceId,
116
+ this.chats.get(response.chatId)!,
117
+ `Unknown message type: ${response.constructor}`,
118
+ response
119
+ );
120
+ break;
121
+ }
122
+ }
123
+
124
+ private enqueueResponse<TType>(response: IReplyMessage<TType>) {
125
+ this.messageQueue.push(response);
126
+ }
127
+
128
+ private enqueueReaction(reaction: Reaction) {
129
+ this.messageQueue.push(reaction);
130
+ }
131
+
132
+ private getInteractions() {
133
+ return {
134
+ react: (reaction) => this.enqueueReaction(reaction),
135
+ respond: (response) => this.enqueueResponse(response)
136
+ } as IBotApiInteractions;
137
+ }
138
+
139
+ createContextForMessage(incomingMessage: IncomingMessage) {
140
+ const firstName = incomingMessage.from?.first_name ?? 'Unknown user';
141
+ const lastName = incomingMessage.from?.last_name
142
+ ? ` ${incomingMessage.from?.last_name}`
143
+ : '';
144
+
145
+ return new MessageContext(
146
+ this.botName,
147
+ this.getInteractions(),
148
+ incomingMessage.chat.id,
149
+ incomingMessage.chatName,
150
+ incomingMessage.message_id,
151
+ incomingMessage.text,
152
+ incomingMessage.from?.id,
153
+ incomingMessage.traceId,
154
+ firstName + lastName
155
+ );
156
+ }
157
+
158
+ createContextForChat(chatId: number, scheduledName: string) {
159
+ return new ChatContext(
160
+ this.botName,
161
+ this.getInteractions(),
162
+ chatId,
163
+ this.chats.get(chatId)!,
164
+ `Scheduled:${scheduledName}:${chatId}`
165
+ );
166
+ }
167
+ }
168
+
169
+ export interface IBotApiInteractions {
170
+ respond: <TType>(response: IReplyMessage<TType>) => void;
171
+ react: (reaction: Reaction) => void;
172
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,110 @@
1
+ {
2
+ "compilerOptions": {
3
+ /* Visit https://aka.ms/tsconfig to read more about this file */
4
+
5
+ /* Projects */
6
+ // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
7
+ // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
8
+ // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
9
+ // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
10
+ // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
11
+ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
12
+
13
+ /* Language and Environment */
14
+ "target": "es2020", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
15
+ "lib": ["es2021", "DOM", "ES6" ,"DOM.Iterable", "ScriptHost"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
16
+ // "jsx": "preserve", /* Specify what JSX code is generated. */
17
+ // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
18
+ // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
19
+ // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
20
+ // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
21
+ // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
22
+ // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
23
+ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
24
+ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
25
+ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
26
+
27
+ /* Modules */
28
+ "module": "commonjs", /* Specify what module code is generated. */
29
+ // "rootDir": "./", /* Specify the root folder within your source files. */
30
+ // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
31
+ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
32
+ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
33
+ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
34
+ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
35
+ // "types": [], /* Specify type package names to be included without being referenced in a source file. */
36
+ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
37
+ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
38
+ // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
39
+ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
40
+ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
41
+ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
42
+ // "noUncheckedSideEffectImports": true, /* Check side effect imports. */
43
+ // "resolveJsonModule": true, /* Enable importing .json files. */
44
+ // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
45
+ // "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
46
+
47
+ /* JavaScript Support */
48
+ // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
49
+ // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
50
+ // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
51
+
52
+ /* Emit */
53
+ // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
54
+ // "declarationMap": true, /* Create sourcemaps for d.ts files. */
55
+ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
56
+ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
57
+ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
58
+ // "noEmit": true, /* Disable emitting files from a compilation. */
59
+ // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
60
+ "outDir": "./dist", /* Specify an output folder for all emitted files. */
61
+ // "removeComments": true, /* Disable emitting comments. */
62
+ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
63
+ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
64
+ // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
65
+ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
66
+ // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
67
+ // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
68
+ // "newLine": "crlf", /* Set the newline character for emitting files. */
69
+ // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
70
+ // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
71
+ // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
72
+ // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
73
+ // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
74
+
75
+ /* Interop Constraints */
76
+ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
77
+ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
78
+ // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */
79
+ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
80
+ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
81
+ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
82
+ "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
83
+
84
+ /* Type Checking */
85
+ "strict": true, /* Enable all strict type-checking options. */
86
+ // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
87
+ // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
88
+ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
89
+ // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
90
+ // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
91
+ // "strictBuiltinIteratorReturn": true, /* Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'. */
92
+ // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
93
+ // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
94
+ // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
95
+ // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
96
+ // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
97
+ // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
98
+ // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
99
+ // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
100
+ // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
101
+ // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
102
+ // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
103
+ // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
104
+ // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
105
+
106
+ /* Completeness */
107
+ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
108
+ "skipLibCheck": true /* Skip type checking all .d.ts files. */
109
+ }
110
+ }
@@ -0,0 +1,3 @@
1
+ export default interface IActionState {
2
+ lastExecutedDate: number;
3
+ }
@@ -0,0 +1,6 @@
1
+ import IActionState from './actionState';
2
+
3
+ export default interface IActionWithState {
4
+ key: string;
5
+ stateConstructor: () => IActionState;
6
+ }
@@ -0,0 +1 @@
1
+ export type CachedValueAccessor = <TResult>(key: string) => Promise<TResult>;
@@ -0,0 +1,6 @@
1
+ import MessageContext from '../entities/context/messageContext';
2
+ import IActionState from './actionState';
3
+
4
+ export type CommandCondition<TActionState extends IActionState> = (
5
+ ctx: MessageContext<TActionState>
6
+ ) => Promise<boolean>;
@@ -0,0 +1,9 @@
1
+ export enum Day {
2
+ Sunday = 0,
3
+ Monday = 1,
4
+ Tuesday = 2,
5
+ Wednesday = 3,
6
+ Thursday = 4,
7
+ Friday = 5,
8
+ Saturday = 6
9
+ }