chz-telegram-bot 0.5.0 → 0.5.2
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.
- package/dist/builtin/helpAction.js +3 -6
- package/dist/dtos/chatHistoryMessage.js +1 -5
- package/dist/dtos/chatInfo.js +1 -5
- package/dist/dtos/commandTriggerCheckResult.js +1 -5
- package/dist/dtos/cooldownInfo.js +1 -5
- package/dist/dtos/incomingMessage.js +21 -25
- package/dist/dtos/incomingQuery.js +1 -5
- package/dist/dtos/messageInfo.js +1 -5
- package/dist/dtos/propertyProviderSets.js +1 -2
- package/dist/dtos/replyInfo.js +1 -5
- package/dist/dtos/responses/delay.js +3 -7
- package/dist/dtos/responses/imageMessage.js +3 -7
- package/dist/dtos/responses/inlineQueryResponse.js +3 -7
- package/dist/dtos/responses/reaction.js +3 -7
- package/dist/dtos/responses/textMessage.d.ts +2 -0
- package/dist/dtos/responses/textMessage.d.ts.map +1 -1
- package/dist/dtos/responses/textMessage.js +5 -7
- package/dist/dtos/responses/unpin.js +3 -7
- package/dist/dtos/responses/videoMessage.js +3 -7
- package/dist/dtos/userInfo.js +1 -5
- package/dist/entities/actions/commandAction.js +32 -39
- package/dist/entities/actions/inlineQueryAction.js +4 -8
- package/dist/entities/actions/replyCaptureAction.js +10 -14
- package/dist/entities/actions/scheduledAction.js +16 -23
- package/dist/entities/botInstance.js +13 -17
- package/dist/entities/cachedStateFactory.js +1 -5
- package/dist/entities/context/baseContext.d.ts +1 -1
- package/dist/entities/context/baseContext.d.ts.map +1 -1
- package/dist/entities/context/baseContext.js +1 -5
- package/dist/entities/context/chatContext.js +13 -17
- package/dist/entities/context/inlineQueryContext.js +4 -8
- package/dist/entities/context/messageContext.js +15 -19
- package/dist/entities/context/replyContext.js +15 -19
- package/dist/entities/states/actionStateBase.js +1 -5
- package/dist/entities/taskRecord.js +1 -5
- package/dist/eslint.config.d.ts +3 -0
- package/dist/eslint.config.d.ts.map +1 -0
- package/dist/eslint.config.js +51 -0
- package/dist/helpers/builders/commandActionBuilder.js +15 -20
- package/dist/helpers/builders/inlineQueryActionBuilder.js +5 -9
- package/dist/helpers/builders/scheduledActionBuilder.js +10 -15
- package/dist/helpers/mapUtils.js +2 -6
- package/dist/helpers/noop.js +1 -5
- package/dist/helpers/objectFromEntries.js +1 -5
- package/dist/helpers/timeConvertions.js +3 -8
- package/dist/helpers/toArray.js +1 -4
- package/dist/helpers/traceFactory.js +1 -4
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -41
- package/dist/main.js +5 -8
- package/dist/services/actionProcessingService.js +15 -19
- package/dist/services/actionProcessors/baseProcessor.js +1 -5
- package/dist/services/actionProcessors/commandActionProcessor.d.ts.map +1 -1
- package/dist/services/actionProcessors/commandActionProcessor.js +35 -38
- package/dist/services/actionProcessors/inlineQueryActionProcessor.js +7 -11
- package/dist/services/actionProcessors/scheduledActionProcessor.js +12 -19
- package/dist/services/jsonFileStorage.js +15 -19
- package/dist/services/jsonLogger.js +1 -5
- package/dist/services/nodeTimeoutScheduler.js +9 -13
- package/dist/services/responseProcessingQueue.js +3 -7
- package/dist/services/telegramApi.d.ts +1 -0
- package/dist/services/telegramApi.d.ts.map +1 -1
- package/dist/services/telegramApi.js +27 -27
- package/dist/types/action.js +1 -2
- package/dist/types/actionState.js +1 -2
- package/dist/types/cachedValueAccessor.js +1 -2
- package/dist/types/capture.js +1 -2
- package/dist/types/commandCondition.js +1 -2
- package/dist/types/commandTrigger.js +1 -2
- package/dist/types/externalAliases.d.ts +3 -3
- package/dist/types/externalAliases.d.ts.map +1 -1
- package/dist/types/externalAliases.js +1 -2
- package/dist/types/handlers.js +1 -2
- package/dist/types/inputFile.js +1 -2
- package/dist/types/logger.js +1 -2
- package/dist/types/messageSendingOptions.d.ts +2 -0
- package/dist/types/messageSendingOptions.d.ts.map +1 -1
- package/dist/types/messageSendingOptions.js +1 -2
- package/dist/types/messageTypes.js +17 -20
- package/dist/types/propertyProvider.js +1 -2
- package/dist/types/response.js +1 -4
- package/dist/types/scheduler.js +1 -2
- package/dist/types/storage.js +1 -2
- package/dist/types/timeValues.js +1 -2
- package/dist/types/trace.js +1 -2
- package/dtos/responses/textMessage.ts +3 -0
- package/entities/botInstance.ts +1 -1
- package/entities/context/messageContext.ts +3 -3
- package/entities/context/replyContext.ts +3 -3
- package/{eslint.config.js → eslint.config.ts} +9 -5
- package/index.ts +3 -0
- package/package.json +2 -1
- package/services/actionProcessors/commandActionProcessor.ts +5 -6
- package/services/jsonFileStorage.ts +1 -1
- package/services/nodeTimeoutScheduler.ts +2 -2
- package/services/telegramApi.ts +34 -25
- package/tsconfig.json +2 -2
- package/types/externalAliases.ts +5 -4
- package/types/messageSendingOptions.ts +3 -0
- package/bun.lock +0 -301
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const moment_1 = __importDefault(require("moment"));
|
|
8
|
-
const async_sema_1 = require("async-sema");
|
|
9
|
-
const timeConvertions_1 = require("../../helpers/timeConvertions");
|
|
10
|
-
const noop_1 = require("../../helpers/noop");
|
|
11
|
-
const mapUtils_1 = require("../../helpers/mapUtils");
|
|
12
|
-
class ScheduledAction {
|
|
1
|
+
import moment from 'moment';
|
|
2
|
+
import { Sema as Semaphore } from 'async-sema';
|
|
3
|
+
import { hoursToMilliseconds } from '../../helpers/timeConvertions';
|
|
4
|
+
import { Noop } from '../../helpers/noop';
|
|
5
|
+
import { getOrSetIfNotExists, getOrThrow } from '../../helpers/mapUtils';
|
|
6
|
+
export class ScheduledAction {
|
|
13
7
|
static locks = new Map();
|
|
14
8
|
name;
|
|
15
9
|
key;
|
|
@@ -35,21 +29,21 @@ class ScheduledAction {
|
|
|
35
29
|
throw new Error(`Context for ${this.key} is not initialized or already consumed`);
|
|
36
30
|
if (!this.activeProvider(ctx) ||
|
|
37
31
|
!this.chatsWhitelistProvider(ctx).includes(ctx.chatInfo.id))
|
|
38
|
-
return
|
|
32
|
+
return Noop.NoResponse;
|
|
39
33
|
const state = await ctx.storage.getActionState(this, ctx.chatInfo.id);
|
|
40
34
|
const isAllowedToTrigger = this.checkIfShouldBeExecuted(state, ctx);
|
|
41
35
|
if (!isAllowedToTrigger)
|
|
42
|
-
return
|
|
36
|
+
return Noop.NoResponse;
|
|
43
37
|
ctx.logger.logWithTraceId(` - Executing [${this.name}] in ${ctx.chatInfo.id}`);
|
|
44
38
|
await this.handler(ctx, (key) => this.getCachedValue(key, ctx.botName, ctx.scheduler), state);
|
|
45
|
-
state.lastExecutedDate = (
|
|
39
|
+
state.lastExecutedDate = moment().valueOf();
|
|
46
40
|
await ctx.storage.saveActionExecutionResult(this, ctx.chatInfo.id, state);
|
|
47
41
|
return ctx.responses;
|
|
48
42
|
}
|
|
49
43
|
async getCachedValue(key, botName, scheduler) {
|
|
50
|
-
const cachedItemFactory =
|
|
44
|
+
const cachedItemFactory = getOrThrow(this.cachedStateFactories, key, `No shared cache was set up for the key [${key}] in action '${this.name}'`);
|
|
51
45
|
const semaphoreKey = `${this.key}_cached:${key}`;
|
|
52
|
-
const semaphore =
|
|
46
|
+
const semaphore = getOrSetIfNotExists(ScheduledAction.locks, semaphoreKey, new Semaphore(1));
|
|
53
47
|
await semaphore.acquire();
|
|
54
48
|
try {
|
|
55
49
|
if (this.cachedState.has(key)) {
|
|
@@ -57,7 +51,7 @@ class ScheduledAction {
|
|
|
57
51
|
}
|
|
58
52
|
const value = await cachedItemFactory.getValue();
|
|
59
53
|
this.cachedState.set(key, value);
|
|
60
|
-
scheduler.createOnetimeTask(`Drop cached value [${this.name} : ${key}]`, () => this.cachedState.delete(key),
|
|
54
|
+
scheduler.createOnetimeTask(`Drop cached value [${this.name} : ${key}]`, () => this.cachedState.delete(key), hoursToMilliseconds(cachedItemFactory.invalidationTimeoutInHours), botName);
|
|
61
55
|
return value;
|
|
62
56
|
}
|
|
63
57
|
finally {
|
|
@@ -65,10 +59,10 @@ class ScheduledAction {
|
|
|
65
59
|
}
|
|
66
60
|
}
|
|
67
61
|
checkIfShouldBeExecuted(state, ctx) {
|
|
68
|
-
const startOfToday = (
|
|
69
|
-
const lastExecutedDate = (
|
|
70
|
-
const currentTime = (
|
|
71
|
-
const scheduledTime = (
|
|
62
|
+
const startOfToday = moment().startOf('day').valueOf();
|
|
63
|
+
const lastExecutedDate = moment(state.lastExecutedDate);
|
|
64
|
+
const currentTime = moment();
|
|
65
|
+
const scheduledTime = moment()
|
|
72
66
|
.startOf('day')
|
|
73
67
|
.add(this.timeinHoursProvider(ctx), 'hours');
|
|
74
68
|
const isAllowedToTrigger = currentTime.isSameOrAfter(scheduledTime);
|
|
@@ -76,4 +70,3 @@ class ScheduledAction {
|
|
|
76
70
|
return isAllowedToTrigger && !hasTriggeredToday;
|
|
77
71
|
}
|
|
78
72
|
}
|
|
79
|
-
exports.ScheduledAction = ScheduledAction;
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const traceFactory_1 = require("../helpers/traceFactory");
|
|
8
|
-
const actionProcessingService_1 = require("../services/actionProcessingService");
|
|
9
|
-
class BotInstance {
|
|
1
|
+
import { JsonFileStorage } from '../services/jsonFileStorage';
|
|
2
|
+
import { JsonLogger } from '../services/jsonLogger';
|
|
3
|
+
import { NodeTimeoutScheduler } from '../services/nodeTimeoutScheduler';
|
|
4
|
+
import { createTrace } from '../helpers/traceFactory';
|
|
5
|
+
import { ActionProcessingService } from '../services/actionProcessingService';
|
|
6
|
+
export class BotInstance {
|
|
10
7
|
storage;
|
|
11
8
|
scheduler;
|
|
12
9
|
logger;
|
|
@@ -18,24 +15,23 @@ class BotInstance {
|
|
|
18
15
|
...options.actions.scheduled
|
|
19
16
|
];
|
|
20
17
|
this.name = options.name;
|
|
21
|
-
this.logger = options.services?.logger ?? new
|
|
18
|
+
this.logger = options.services?.logger ?? new JsonLogger();
|
|
22
19
|
this.scheduler =
|
|
23
20
|
options.services?.scheduler ??
|
|
24
|
-
new
|
|
21
|
+
new NodeTimeoutScheduler(this.logger);
|
|
25
22
|
this.storage =
|
|
26
23
|
options.services?.storageClient ??
|
|
27
|
-
new
|
|
28
|
-
this.actionProcessingService = new
|
|
24
|
+
new JsonFileStorage(options.name, actions, options.storagePath);
|
|
25
|
+
this.actionProcessingService = new ActionProcessingService(this.name, options.chats, this.storage, this.scheduler, this.logger);
|
|
29
26
|
}
|
|
30
27
|
async start(token, actions, scheduledPeriod, verboseLoggingForIncomingMessage) {
|
|
31
|
-
this.logger.logWithTraceId(this.name,
|
|
28
|
+
this.logger.logWithTraceId(this.name, createTrace(this, this.name, 'Start'), 'System', 'Starting bot...');
|
|
32
29
|
await this.actionProcessingService.initialize(token, actions, scheduledPeriod, verboseLoggingForIncomingMessage);
|
|
33
30
|
}
|
|
34
31
|
async stop() {
|
|
35
|
-
this.logger.logWithTraceId(this.name,
|
|
32
|
+
this.logger.logWithTraceId(this.name, createTrace(this, this.name, 'Stop'), 'System', 'Stopping bot...');
|
|
36
33
|
this.scheduler.stopAll();
|
|
37
34
|
await this.storage.close();
|
|
38
|
-
|
|
35
|
+
this.actionProcessingService.stop();
|
|
39
36
|
}
|
|
40
37
|
}
|
|
41
|
-
exports.BotInstance = BotInstance;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CachedStateFactory = void 0;
|
|
4
|
-
class CachedStateFactory {
|
|
1
|
+
export class CachedStateFactory {
|
|
5
2
|
getValue;
|
|
6
3
|
invalidationTimeoutInHours;
|
|
7
4
|
constructor(itemFactory, invalidationTimeout) {
|
|
@@ -9,4 +6,3 @@ class CachedStateFactory {
|
|
|
9
6
|
this.invalidationTimeoutInHours = invalidationTimeout;
|
|
10
7
|
}
|
|
11
8
|
}
|
|
12
|
-
exports.CachedStateFactory = CachedStateFactory;
|
|
@@ -23,7 +23,7 @@ export declare abstract class BaseContextInternal<TAction extends IAction> {
|
|
|
23
23
|
botName: string;
|
|
24
24
|
/** Chat information. */
|
|
25
25
|
chatInfo: ChatInfo;
|
|
26
|
-
get actionKey(): import("
|
|
26
|
+
get actionKey(): import("../..").ActionKey;
|
|
27
27
|
/** Ordered collection of responses to be processed */
|
|
28
28
|
get responses(): BotResponse[];
|
|
29
29
|
set responses(value: BotResponse[]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baseContext.d.ts","sourceRoot":"","sources":["../../../entities/context/baseContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAG5C,MAAM,MAAM,2BAA2B,GACjC,QAAQ,GACR,eAAe,GACf,SAAS,GACT,WAAW,GACX,QAAQ,GACR,WAAW,GACX,SAAS,CAAC;AAEhB,8BAAsB,mBAAmB,CAAC,OAAO,SAAS,OAAO;IAC7D,aAAa,UAAS;IACtB,OAAO,CAAC,UAAU,CAAqB;IAEvC,MAAM,EAAG,OAAO,CAAC;IAEjB,iEAAiE;IACjE,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IACjC,2DAA2D;IAC3D,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC;IAC/B,MAAM,EAAG,aAAa,CAAC;IACvB,sCAAsC;IACtC,OAAO,EAAG,OAAO,CAAC;IAClB,+CAA+C;IAC/C,OAAO,EAAG,MAAM,CAAC;IACjB,wBAAwB;IACxB,QAAQ,EAAG,QAAQ,CAAC;IACpB,IAAI,SAAS,
|
|
1
|
+
{"version":3,"file":"baseContext.d.ts","sourceRoot":"","sources":["../../../entities/context/baseContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAG5C,MAAM,MAAM,2BAA2B,GACjC,QAAQ,GACR,eAAe,GACf,SAAS,GACT,WAAW,GACX,QAAQ,GACR,WAAW,GACX,SAAS,CAAC;AAEhB,8BAAsB,mBAAmB,CAAC,OAAO,SAAS,OAAO;IAC7D,aAAa,UAAS;IACtB,OAAO,CAAC,UAAU,CAAqB;IAEvC,MAAM,EAAG,OAAO,CAAC;IAEjB,iEAAiE;IACjE,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IACjC,2DAA2D;IAC3D,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC;IAC/B,MAAM,EAAG,aAAa,CAAC;IACvB,sCAAsC;IACtC,OAAO,EAAG,OAAO,CAAC;IAClB,+CAA+C;IAC/C,OAAO,EAAG,MAAM,CAAC;IACjB,wBAAwB;IACxB,QAAQ,EAAG,QAAQ,CAAC;IACpB,IAAI,SAAS,8BAEZ;IAED,uDAAuD;IACvD,IAAW,SAAS,IAAI,WAAW,EAAE,CAEpC;IACD,IAAW,SAAS,CAAC,KAAK,EAAE,WAAW,EAAE,EAExC;gBAEW,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU;IAK1D,SAAS,CAAC,uBAAuB,CAC7B,QAAQ,EAAE,cAAc,GACzB,kBAAkB;IAmBrB;;;;OAIG;IACG,WAAW,CAAC,mBAAmB,SAAS,YAAY,EACtD,MAAM,EAAE,gBAAgB,CAAC,mBAAmB,CAAC;CAWpD"}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseContextInternal = void 0;
|
|
4
|
-
class BaseContextInternal {
|
|
1
|
+
export class BaseContextInternal {
|
|
5
2
|
isInitialized = false;
|
|
6
3
|
_responses = [];
|
|
7
4
|
action;
|
|
@@ -56,4 +53,3 @@ class BaseContextInternal {
|
|
|
56
53
|
return Object.freeze(stateForChat);
|
|
57
54
|
}
|
|
58
55
|
}
|
|
59
|
-
exports.BaseContextInternal = BaseContextInternal;
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const unpin_1 = require("../../dtos/responses/unpin");
|
|
9
|
-
const delay_1 = require("../../dtos/responses/delay");
|
|
10
|
-
const baseContext_1 = require("./baseContext");
|
|
1
|
+
import { resolve } from 'path';
|
|
2
|
+
import { ImageMessage } from '../../dtos/responses/imageMessage';
|
|
3
|
+
import { TextMessage } from '../../dtos/responses/textMessage';
|
|
4
|
+
import { VideoMessage } from '../../dtos/responses/videoMessage';
|
|
5
|
+
import { UnpinResponse } from '../../dtos/responses/unpin';
|
|
6
|
+
import { DelayResponse } from '../../dtos/responses/delay';
|
|
7
|
+
import { BaseContextInternal } from './baseContext';
|
|
11
8
|
/**
|
|
12
9
|
* Context of action executed in chat.
|
|
13
10
|
*/
|
|
14
|
-
class ChatContextInternal extends
|
|
11
|
+
export class ChatContextInternal extends BaseContextInternal {
|
|
15
12
|
/**
|
|
16
13
|
* Collection of actions that send something to chat as a standalone message.
|
|
17
14
|
*/
|
|
@@ -23,7 +20,7 @@ class ChatContextInternal extends baseContext_1.BaseContextInternal {
|
|
|
23
20
|
* @param options Message sending option.
|
|
24
21
|
*/
|
|
25
22
|
text: (text, options) => {
|
|
26
|
-
const response = new
|
|
23
|
+
const response = new TextMessage(text, this.chatInfo, this.traceId, this.action, undefined, options);
|
|
27
24
|
this.responses.push(response);
|
|
28
25
|
return this.createCaptureController(response);
|
|
29
26
|
},
|
|
@@ -34,7 +31,7 @@ class ChatContextInternal extends baseContext_1.BaseContextInternal {
|
|
|
34
31
|
* @param options Message sending option.
|
|
35
32
|
*/
|
|
36
33
|
image: (name, options) => {
|
|
37
|
-
const response = new
|
|
34
|
+
const response = new ImageMessage({ source: resolve(`./content/${name}.png`) }, this.chatInfo, this.traceId, this.action, undefined, options);
|
|
38
35
|
this.responses.push(response);
|
|
39
36
|
return this.createCaptureController(response);
|
|
40
37
|
},
|
|
@@ -45,7 +42,7 @@ class ChatContextInternal extends baseContext_1.BaseContextInternal {
|
|
|
45
42
|
* @param options Message sending option.
|
|
46
43
|
*/
|
|
47
44
|
video: (name, options) => {
|
|
48
|
-
const response = new
|
|
45
|
+
const response = new VideoMessage({ source: resolve(`./content/${name}.mp4`) }, this.chatInfo, this.traceId, this.action, undefined, options);
|
|
49
46
|
this.responses.push(response);
|
|
50
47
|
return this.createCaptureController(response);
|
|
51
48
|
}
|
|
@@ -56,14 +53,13 @@ class ChatContextInternal extends baseContext_1.BaseContextInternal {
|
|
|
56
53
|
* @param messageId Message id.
|
|
57
54
|
*/
|
|
58
55
|
unpinMessage(messageId) {
|
|
59
|
-
this.responses.push(new
|
|
56
|
+
this.responses.push(new UnpinResponse(messageId, this.chatInfo, this.traceId, this.action));
|
|
60
57
|
}
|
|
61
58
|
/**
|
|
62
59
|
* Delays next responses by specified amount of time.
|
|
63
60
|
* @param delay Delay in milliseconds.
|
|
64
61
|
*/
|
|
65
62
|
wait(delay) {
|
|
66
|
-
this.responses.push(new
|
|
63
|
+
this.responses.push(new DelayResponse(delay, this.chatInfo, this.traceId, this.action));
|
|
67
64
|
}
|
|
68
65
|
}
|
|
69
|
-
exports.ChatContextInternal = ChatContextInternal;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const inlineQueryResponse_1 = require("../../dtos/responses/inlineQueryResponse");
|
|
5
|
-
const baseContext_1 = require("./baseContext");
|
|
6
|
-
class InlineQueryContextInternal extends baseContext_1.BaseContextInternal {
|
|
1
|
+
import { InlineQueryResponse } from '../../dtos/responses/inlineQueryResponse';
|
|
2
|
+
import { BaseContextInternal } from './baseContext';
|
|
3
|
+
export class InlineQueryContextInternal extends BaseContextInternal {
|
|
7
4
|
queryResults = [];
|
|
8
5
|
/**
|
|
9
6
|
* Abort signal to be utilized in query handler.
|
|
@@ -13,7 +10,7 @@ class InlineQueryContextInternal extends baseContext_1.BaseContextInternal {
|
|
|
13
10
|
/** Ordered collection of responses to be processed */
|
|
14
11
|
get responses() {
|
|
15
12
|
return [
|
|
16
|
-
new
|
|
13
|
+
new InlineQueryResponse(this.queryResults, this.queryId, this.traceId, this.action)
|
|
17
14
|
];
|
|
18
15
|
}
|
|
19
16
|
/** Inline query text */
|
|
@@ -30,4 +27,3 @@ class InlineQueryContextInternal extends baseContext_1.BaseContextInternal {
|
|
|
30
27
|
this.queryResults.push(queryResult);
|
|
31
28
|
}
|
|
32
29
|
}
|
|
33
|
-
exports.InlineQueryContextInternal = InlineQueryContextInternal;
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const videoMessage_1 = require("../../dtos/responses/videoMessage");
|
|
9
|
-
const chatContext_1 = require("./chatContext");
|
|
10
|
-
const replyInfo_1 = require("../../dtos/replyInfo");
|
|
1
|
+
import { resolve } from 'path';
|
|
2
|
+
import { ImageMessage } from '../../dtos/responses/imageMessage';
|
|
3
|
+
import { Reaction } from '../../dtos/responses/reaction';
|
|
4
|
+
import { TextMessage } from '../../dtos/responses/textMessage';
|
|
5
|
+
import { VideoMessage } from '../../dtos/responses/videoMessage';
|
|
6
|
+
import { ChatContextInternal } from './chatContext';
|
|
7
|
+
import { ReplyInfo } from '../../dtos/replyInfo';
|
|
11
8
|
/**
|
|
12
9
|
* Context of action executed in chat, in response to a message
|
|
13
10
|
*/
|
|
14
|
-
class MessageContextInternal extends
|
|
11
|
+
export class MessageContextInternal extends ChatContextInternal {
|
|
15
12
|
/** Information about the user that triggered this action */
|
|
16
13
|
userInfo;
|
|
17
14
|
/** Information about the message that triggered this action */
|
|
@@ -26,25 +23,25 @@ class MessageContextInternal extends chatContext_1.ChatContextInternal {
|
|
|
26
23
|
getQuotePart(quote) {
|
|
27
24
|
if (typeof quote != 'boolean')
|
|
28
25
|
return quote;
|
|
29
|
-
return this.matchResults.length
|
|
30
|
-
? this.
|
|
31
|
-
: this.
|
|
26
|
+
return this.matchResults.length == 0
|
|
27
|
+
? this.messageInfo.text
|
|
28
|
+
: this.matchResults[0][1];
|
|
32
29
|
}
|
|
33
30
|
replyWithText(text, quote, options) {
|
|
34
31
|
const quotedPart = this.getQuotePart(quote);
|
|
35
|
-
const response = new
|
|
32
|
+
const response = new TextMessage(text, this.chatInfo, this.traceId, this.action, new ReplyInfo(this.messageInfo.id, quote ? quotedPart : undefined), options);
|
|
36
33
|
this.responses.push(response);
|
|
37
34
|
return this.createCaptureController(response);
|
|
38
35
|
}
|
|
39
36
|
replyWithImage(name, quote, options) {
|
|
40
37
|
const quotedPart = this.getQuotePart(quote);
|
|
41
|
-
const response = new
|
|
38
|
+
const response = new ImageMessage({ source: resolve(`./content/${name}.png`) }, this.chatInfo, this.traceId, this.action, new ReplyInfo(this.messageInfo.id, quote ? quotedPart : undefined), options);
|
|
42
39
|
this.responses.push(response);
|
|
43
40
|
return this.createCaptureController(response);
|
|
44
41
|
}
|
|
45
42
|
replyWithVideo(name, quote, options) {
|
|
46
43
|
const quotedPart = this.getQuotePart(quote);
|
|
47
|
-
const response = new
|
|
44
|
+
const response = new VideoMessage({ source: resolve(`./content/${name}.mp4`) }, this.chatInfo, this.traceId, this.action, new ReplyInfo(this.messageInfo.id, quote ? quotedPart : undefined), options);
|
|
48
45
|
this.responses.push(response);
|
|
49
46
|
return this.createCaptureController(response);
|
|
50
47
|
}
|
|
@@ -113,8 +110,7 @@ class MessageContextInternal extends chatContext_1.ChatContextInternal {
|
|
|
113
110
|
* @param emoji Telegram emoji to react with.
|
|
114
111
|
*/
|
|
115
112
|
withReaction: (emoji) => {
|
|
116
|
-
this.responses.push(new
|
|
113
|
+
this.responses.push(new Reaction(this.traceId, this.chatInfo, this.messageInfo.id, emoji, this.action));
|
|
117
114
|
}
|
|
118
115
|
};
|
|
119
116
|
}
|
|
120
|
-
exports.MessageContextInternal = MessageContextInternal;
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const path_1 = require("path");
|
|
10
|
-
const baseContext_1 = require("./baseContext");
|
|
11
|
-
class ReplyContextInternal extends baseContext_1.BaseContextInternal {
|
|
1
|
+
import { ReplyInfo } from '../../dtos/replyInfo';
|
|
2
|
+
import { ImageMessage } from '../../dtos/responses/imageMessage';
|
|
3
|
+
import { Reaction } from '../../dtos/responses/reaction';
|
|
4
|
+
import { TextMessage } from '../../dtos/responses/textMessage';
|
|
5
|
+
import { VideoMessage } from '../../dtos/responses/videoMessage';
|
|
6
|
+
import { resolve } from 'path';
|
|
7
|
+
import { BaseContextInternal } from './baseContext';
|
|
8
|
+
export class ReplyContextInternal extends BaseContextInternal {
|
|
12
9
|
/** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
|
|
13
10
|
matchResults;
|
|
14
11
|
/** Id of a message that triggered this action. */
|
|
@@ -23,25 +20,25 @@ class ReplyContextInternal extends baseContext_1.BaseContextInternal {
|
|
|
23
20
|
getQuotePart(quote) {
|
|
24
21
|
if (typeof quote != 'boolean')
|
|
25
22
|
return quote;
|
|
26
|
-
return this.matchResults.length
|
|
27
|
-
? this.
|
|
28
|
-
: this.
|
|
23
|
+
return this.matchResults.length == 0
|
|
24
|
+
? this.messageInfo.text
|
|
25
|
+
: this.matchResults[0][1];
|
|
29
26
|
}
|
|
30
27
|
replyWithText(text, quote, options) {
|
|
31
28
|
const quotedPart = this.getQuotePart(quote);
|
|
32
|
-
const response = new
|
|
29
|
+
const response = new TextMessage(text, this.chatInfo, this.traceId, this.action, new ReplyInfo(this.messageInfo.id, quote ? quotedPart : undefined), options);
|
|
33
30
|
this.responses.push(response);
|
|
34
31
|
return this.createCaptureController(response);
|
|
35
32
|
}
|
|
36
33
|
replyWithImage(name, quote, options) {
|
|
37
34
|
const quotedPart = this.getQuotePart(quote);
|
|
38
|
-
const response = new
|
|
35
|
+
const response = new ImageMessage({ source: resolve(`./content/${name}.png`) }, this.chatInfo, this.traceId, this.action, new ReplyInfo(this.messageInfo.id, quote ? quotedPart : undefined), options);
|
|
39
36
|
this.responses.push(response);
|
|
40
37
|
return this.createCaptureController(response);
|
|
41
38
|
}
|
|
42
39
|
replyWithVideo(name, quote, options) {
|
|
43
40
|
const quotedPart = this.getQuotePart(quote);
|
|
44
|
-
const response = new
|
|
41
|
+
const response = new VideoMessage({ source: resolve(`./content/${name}.mp4`) }, this.chatInfo, this.traceId, this.action, new ReplyInfo(this.messageInfo.id, quote ? quotedPart : undefined), options);
|
|
45
42
|
this.responses.push(response);
|
|
46
43
|
return this.createCaptureController(response);
|
|
47
44
|
}
|
|
@@ -121,8 +118,7 @@ class ReplyContextInternal extends baseContext_1.BaseContextInternal {
|
|
|
121
118
|
* @param emoji Telegram emoji to react with.
|
|
122
119
|
*/
|
|
123
120
|
withReaction: (emoji) => {
|
|
124
|
-
this.responses.push(new
|
|
121
|
+
this.responses.push(new Reaction(this.traceId, this.chatInfo, this.messageInfo.id, emoji, this.action));
|
|
125
122
|
}
|
|
126
123
|
};
|
|
127
124
|
}
|
|
128
|
-
exports.ReplyContextInternal = ReplyContextInternal;
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ActionStateBase = void 0;
|
|
4
|
-
class ActionStateBase {
|
|
1
|
+
export class ActionStateBase {
|
|
5
2
|
pinnedMessages = [];
|
|
6
3
|
lastExecutedDate = 0;
|
|
7
4
|
}
|
|
8
|
-
exports.ActionStateBase = ActionStateBase;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TaskRecord = void 0;
|
|
4
|
-
class TaskRecord {
|
|
1
|
+
export class TaskRecord {
|
|
5
2
|
name;
|
|
6
3
|
taskId;
|
|
7
4
|
interval;
|
|
@@ -11,4 +8,3 @@ class TaskRecord {
|
|
|
11
8
|
this.interval = interval;
|
|
12
9
|
}
|
|
13
10
|
}
|
|
14
|
-
exports.TaskRecord = TaskRecord;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eslint.config.d.ts","sourceRoot":"","sources":["../eslint.config.ts"],"names":[],"mappings":";AAIA,wBAoDE"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import eslint from '@eslint/js';
|
|
2
|
+
import tseslint from 'typescript-eslint';
|
|
3
|
+
import parser from '@typescript-eslint/parser';
|
|
4
|
+
export default tseslint.config({
|
|
5
|
+
ignores: ['dist/**']
|
|
6
|
+
}, eslint.configs.recommended, tseslint.configs.strictTypeChecked, {
|
|
7
|
+
languageOptions: {
|
|
8
|
+
parser,
|
|
9
|
+
parserOptions: {
|
|
10
|
+
project: './tsconfig.json',
|
|
11
|
+
tsconfigRootDir: __dirname,
|
|
12
|
+
sourceType: 'module',
|
|
13
|
+
projectService: true
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
plugins: { '@typescript-eslint': tseslint.plugin },
|
|
17
|
+
rules: {
|
|
18
|
+
'@typescript-eslint/switch-exhaustiveness-check': 'error',
|
|
19
|
+
'@typescript-eslint/no-unused-vars': [
|
|
20
|
+
'error',
|
|
21
|
+
{
|
|
22
|
+
args: 'all',
|
|
23
|
+
argsIgnorePattern: '^_',
|
|
24
|
+
caughtErrors: 'all',
|
|
25
|
+
caughtErrorsIgnorePattern: '^_',
|
|
26
|
+
destructuredArrayIgnorePattern: '^_',
|
|
27
|
+
varsIgnorePattern: '^_',
|
|
28
|
+
ignoreRestSiblings: true
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
'@typescript-eslint/no-misused-promises': [
|
|
32
|
+
'error',
|
|
33
|
+
{
|
|
34
|
+
checksVoidReturn: true,
|
|
35
|
+
checksConditionals: true
|
|
36
|
+
}
|
|
37
|
+
],
|
|
38
|
+
'@typescript-eslint/restrict-template-expressions': [
|
|
39
|
+
'error',
|
|
40
|
+
{
|
|
41
|
+
allowNumber: true
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
'@typescript-eslint/unbound-method': [
|
|
45
|
+
'error',
|
|
46
|
+
{
|
|
47
|
+
ignoreStatic: true
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
});
|
|
@@ -1,26 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const toArray_1 = require("../toArray");
|
|
7
|
-
const noop_1 = require("../noop");
|
|
8
|
-
const cooldownInfo_1 = require("../../dtos/cooldownInfo");
|
|
1
|
+
import { CommandAction } from '../../entities/actions/commandAction';
|
|
2
|
+
import { ActionStateBase } from '../../entities/states/actionStateBase';
|
|
3
|
+
import { toArray } from '../toArray';
|
|
4
|
+
import { Noop } from '../noop';
|
|
5
|
+
import { CooldownInfo } from '../../dtos/cooldownInfo';
|
|
9
6
|
/**
|
|
10
7
|
* Builder for `CommandAction` with state represented by `TActionState`
|
|
11
8
|
*/
|
|
12
|
-
class CommandActionBuilderWithState {
|
|
9
|
+
export class CommandActionBuilderWithState {
|
|
13
10
|
name;
|
|
14
11
|
trigger = [];
|
|
15
12
|
activeProvider = () => true;
|
|
16
|
-
cooldownSettingsProvider = () => new
|
|
13
|
+
cooldownSettingsProvider = () => new CooldownInfo(0);
|
|
17
14
|
blacklistProvider = () => [];
|
|
18
15
|
whitelistProvider = () => [];
|
|
19
16
|
allowedUsersProvider = () => [];
|
|
20
|
-
readmeFactory =
|
|
17
|
+
readmeFactory = Noop.emptyString;
|
|
21
18
|
stateConstructor;
|
|
22
|
-
handler =
|
|
23
|
-
condition =
|
|
19
|
+
handler = Noop.call;
|
|
20
|
+
condition = Noop.true;
|
|
24
21
|
maxAllowedSimultaniousExecutions = 0;
|
|
25
22
|
/**
|
|
26
23
|
* Builder for `CommandAction` with state represented by `TActionState`
|
|
@@ -45,7 +42,7 @@ class CommandActionBuilderWithState {
|
|
|
45
42
|
* @param id User id or ids
|
|
46
43
|
*/
|
|
47
44
|
from(id) {
|
|
48
|
-
const ids =
|
|
45
|
+
const ids = toArray(id);
|
|
49
46
|
this.allowedUsersProvider = () => ids;
|
|
50
47
|
return this;
|
|
51
48
|
}
|
|
@@ -102,7 +99,7 @@ class CommandActionBuilderWithState {
|
|
|
102
99
|
* @param cooldownSettings Settings.
|
|
103
100
|
*/
|
|
104
101
|
withCooldown(cooldownSettings) {
|
|
105
|
-
const settings = new
|
|
102
|
+
const settings = new CooldownInfo(cooldownSettings.cooldown, cooldownSettings.message);
|
|
106
103
|
this.cooldownSettingsProvider = () => settings;
|
|
107
104
|
return this;
|
|
108
105
|
}
|
|
@@ -127,7 +124,7 @@ class CommandActionBuilderWithState {
|
|
|
127
124
|
}
|
|
128
125
|
/** Builds action */
|
|
129
126
|
build() {
|
|
130
|
-
return new
|
|
127
|
+
return new CommandAction(this.trigger, this.handler, this.name, {
|
|
131
128
|
cooldownProvider: this.cooldownSettingsProvider,
|
|
132
129
|
isActiveProvider: this.activeProvider,
|
|
133
130
|
chatsBlacklistProvider: this.blacklistProvider,
|
|
@@ -136,16 +133,14 @@ class CommandActionBuilderWithState {
|
|
|
136
133
|
}, this.maxAllowedSimultaniousExecutions, this.condition, this.stateConstructor, this.readmeFactory);
|
|
137
134
|
}
|
|
138
135
|
}
|
|
139
|
-
exports.CommandActionBuilderWithState = CommandActionBuilderWithState;
|
|
140
136
|
/**
|
|
141
137
|
* Builder for `CommandAction` with state represented by default state (containing only last execution date).
|
|
142
138
|
*/
|
|
143
|
-
class CommandActionBuilder extends CommandActionBuilderWithState {
|
|
139
|
+
export class CommandActionBuilder extends CommandActionBuilderWithState {
|
|
144
140
|
/**
|
|
145
141
|
* Builder for `CommandAction` with state represented by default state (containing only last execution date).
|
|
146
142
|
*/
|
|
147
143
|
constructor(name) {
|
|
148
|
-
super(name, () => new
|
|
144
|
+
super(name, () => new ActionStateBase());
|
|
149
145
|
}
|
|
150
146
|
}
|
|
151
|
-
exports.CommandActionBuilder = CommandActionBuilder;
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.InlineQueryActionBuilder = void 0;
|
|
4
|
-
const noop_1 = require("../noop");
|
|
5
|
-
const inlineQueryAction_1 = require("../../entities/actions/inlineQueryAction");
|
|
1
|
+
import { Noop } from '../noop';
|
|
2
|
+
import { InlineQueryAction } from '../../entities/actions/inlineQueryAction';
|
|
6
3
|
/**
|
|
7
4
|
* Builder for `InlineQueryAction`
|
|
8
5
|
*/
|
|
9
|
-
class InlineQueryActionBuilder {
|
|
6
|
+
export class InlineQueryActionBuilder {
|
|
10
7
|
name;
|
|
11
8
|
pattern = /.+/gi;
|
|
12
9
|
activeProvider = () => true;
|
|
13
|
-
handler =
|
|
10
|
+
handler = Noop.call;
|
|
14
11
|
/**
|
|
15
12
|
* Builder for `InlineQueryAction`
|
|
16
13
|
* @param name Action name, will be used for logging and storage
|
|
@@ -48,7 +45,6 @@ class InlineQueryActionBuilder {
|
|
|
48
45
|
}
|
|
49
46
|
/** Builds action */
|
|
50
47
|
build() {
|
|
51
|
-
return new
|
|
48
|
+
return new InlineQueryAction(this.handler, this.name, this.activeProvider, this.pattern);
|
|
52
49
|
}
|
|
53
50
|
}
|
|
54
|
-
exports.InlineQueryActionBuilder = InlineQueryActionBuilder;
|