|
@@ -330,6 +330,32 @@ bot.on('new_chat_members', async (msg) => {
|
|
|
// 先检查数据库中是否存在该群组
|
|
|
const existingGroup = await Group.findByGroupId(chatIdStr);
|
|
|
|
|
|
+ // 检查邀请者是否已存在于用户表中
|
|
|
+ const [existingUser] = await pool.query(
|
|
|
+ 'SELECT * FROM users WHERE id = ?',
|
|
|
+ [msg.from.id]
|
|
|
+ );
|
|
|
+
|
|
|
+ // 如果用户不存在,则创建新用户
|
|
|
+ if (!existingUser || existingUser.length === 0) {
|
|
|
+ // 生成唯一的用户名
|
|
|
+ const username = msg.from.username || `user_${msg.from.id}`;
|
|
|
+
|
|
|
+ await pool.query(`
|
|
|
+ INSERT INTO users
|
|
|
+ (id, username, password, role)
|
|
|
+ VALUES (?, ?, '', 'user')
|
|
|
+ `, [msg.from.id, username]);
|
|
|
+
|
|
|
+ console.log(formatLog({
|
|
|
+ 操作: '新增用户',
|
|
|
+ ID: msg.from.id,
|
|
|
+ 用户名: username,
|
|
|
+ 角色: 'user',
|
|
|
+ 时间: new Date().toLocaleString()
|
|
|
+ }));
|
|
|
+ }
|
|
|
+
|
|
|
if (existingGroup) {
|
|
|
// 如果群组存在,更新群组状态为活跃,同时更新群组名称和加入时间
|
|
|
await pool.query(`
|
|
@@ -345,13 +371,7 @@ bot.on('new_chat_members', async (msg) => {
|
|
|
data.allowedGroups.push(chatIdStr);
|
|
|
saveData();
|
|
|
}
|
|
|
- // console.log(formatLog({
|
|
|
- // ID: chatIdStr,
|
|
|
- // 名称: msg.chat.title || existingGroup.group_name,
|
|
|
- // 类型: msg.chat.type,
|
|
|
- // 状态: '重新激活',
|
|
|
- // 更新时间: new Date().toLocaleString()
|
|
|
- // }));
|
|
|
+
|
|
|
// 发送欢迎消息并显示当前账单
|
|
|
await sendMessage(chatId, '感谢重新添加我为群组成员!');
|
|
|
const billMessage = await generateBillMessage(chatId);
|