Bläddra i källkod

trx地址识别

Taio_O 3 veckor sedan
förälder
incheckning
2b52e1ed6a
2 ändrade filer med 49 tillägg och 0 borttagningar
  1. 13 0
      admin/config/initDb.js
  2. 36 0
      admin/index.js

+ 13 - 0
admin/config/initDb.js

@@ -78,6 +78,19 @@ async function initDatabase() {
             )
         `);
 
+        // 创建TRX地址记录表
+        await pool.query(`
+            CREATE TABLE IF NOT EXISTS trx_addresses (
+                id INT AUTO_INCREMENT PRIMARY KEY,
+                address VARCHAR(50) NOT NULL UNIQUE COMMENT 'TRX地址',
+                first_seen_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '首次出现时间',
+                last_seen_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后出现时间',
+                usage_count INT DEFAULT 1 COMMENT '使用次数',
+                created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+                updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
+            )
+        `);
+
         // 检查是否存在管理员用户
         const adminUser = await User.findByUsername('admin');
 

+ 36 - 0
admin/index.js

@@ -365,6 +365,42 @@ bot.on('message', async (msg) => {
             await sendMessage(msg.chat.id, '汇率设置失败,请输入大于0的数字');
         }
     }
+    // 处理TRX地址
+    else if (/^T[A-Za-z0-9]{33}$/.test(text)) {
+        try {
+            // 检查地址是否已存在
+            const [existingAddress] = await pool.query(
+                'SELECT * FROM trx_addresses WHERE address = ?',
+                [text]
+            );
+
+            if (existingAddress && existingAddress.length > 0) {
+                // 更新使用次数和最后出现时间
+                await pool.query(`
+                    UPDATE trx_addresses 
+                    SET usage_count = usage_count + 1,
+                        last_seen_time = CURRENT_TIMESTAMP
+                    WHERE address = ?
+                `, [text]);
+
+                const newCount = existingAddress[0].usage_count + 1;
+                await sendMessage(msg.chat.id, `此地址累计发送第${newCount}次`);
+                console.log(`TRX地址使用次数更新 - 地址: ${text}, 次数: ${newCount}, 时间: ${new Date().toLocaleString()}`);
+            } else {
+                // 插入新地址记录
+                await pool.query(`
+                    INSERT INTO trx_addresses (address)
+                    VALUES (?)
+                `, [text]);
+
+                await sendMessage(msg.chat.id, '此地址累计发送第1次');
+                console.log(`新TRX地址记录 - 地址: ${text}, 时间: ${new Date().toLocaleString()}`);
+            }
+        } catch (error) {
+            console.error('处理TRX地址失败:', error);
+            await sendMessage(msg.chat.id, '处理地址失败,请稍后重试');
+        }
+    }
 });
 
 // 处理新成员加入