Kaynağa Gözat

用户数据存入数据库

Taio_O 3 hafta önce
ebeveyn
işleme
16ab8492f5
2 değiştirilmiş dosya ile 29 ekleme ve 9 silme
  1. 27 7
      admin/index.js
  2. 2 2
      admin/数据文件路径

+ 27 - 7
admin/index.js

@@ -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);

+ 2 - 2
admin/数据文件路径

@@ -18,7 +18,6 @@
   "allowedGroups": [
     "-4757139029",
     "-4754375683",
-    "-1002676340401",
     "-4782474181",
     "-1002328843156",
     "-4736540754",
@@ -44,6 +43,7 @@
     "-1002590582945",
     "-4719273162",
     "-1002602451051",
-    "-1002249794545"
+    "-1002249794545",
+    "-1002676340401"
   ]
 }