@alemonjs/telegram 0.2.0 → 0.2.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/lib/index.js CHANGED
@@ -1,14 +1,20 @@
1
1
  import { defineBot, getConfigValue, useUserHashKey, OnProcessor } from 'alemonjs';
2
2
  import TelegramClient from 'node-telegram-bot-api';
3
3
 
4
- const client = global.client;
4
+ const client = new Proxy({}, {
5
+ get: (_, prop) => {
6
+ if (prop in global.client) {
7
+ const original = global.client[prop];
8
+ // 防止函数内this丢失
9
+ return typeof original === 'function' ? original.bind(global.client) : original;
10
+ }
11
+ return undefined;
12
+ }
13
+ });
14
+ const platform = 'telegram';
5
15
  var index = defineBot(() => {
6
16
  const value = getConfigValue();
7
- const config = value?.telegram;
8
- if (!config)
9
- return;
10
- const Platform = 'telegram';
11
- //
17
+ const config = value[platform];
12
18
  const client = new TelegramClient(config.token, {
13
19
  polling: true,
14
20
  baseApiUrl: config?.base_api_url ?? '',
@@ -53,7 +59,7 @@ var index = defineBot(() => {
53
59
  client.on('text', async (event) => {
54
60
  const UserId = String(event?.from?.id);
55
61
  const UserKey = useUserHashKey({
56
- Platform: Platform,
62
+ Platform: platform,
57
63
  UserId: UserId
58
64
  });
59
65
  const UserAvatar = {
@@ -94,7 +100,7 @@ var index = defineBot(() => {
94
100
  // 定义消
95
101
  const e = {
96
102
  // 事件类型
97
- Platform: Platform,
103
+ Platform: platform,
98
104
  // 频道
99
105
  GuildId: String(event?.chat.id),
100
106
  ChannelId: String(event?.chat.id),
@@ -127,7 +133,7 @@ var index = defineBot(() => {
127
133
  // 定义消
128
134
  const e = {
129
135
  // 事件类型
130
- Platform: Platform,
136
+ Platform: platform,
131
137
  // 用户Id
132
138
  UserId: String(event?.from.id),
133
139
  UserKey: UserKey,
@@ -160,7 +166,7 @@ var index = defineBot(() => {
160
166
  return;
161
167
  const UserId = String(event?.from?.id);
162
168
  const UserKey = useUserHashKey({
163
- Platform: Platform,
169
+ Platform: platform,
164
170
  UserId: UserId
165
171
  });
166
172
  const UserAvatar = {
@@ -191,7 +197,7 @@ var index = defineBot(() => {
191
197
  // 定义消
192
198
  const e = {
193
199
  // 事件类型
194
- Platform: Platform,
200
+ Platform: platform,
195
201
  // guild
196
202
  GuildId: String(event?.chat.id),
197
203
  ChannelId: String(event?.chat.id),
@@ -251,4 +257,4 @@ var index = defineBot(() => {
251
257
  };
252
258
  });
253
259
 
254
- export { client, index as default };
260
+ export { client, index as default, platform };
package/package.json CHANGED
@@ -1,31 +1,36 @@
1
1
  {
2
2
  "name": "@alemonjs/telegram",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "telegram-bot",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",
7
7
  "type": "module",
8
8
  "main": "lib/index.js",
9
9
  "types": "lib",
10
+ "scripts": {
11
+ "build": "node bundle.js"
12
+ },
10
13
  "dependencies": {
11
14
  "grammy": "^1.30.0",
12
15
  "node-telegram-bot-api": "^0.66.0"
13
16
  },
14
17
  "devDependencies": {
18
+ "@rollup/plugin-typescript": "^11.1.6",
19
+ "lvyjs": "^0.2.13",
20
+ "rollup": "^4.18.1",
21
+ "rollup-plugin-dts": "^6.1.1",
22
+ "tsx": "^4.19.1",
15
23
  "@types/node-telegram-bot-api": "^0.64.7"
16
24
  },
17
25
  "exports": {
18
26
  ".": {
19
27
  "import": "./lib/index.js",
20
28
  "types": "./lib/index.d.ts"
21
- }
29
+ },
30
+ "./package": "./package.json"
22
31
  },
23
32
  "keywords": [
24
- "alemonjs",
25
- "telegram",
26
- "telegram-bot",
27
- "bot",
28
- "chat-bot"
33
+ "alemonjs"
29
34
  ],
30
35
  "publishConfig": {
31
36
  "registry": "https://registry.npmjs.org",
package/lib/index.d.ts DELETED
@@ -1,8 +0,0 @@
1
- import * as alemonjs from 'alemonjs';
2
- import TelegramClient from 'node-telegram-bot-api';
3
-
4
- type Client = typeof TelegramClient.prototype;
5
- declare const client: Client;
6
- declare const _default: () => alemonjs.ClientAPI;
7
-
8
- export { type Client, client, _default as default };