|
@@ -9,7 +9,7 @@ const {
|
|
pool,
|
|
pool,
|
|
testConnection
|
|
testConnection
|
|
} = require('./config/database');
|
|
} = require('./config/database');
|
|
-const initDatabase = require('./config/initDb');
|
|
|
|
|
|
+// const initDatabase = require('./config/initDb');
|
|
const Group = require('./models/Group');
|
|
const Group = require('./models/Group');
|
|
const Transaction = require('./models/Transaction');
|
|
const Transaction = require('./models/Transaction');
|
|
|
|
|
|
@@ -99,8 +99,10 @@ async function checkUserPermission(chatId, userId) {
|
|
console.error('解析操作人列表失败:', e);
|
|
console.error('解析操作人列表失败:', e);
|
|
operators = [];
|
|
operators = [];
|
|
}
|
|
}
|
|
-
|
|
|
|
- const isOperator = operators.some(op => op.operator_id === userIdStr);
|
|
|
|
|
|
+ // console.log(groupInfo.operators)
|
|
|
|
+ // console.log(operators);
|
|
|
|
+ // console.log(userIdStr);
|
|
|
|
+ const isOperator = operators.some(op => op.operator_id == userIdStr);
|
|
|
|
|
|
// 只在权限检查失败时输出详细日志
|
|
// 只在权限检查失败时输出详细日志
|
|
if (!isCreator && !isOperator) {
|
|
if (!isCreator && !isOperator) {
|
|
@@ -151,7 +153,7 @@ bot.on('message', async (msg) => {
|
|
|
|
|
|
const text = msg.text?.trim();
|
|
const text = msg.text?.trim();
|
|
if (!text) return;
|
|
if (!text) return;
|
|
-
|
|
|
|
|
|
+ console.error(msg);
|
|
// 0. 检查用户权限
|
|
// 0. 检查用户权限
|
|
const hasPermission = await checkUserPermission(msg.chat.id, msg.from.id);
|
|
const hasPermission = await checkUserPermission(msg.chat.id, msg.from.id);
|
|
if (!hasPermission) {
|
|
if (!hasPermission) {
|
|
@@ -419,18 +421,18 @@ bot.on('message', async (msg) => {
|
|
else if (text.startsWith('设置操作人')) {
|
|
else if (text.startsWith('设置操作人')) {
|
|
try {
|
|
try {
|
|
const groupId = msg.chat.id.toString();
|
|
const groupId = msg.chat.id.toString();
|
|
- const mentionedUser = msg.entities?.find(e => e.type === 'mention');
|
|
|
|
|
|
+ // const mentionedUser = msg.entities?.find(e => e.type === 'mention');
|
|
|
|
|
|
- if (!mentionedUser) {
|
|
|
|
|
|
+ if (!msg.reply_to_message.from.id) {
|
|
// 如果没有@用户,回复原消息并提示设置用户名
|
|
// 如果没有@用户,回复原消息并提示设置用户名
|
|
- await bot.sendMessage(msg.chat.id, '请设置您的Telegram用户名后再试', {
|
|
|
|
|
|
+ await bot.sendMessage(msg.chat.id, '请通过回复要添加操作人的消息设置', {
|
|
reply_to_message_id: msg.message_id
|
|
reply_to_message_id: msg.message_id
|
|
});
|
|
});
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
// 获取被@的用户名
|
|
// 获取被@的用户名
|
|
- const username = text.slice(mentionedUser.offset + 1, mentionedUser.offset + mentionedUser.length);
|
|
|
|
|
|
+ const username = msg.reply_to_message.from.first_name;//text.slice(mentionedUser.offset + 1, mentionedUser.offset + mentionedUser.length);
|
|
|
|
|
|
// 获取群组信息
|
|
// 获取群组信息
|
|
const [group] = await pool.query(
|
|
const [group] = await pool.query(
|
|
@@ -475,15 +477,16 @@ bot.on('message', async (msg) => {
|
|
[username]
|
|
[username]
|
|
);
|
|
);
|
|
|
|
|
|
- let newOperatorId;
|
|
|
|
|
|
+ let newOperatorId=msg.reply_to_message.from.id;
|
|
|
|
+ let newOperatorUid=msg.reply_to_message.from.username;
|
|
if (!user || !user[0]) {
|
|
if (!user || !user[0]) {
|
|
// 如果用户不存在,创建新用户
|
|
// 如果用户不存在,创建新用户
|
|
try {
|
|
try {
|
|
const [result] = await pool.query(
|
|
const [result] = await pool.query(
|
|
- 'INSERT INTO users (username, password, role) VALUES (?, ?, ?)',
|
|
|
|
- [username, '', 'user']
|
|
|
|
|
|
+ 'INSERT INTO users (id,uid,username, password, role) VALUES (?,?,?, ?, ?)',
|
|
|
|
+ [newOperatorId,newOperatorUid,username, '', 'user']
|
|
);
|
|
);
|
|
- newOperatorId = result.insertId.toString();
|
|
|
|
|
|
+ // newOperatorId = result.insertId.toString();
|
|
console.log(`创建新用户成功 - 用户名: ${username}, ID: ${newOperatorId}`);
|
|
console.log(`创建新用户成功 - 用户名: ${username}, ID: ${newOperatorId}`);
|
|
} catch (error) {
|
|
} catch (error) {
|
|
console.error('创建新用户失败:', error);
|
|
console.error('创建新用户失败:', error);
|
|
@@ -491,7 +494,7 @@ bot.on('message', async (msg) => {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- newOperatorId = user[0].id.toString();
|
|
|
|
|
|
+ // newOperatorId = user[0].id.toString();
|
|
}
|
|
}
|
|
|
|
|
|
// 检查是否已经是操作人
|
|
// 检查是否已经是操作人
|
|
@@ -504,6 +507,7 @@ bot.on('message', async (msg) => {
|
|
operators.push({
|
|
operators.push({
|
|
operator_id: newOperatorId,
|
|
operator_id: newOperatorId,
|
|
operator_username: username,
|
|
operator_username: username,
|
|
|
|
+ operator_uid:newOperatorUid,
|
|
added_by: userId,
|
|
added_by: userId,
|
|
added_at: new Date().toISOString()
|
|
added_at: new Date().toISOString()
|
|
});
|
|
});
|
|
@@ -683,19 +687,16 @@ function generateInlineKeyboard(chatId) {
|
|
bot.on('callback_query', async (callbackQuery) => {
|
|
bot.on('callback_query', async (callbackQuery) => {
|
|
const chatId = callbackQuery.message.chat.id;
|
|
const chatId = callbackQuery.message.chat.id;
|
|
const data = callbackQuery.data;
|
|
const data = callbackQuery.data;
|
|
-
|
|
|
|
try {
|
|
try {
|
|
if (data.startsWith('bill_page_')) {
|
|
if (data.startsWith('bill_page_')) {
|
|
const groupId = data.split('_')[2];
|
|
const groupId = data.split('_')[2];
|
|
- await bot.answerCallbackQuery(callbackQuery.id, {
|
|
|
|
- url: 'https://google.com'
|
|
|
|
- });
|
|
|
|
|
|
+ console.log('https://jfpay.top/admin/views/statistics_bill.html?groupId='+groupId)
|
|
|
|
+ await bot.sendMessage(chatId, `点击查看完整账单:[完整账单](https://jfpay.top/admin/views/statistics_bill.html?groupId=${groupId})`, {parse_mode: 'Markdown'});
|
|
} else if (data === 'business_contact') {
|
|
} else if (data === 'business_contact') {
|
|
- await bot.answerCallbackQuery(callbackQuery.id, {
|
|
|
|
- url: 'https://t.me/your_business_account'
|
|
|
|
- });
|
|
|
|
|
|
+ await bot.sendMessage(chatId, `24小时商务对接:[点击跳转](https://t.me/yyyyaaaa123_bot)`, {parse_mode: 'Markdown'})
|
|
}
|
|
}
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
|
+ console.log(error)
|
|
console.error(formatLog('处理内联按钮回调失败', error));
|
|
console.error(formatLog('处理内联按钮回调失败', error));
|
|
await bot.answerCallbackQuery(callbackQuery.id, {
|
|
await bot.answerCallbackQuery(callbackQuery.id, {
|
|
text: '操作失败,请稍后重试',
|
|
text: '操作失败,请稍后重试',
|
|
@@ -840,7 +841,7 @@ function loadData() {
|
|
}
|
|
}
|
|
// 测试数据库连接并初始化
|
|
// 测试数据库连接并初始化
|
|
testConnection().then(() => {
|
|
testConnection().then(() => {
|
|
- return initDatabase();
|
|
|
|
|
|
+ // return initDatabase();
|
|
}).then(() => {
|
|
}).then(() => {
|
|
// 加载数据
|
|
// 加载数据
|
|
loadData();
|
|
loadData();
|