@alemonjs/telegram 0.0.4 → 0.0.5

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 (2) hide show
  1. package/lib/index.js +59 -8
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { defineBot, getConfig, Text, OnProcessor, useParse } from 'alemonjs';
2
2
  import Client from 'node-telegram-bot-api';
3
3
 
4
- process.env.NODE_NO_WARNINGS = '1';
5
4
  var index = defineBot(() => {
6
5
  //
7
6
  const cfg = getConfig();
@@ -17,7 +16,7 @@ var index = defineBot(() => {
17
16
  proxy: config?.proxy ?? ''
18
17
  }
19
18
  });
20
- const getUserProfilePhotosUrl = UserId => {
19
+ const getUserProfilePhotosUrl = (UserId) => {
21
20
  return new Promise((resolve, reject) => {
22
21
  if (!UserId) {
23
22
  reject(new Error('UserId 不能为空'));
@@ -48,14 +47,14 @@ var index = defineBot(() => {
48
47
  //
49
48
  client.on('text', async (event) => {
50
49
  let UserAvatar = '';
51
- if (event?.chat.type == 'channel' || event?.chat.type == 'private') {
50
+ if (event?.chat.type == 'supergroup' || event?.chat.type == 'private') {
52
51
  const photo = await getUserProfilePhotosUrl(event?.from?.id).catch(console.error);
53
52
  if (typeof photo == 'string')
54
53
  UserAvatar = photo;
55
54
  }
56
- if (event?.chat.type == 'channel' || event.chat.type == 'supergroup') {
55
+ if (event?.chat.type == 'channel' || event?.chat.type == 'supergroup') {
57
56
  // 机器人消息不处理
58
- if (event.from?.is_bot)
57
+ if (event?.from?.is_bot)
59
58
  return;
60
59
  // 定义消
61
60
  const e = {
@@ -67,6 +66,8 @@ var index = defineBot(() => {
67
66
  GuildName: event?.chat.title,
68
67
  // 子频道
69
68
  ChannelId: String(event?.chat.id),
69
+ GuildIdAvatar: '',
70
+ GuildIdName: '',
70
71
  // 是否是主人
71
72
  IsMaster: false,
72
73
  // 用户ID
@@ -80,7 +81,7 @@ var index = defineBot(() => {
80
81
  // 用户消息
81
82
  Megs: [Text(event?.text)],
82
83
  // 用户openId
83
- OpenID: String(event.chat?.id),
84
+ OpenID: String(event?.chat?.id),
84
85
  // 创建时间
85
86
  CreateAt: Date.now(),
86
87
  //
@@ -116,7 +117,7 @@ var index = defineBot(() => {
116
117
  // 用户消息
117
118
  Megs: [Text(event?.text)],
118
119
  // 用户openId
119
- OpenID: String(event.chat?.id),
120
+ OpenID: String(event?.chat?.id),
120
121
  // 创建时间
121
122
  CreateAt: Date.now(),
122
123
  //
@@ -134,6 +135,56 @@ var index = defineBot(() => {
134
135
  OnProcessor(e, 'private.message.create');
135
136
  }
136
137
  });
138
+ client.on('new_chat_members', async (event) => {
139
+ // 机器人消息不处理
140
+ if (event?.from.is_bot)
141
+ return;
142
+ let UserAvatar = '';
143
+ const photo = await getUserProfilePhotosUrl(event?.from?.id).catch(console.error);
144
+ if (typeof photo == 'string')
145
+ UserAvatar = photo;
146
+ // 定义消
147
+ const e = {
148
+ // 事件类型
149
+ Platform: 'telegram',
150
+ // 频道
151
+ GuildId: String(event?.chat.id),
152
+ // 频道名称
153
+ GuildName: event?.chat.title,
154
+ // 子频道
155
+ ChannelId: String(event?.chat.id),
156
+ GuildIdAvatar: '',
157
+ GuildIdName: '',
158
+ // 是否是主人
159
+ IsMaster: false,
160
+ // 用户ID
161
+ UserId: String(event?.from?.id),
162
+ // 用户名
163
+ UserName: event?.chat.username,
164
+ // 用户头像
165
+ UserAvatar: UserAvatar,
166
+ // 格式化数据
167
+ MsgId: String(event?.message_id),
168
+ // 用户消息
169
+ Megs: [Text(event?.text)],
170
+ // 用户openId
171
+ OpenID: String(event?.chat?.id),
172
+ // 创建时间
173
+ CreateAt: Date.now(),
174
+ //
175
+ tag: 'txt',
176
+ //
177
+ value: null
178
+ };
179
+ // 当访问的时候获取
180
+ Object.defineProperty(e, 'value', {
181
+ get() {
182
+ return event;
183
+ }
184
+ });
185
+ //
186
+ OnProcessor(e, 'member.add');
187
+ });
137
188
  // const eventKeys = [
138
189
  // 'message',
139
190
  // 'text',
@@ -210,7 +261,7 @@ var index = defineBot(() => {
210
261
  if (val.length < 0)
211
262
  return Promise.all([]);
212
263
  const content = useParse(val, 'Text');
213
- const e = event.value;
264
+ const e = event?.value;
214
265
  if (content) {
215
266
  return Promise.all([content].map(item => client.sendMessage(e.chat.id, item)));
216
267
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alemonjs/telegram",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "telegram-bot",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",