@alemonjs/telegram 0.2.0 → 0.2.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.
package/lib/index.d.ts CHANGED
@@ -3,6 +3,7 @@ import TelegramClient from 'node-telegram-bot-api';
3
3
 
4
4
  type Client = typeof TelegramClient.prototype;
5
5
  declare const client: Client;
6
+ declare const platform = "telegram";
6
7
  declare const _default: () => alemonjs.ClientAPI;
7
8
 
8
- export { type Client, client, _default as default };
9
+ export { type Client, client, _default as default, platform };
package/lib/index.js CHANGED
@@ -1,13 +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
+ return global.client[prop];
8
+ }
9
+ return undefined;
10
+ }
11
+ });
12
+ const platform = 'telegram';
5
13
  var index = defineBot(() => {
6
14
  const value = getConfigValue();
7
15
  const config = value?.telegram;
8
16
  if (!config)
9
17
  return;
10
- const Platform = 'telegram';
11
18
  //
12
19
  const client = new TelegramClient(config.token, {
13
20
  polling: true,
@@ -53,7 +60,7 @@ var index = defineBot(() => {
53
60
  client.on('text', async (event) => {
54
61
  const UserId = String(event?.from?.id);
55
62
  const UserKey = useUserHashKey({
56
- Platform: Platform,
63
+ Platform: platform,
57
64
  UserId: UserId
58
65
  });
59
66
  const UserAvatar = {
@@ -94,7 +101,7 @@ var index = defineBot(() => {
94
101
  // 定义消
95
102
  const e = {
96
103
  // 事件类型
97
- Platform: Platform,
104
+ Platform: platform,
98
105
  // 频道
99
106
  GuildId: String(event?.chat.id),
100
107
  ChannelId: String(event?.chat.id),
@@ -127,7 +134,7 @@ var index = defineBot(() => {
127
134
  // 定义消
128
135
  const e = {
129
136
  // 事件类型
130
- Platform: Platform,
137
+ Platform: platform,
131
138
  // 用户Id
132
139
  UserId: String(event?.from.id),
133
140
  UserKey: UserKey,
@@ -160,7 +167,7 @@ var index = defineBot(() => {
160
167
  return;
161
168
  const UserId = String(event?.from?.id);
162
169
  const UserKey = useUserHashKey({
163
- Platform: Platform,
170
+ Platform: platform,
164
171
  UserId: UserId
165
172
  });
166
173
  const UserAvatar = {
@@ -191,7 +198,7 @@ var index = defineBot(() => {
191
198
  // 定义消
192
199
  const e = {
193
200
  // 事件类型
194
- Platform: Platform,
201
+ Platform: platform,
195
202
  // guild
196
203
  GuildId: String(event?.chat.id),
197
204
  ChannelId: String(event?.chat.id),
@@ -251,4 +258,4 @@ var index = defineBot(() => {
251
258
  };
252
259
  });
253
260
 
254
- export { client, index as default };
261
+ export { client, index as default, platform };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alemonjs/telegram",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "telegram-bot",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",