Browse Source

refactor: telegram bot

M1Screw 2 years ago
parent
commit
ef62ab0154

+ 1 - 0
app/routes.php

@@ -236,6 +236,7 @@ return static function (Slim\App $app): void {
         $group->get('/setting/support', App\Controllers\Admin\Setting\SupportController::class . ':support');
         $group->post('/setting/support', App\Controllers\Admin\Setting\SupportController::class . ':saveSupport');
         $group->post('/setting/test_email', App\Controllers\Admin\Setting\EmailController::class . ':testEmail');
+        $group->post('/setting/test_telegram', App\Controllers\Admin\Setting\ImController::class . ':testTelegram');
         $group->post('/setting/test_discord', App\Controllers\Admin\Setting\ImController::class . ':testDiscord');
         $group->post('/setting/test_slack', App\Controllers\Admin\Setting\ImController::class . ':testSlack');
         // 礼品卡

+ 0 - 8
config/.config.example.php

@@ -79,14 +79,6 @@ $_ENV['auto_detect_ban_allow_users'] = [];          // 审计封禁的例外用
 $_ENV['auto_detect_ban_number']      = 30;             // 每次执行封禁所需的触发次数
 $_ENV['auto_detect_ban_time']        = 60;             // 每次封禁的时长 (分钟)
 
-//Bot 设置--------------------------------------------------------------------------------------------
-# Telegram bot
-$_ENV['enable_telegram']                    = false;        //是否开启 Telegram bot
-$_ENV['telegram_token']                     = '';           //Telegram bot,bot 的 token ,跟 father bot 申请
-$_ENV['telegram_chatid']                    = -111;         //Telegram bot,群组会话 ID,把机器人拉进群里之后跟他 /ping 一下即可得到
-$_ENV['telegram_bot']                       = '_bot';       //Telegram 机器人账号
-$_ENV['telegram_request_token']             = '';           //Webhook密钥,更新这个参数之后请 php xcat Tool setTelegram
-
 //节点检测-----------------------------------------------------------------------------------------------
 #GFW检测
 $_ENV['detect_gfw_port']     = 443;                                                  //所有节点服务器都打开的TCP端口

+ 415 - 475
config/settings.json

@@ -641,373 +641,53 @@
     },
     {
         "id": null,
-        "item": "discord_bot_token",
-        "value": "",
-        "class": "discord",
-        "is_public": 0,
-        "type": "string",
-        "default": "",
-        "mark": "Discord Bot Token"
-    },
-    {
-        "id": null,
-        "item": "slack_token",
-        "value": "",
-        "class": "slack",
-        "is_public": 0,
-        "type": "string",
-        "default": "",
-        "mark": "Slack App Token"
-    },
-    {
-        "id": null,
-        "item": "tawk_id",
-        "value": "",
-        "class": "support",
-        "is_public": 1,
-        "type": "string",
-        "default": "",
-        "mark": "tawk_id"
-    },
-    {
-        "id": null,
-        "item": "crisp_id",
-        "value": "",
-        "class": "support",
-        "is_public": 1,
-        "type": "string",
-        "default": "",
-        "mark": "crisp_id"
-    },
-    {
-        "id": null,
-        "item": "livechat_id",
-        "value": "",
-        "class": "support",
-        "is_public": 1,
-        "type": "string",
-        "default": "",
-        "mark": "livechat_id"
-    },
-    {
-        "id": null,
-        "item": "mylivechat_id",
-        "value": "",
-        "class": "support",
-        "is_public": 1,
-        "type": "string",
-        "default": "",
-        "mark": "mylivechat_id"
-    },
-    {
-        "id": null,
-        "item": "live_chat",
-        "value": "none",
-        "class": "support",
-        "is_public": 1,
-        "type": "string",
-        "default": "none",
-        "mark": "客服系统开关"
-    },
-    {
-        "id": null,
-        "item": "enable_ticket",
-        "value": "1",
-        "class": "support",
-        "is_public": 1,
-        "type": "bool",
-        "default": "1",
-        "mark": "启用工单系统"
-    },
-    {
-        "id": null,
-        "item": "mail_ticket",
-        "value": "1",
-        "class": "support",
-        "is_public": 0,
-        "type": "bool",
-        "default": "1",
-        "mark": "启用工单邮件提醒"
-    },
-    {
-        "id": null,
-        "item": "ticket_limit",
-        "value": "3",
-        "class": "support",
-        "is_public": 0,
-        "type": "int",
-        "default": "3",
-        "mark": "用戶工单配額(每月)"
-    },
-    {
-        "id": null,
-        "item": "reg_mode",
-        "value": "open",
-        "class": "register",
-        "is_public": 1,
-        "type": "string",
-        "default": "open",
-        "mark": "注册模式"
-    },
-    {
-        "id": null,
-        "item": "reg_email_verify",
+        "item": "enable_telegram",
         "value": "0",
-        "class": "register",
+        "class": "telegram",
         "is_public": 1,
         "type": "bool",
         "default": "0",
-        "mark": "邮箱验证"
-    },
-    {
-        "id": null,
-        "item": "reg_forbidden_ip",
-        "value": "127.0.0.0/8,::1/128",
-        "class": "register",
-        "is_public": 0,
-        "type": "string",
-        "default": "127.0.0.0/8,::1/128",
-        "mark": "注册时默认禁止访问IP列表"
+        "mark": "是否启用Telegram机器人"
     },
     {
         "id": null,
-        "item": "reg_forbidden_port",
+        "item": "telegram_token",
         "value": "",
-        "class": "register",
+        "class": "telegram",
         "is_public": 0,
         "type": "string",
         "default": "",
-        "mark": "注册时默认禁止访问端口列表"
-    },
-    {
-        "id": null,
-        "item": "random_group",
-        "value": "0",
-        "class": "register",
-        "is_public": 0,
-        "type": "string",
-        "default": "0",
-        "mark": "注册时随机分配到的分组"
-    },
-    {
-        "id": null,
-        "item": "min_port",
-        "value": "10000",
-        "class": "register",
-        "is_public": 1,
-        "type": "int",
-        "default": "10000",
-        "mark": "用户端口池最小值"
-    },
-    {
-        "id": null,
-        "item": "max_port",
-        "value": "65535",
-        "class": "register",
-        "is_public": 1,
-        "type": "int",
-        "default": "65535",
-        "mark": "用户端口池最大值"
-    },
-    {
-        "id": null,
-        "item": "free_user_reset_day",
-        "value": "0",
-        "class": "register",
-        "is_public": 0,
-        "type": "int",
-        "default": "0",
-        "mark": "免费用戶的流量重置日"
-    },
-    {
-        "id": null,
-        "item": "free_user_reset_bandwidth",
-        "value": "0",
-        "class": "register",
-        "is_public": 0,
-        "type": "int",
-        "default": "0",
-        "mark": "需要重置的免费流量"
-    },
-    {
-        "id": null,
-        "item": "sign_up_for_free_traffic",
-        "value": "20",
-        "class": "register",
-        "is_public": 0,
-        "type": "int",
-        "default": "20",
-        "mark": "注册时赠送的流量(GB)"
-    },
-    {
-        "id": null,
-        "item": "sign_up_for_free_time",
-        "value": "365",
-        "class": "register",
-        "is_public": 0,
-        "type": "int",
-        "default": "365",
-        "mark": "注册时设定的账户有效期(天)"
-    },
-    {
-        "id": null,
-        "item": "connection_ip_limit",
-        "value": "0",
-        "class": "register",
-        "is_public": 0,
-        "type": "int",
-        "default": "0",
-        "mark": "注册时设定的连接 IP 限制"
-    },
-    {
-        "id": null,
-        "item": "connection_rate_limit",
-        "value": "0",
-        "class": "register",
-        "is_public": 0,
-        "type": "int",
-        "default": "0",
-        "mark": "注册时设定的使用速率限制"
-    },
-    {
-        "id": null,
-        "item": "sign_up_for_class",
-        "value": "0",
-        "class": "register",
-        "is_public": 0,
-        "type": "int",
-        "default": "0",
-        "mark": "注册时设定的等级"
+        "mark": "Telegram Bot Token"
     },
     {
         "id": null,
-        "item": "sign_up_for_class_time",
-        "value": "7",
-        "class": "register",
-        "is_public": 0,
-        "type": "int",
-        "default": "7",
-        "mark": "注册时设定的等级过期时间(天)"
-    },
-    {
-        "id": null,
-        "item": "sign_up_for_method",
-        "value": "aes-128-gcm",
-        "class": "register",
-        "is_public": 0,
-        "type": "string",
-        "default": "aes-128-gcm",
-        "mark": "默认加密"
-    },
-    {
-        "id": null,
-        "item": "sign_up_for_daily_report",
-        "value": "0",
-        "class": "register",
-        "is_public": 0,
-        "type": "bool",
-        "default": "0",
-        "mark": "注册后是否默认接收每日用量邮件推送"
-    },
-    {
-        "id": null,
-        "item": "sign_up_for_invitation_codes",
-        "value": "10",
-        "class": "register",
-        "is_public": 0,
-        "type": "int",
-        "default": "10",
-        "mark": "初始邀请注册链接使用次数限制"
-    },
-    {
-        "id": null,
-        "item": "invitation_to_register_balance_reward",
-        "value": "1",
-        "class": "invite",
-        "is_public": 1,
-        "type": "int",
-        "default": "1",
-        "mark": "邀请注册余额奖励(元)"
-    },
-    {
-        "id": null,
-        "item": "invitation_to_register_traffic_reward",
-        "value": "10",
-        "class": "invite",
-        "is_public": 1,
-        "type": "int",
-        "default": "10",
-        "mark": "邀请注册流量奖励(GB)"
-    },
-    {
-        "id": null,
-        "item": "invitation_mode",
-        "value": "after_paid",
-        "class": "invite",
-        "is_public": 0,
-        "type": "string",
-        "default": "after_paid",
-        "mark": "邀请模式"
-    },
-    {
-        "id": null,
-        "item": "invite_rebate_mode",
-        "value": "limit_amount",
-        "class": "invite",
-        "is_public": 0,
-        "type": "string",
-        "default": "limit_amount",
-        "mark": "返利模式"
-    },
-    {
-        "id": null,
-        "item": "rebate_frequency_limit",
-        "value": "3",
-        "class": "invite",
-        "is_public": 0,
-        "type": "string",
-        "default": "3",
-        "mark": "返利总次数限制"
-    },
-    {
-        "id": null,
-        "item": "rebate_amount_limit",
-        "value": "100",
-        "class": "invite",
+        "item": "telegram_chatid",
+        "value": "-1",
+        "class": "telegram",
         "is_public": 0,
         "type": "int",
-        "default": "100",
-        "mark": "返利总金额限制"
+        "default": "-1",
+        "mark": "Telegram 群组会话 ID"
     },
     {
         "id": null,
-        "item": "rebate_ratio",
-        "value": "0.2",
-        "class": "invite",
+        "item": "telegram_bot",
+        "value": "_bot",
+        "class": "telegram",
         "is_public": 1,
-        "type": "string",
-        "default": "0.2",
-        "mark": "返利比例"
-    },
-    {
-        "id": null,
-        "item": "rebate_time_range_limit",
-        "value": "180",
-        "class": "invite",
-        "is_public": 0,
-        "type": "int",
-        "default": "180",
-        "mark": "返利时间范围限制(天)"
+        "type": "string",
+        "default": "_bot",
+        "mark": "Telegram 机器人账号"
     },
     {
         "id": null,
-        "item": "telegram_enable",
-        "value": "0",
+        "item": "telegram_request_token",
+        "value": "",
         "class": "telegram",
         "is_public": 0,
-        "type": "bool",
-        "default": "0",
-        "mark": "是否启用Telegram机器人"
+        "type": "string",
+        "default": "",
+        "mark": "Telegram Webhook 密钥"
     },
     {
         "id": null,
@@ -1131,243 +811,503 @@
     },
     {
         "id": null,
-        "item": "telegram_node_offline",
-        "value": "1",
-        "class": "telegram",
-        "is_public": 0,
+        "item": "telegram_node_offline",
+        "value": "1",
+        "class": "telegram",
+        "is_public": 0,
+        "type": "bool",
+        "default": "1",
+        "mark": "是否启用Telegram机器人节点离线通知"
+    },
+    {
+        "id": null,
+        "item": "telegram_node_offline_text",
+        "value": "%node_name% 出现了一些故障",
+        "class": "telegram",
+        "is_public": 0,
+        "type": "string",
+        "default": "%node_name% 出现了一些故障",
+        "mark": "Telegram机器人节点离线通知文本"
+    },
+    {
+        "id": null,
+        "item": "telegram_daily_job",
+        "value": "1",
+        "class": "telegram",
+        "is_public": 0,
+        "type": "bool",
+        "default": "1",
+        "mark": "是否启用Telegram机器人每日任务通知"
+    },
+    {
+        "id": null,
+        "item": "telegram_daily_job_text",
+        "value": "成功执行每日任务",
+        "class": "telegram",
+        "is_public": 0,
+        "type": "string",
+        "default": "成功执行每日任务",
+        "mark": "Telegram机器人每日任务通知文本"
+    },
+    {
+        "id": null,
+        "item": "telegram_diary",
+        "value": "1",
+        "class": "telegram",
+        "is_public": 0,
+        "type": "bool",
+        "default": "1",
+        "mark": "是否启用Telegram机器人系统运行状况通知"
+    },
+    {
+        "id": null,
+        "item": "telegram_diary_text",
+        "value": "今日签到人数:%getTodayCheckinUser% \n 今日使用总流量:%lastday_total%",
+        "class": "telegram",
+        "is_public": 0,
+        "type": "string",
+        "default": "今日签到人数:%getTodayCheckinUser% \n 今日使用总流量:%lastday_total%",
+        "mark": "Telegram机器人系统运行状况通知文本"
+    },
+    {
+        "id": null,
+        "item": "telegram_unbind_kick_member",
+        "value": "0",
+        "class": "telegram",
+        "is_public": 0,
+        "type": "bool",
+        "default": "0",
+        "mark": "解绑Telegram账户后自动踢出群组"
+    },
+    {
+        "id": null,
+        "item": "telegram_group_bound_user",
+        "value": "0",
+        "class": "telegram",
+        "is_public": 0,
+        "type": "bool",
+        "default": "0",
+        "mark": "是否仅允许已绑定Telegram账户的用户加入群组"
+    },
+    {
+        "id": null,
+        "item": "enable_welcome_message",
+        "value": "0",
+        "class": "telegram",
+        "is_public": 0,
+        "type": "bool",
+        "default": "0",
+        "mark": "Telegram 机器人发送欢迎消息"
+    },
+    {
+        "id": null,
+        "item": "telegram_group_quiet",
+        "value": "1",
+        "class": "telegram",
+        "is_public": 0,
+        "type": "bool",
+        "default": "1",
+        "mark": "Telegram 机器人在群组中不回应"
+    },
+    {
+        "id": null,
+        "item": "allow_to_join_new_groups",
+        "value": "0",
+        "class": "telegram",
+        "is_public": 0,
+        "type": "bool",
+        "default": "0",
+        "mark": "允许 Bot 加入下方配置之外的群组"
+    },
+    {
+        "id": null,
+        "item": "group_id_allowed_to_join",
+        "value": "[]",
+        "class": "telegram",
+        "is_public": 0,
+        "type": "array",
+        "default": "[]",
+        "mark": "允许加入的群组 ID"
+    },
+    {
+        "id": null,
+        "item": "help_any_command",
+        "value": "0",
+        "class": "telegram",
+        "is_public": 0,
+        "type": "bool",
+        "default": "0",
+        "mark": "允许任意未知的命令触发 /help 的回复"
+    },
+    {
+        "id": null,
+        "item": "user_not_bind_reply",
+        "value": "您未绑定本站账号,您可以进入网站的 **资料编辑**,在右下方绑定您的账号。",
+        "class": "telegram",
+        "is_public": 0,
+        "type": "string",
+        "default": "您未绑定本站账号,您可以进入网站的 **资料编辑**,在右下方绑定您的账号。",
+        "mark": "未绑定账户的回复"
+    },
+    {
+        "id": null,
+        "item": "discord_bot_token",
+        "value": "",
+        "class": "discord",
+        "is_public": 0,
+        "type": "string",
+        "default": "",
+        "mark": "Discord Bot Token"
+    },
+    {
+        "id": null,
+        "item": "slack_token",
+        "value": "",
+        "class": "slack",
+        "is_public": 0,
+        "type": "string",
+        "default": "",
+        "mark": "Slack App Token"
+    },
+    {
+        "id": null,
+        "item": "tawk_id",
+        "value": "",
+        "class": "support",
+        "is_public": 1,
+        "type": "string",
+        "default": "",
+        "mark": "tawk_id"
+    },
+    {
+        "id": null,
+        "item": "crisp_id",
+        "value": "",
+        "class": "support",
+        "is_public": 1,
+        "type": "string",
+        "default": "",
+        "mark": "crisp_id"
+    },
+    {
+        "id": null,
+        "item": "livechat_id",
+        "value": "",
+        "class": "support",
+        "is_public": 1,
+        "type": "string",
+        "default": "",
+        "mark": "livechat_id"
+    },
+    {
+        "id": null,
+        "item": "mylivechat_id",
+        "value": "",
+        "class": "support",
+        "is_public": 1,
+        "type": "string",
+        "default": "",
+        "mark": "mylivechat_id"
+    },
+    {
+        "id": null,
+        "item": "live_chat",
+        "value": "none",
+        "class": "support",
+        "is_public": 1,
+        "type": "string",
+        "default": "none",
+        "mark": "客服系统开关"
+    },
+    {
+        "id": null,
+        "item": "enable_ticket",
+        "value": "1",
+        "class": "support",
+        "is_public": 1,
+        "type": "bool",
+        "default": "1",
+        "mark": "启用工单系统"
+    },
+    {
+        "id": null,
+        "item": "mail_ticket",
+        "value": "1",
+        "class": "support",
+        "is_public": 0,
+        "type": "bool",
+        "default": "1",
+        "mark": "启用工单邮件提醒"
+    },
+    {
+        "id": null,
+        "item": "ticket_limit",
+        "value": "3",
+        "class": "support",
+        "is_public": 0,
+        "type": "int",
+        "default": "3",
+        "mark": "用戶工单配額(每月)"
+    },
+    {
+        "id": null,
+        "item": "reg_mode",
+        "value": "open",
+        "class": "register",
+        "is_public": 1,
+        "type": "string",
+        "default": "open",
+        "mark": "注册模式"
+    },
+    {
+        "id": null,
+        "item": "reg_email_verify",
+        "value": "0",
+        "class": "register",
+        "is_public": 1,
         "type": "bool",
-        "default": "1",
-        "mark": "是否启用Telegram机器人节点离线通知"
+        "default": "0",
+        "mark": "邮箱验证"
     },
     {
         "id": null,
-        "item": "telegram_node_offline_text",
-        "value": "%node_name% 出现了一些故障",
-        "class": "telegram",
+        "item": "reg_forbidden_ip",
+        "value": "127.0.0.0/8,::1/128",
+        "class": "register",
         "is_public": 0,
         "type": "string",
-        "default": "%node_name% 出现了一些故障",
-        "mark": "Telegram机器人节点离线通知文本"
+        "default": "127.0.0.0/8,::1/128",
+        "mark": "注册时默认禁止访问IP列表"
     },
     {
         "id": null,
-        "item": "telegram_daily_job",
-        "value": "1",
-        "class": "telegram",
+        "item": "reg_forbidden_port",
+        "value": "",
+        "class": "register",
         "is_public": 0,
-        "type": "bool",
-        "default": "1",
-        "mark": "是否启用Telegram机器人每日任务通知"
+        "type": "string",
+        "default": "",
+        "mark": "注册时默认禁止访问端口列表"
     },
     {
         "id": null,
-        "item": "telegram_daily_job_text",
-        "value": "成功执行每日任务",
-        "class": "telegram",
+        "item": "random_group",
+        "value": "0",
+        "class": "register",
         "is_public": 0,
         "type": "string",
-        "default": "成功执行每日任务",
-        "mark": "Telegram机器人每日任务通知文本"
+        "default": "0",
+        "mark": "注册时随机分配到的分组"
     },
     {
         "id": null,
-        "item": "telegram_diary",
-        "value": "1",
-        "class": "telegram",
-        "is_public": 0,
-        "type": "bool",
-        "default": "1",
-        "mark": "是否启用Telegram机器人系统运行状况通知"
+        "item": "min_port",
+        "value": "10000",
+        "class": "register",
+        "is_public": 1,
+        "type": "int",
+        "default": "10000",
+        "mark": "用户端口池最小值"
     },
     {
         "id": null,
-        "item": "telegram_diary_text",
-        "value": "今日签到人数:%getTodayCheckinUser% \n 今日使用总流量:%lastday_total%",
-        "class": "telegram",
-        "is_public": 0,
-        "type": "string",
-        "default": "今日签到人数:%getTodayCheckinUser% \n 今日使用总流量:%lastday_total%",
-        "mark": "Telegram机器人系统运行状况通知文本"
+        "item": "max_port",
+        "value": "65535",
+        "class": "register",
+        "is_public": 1,
+        "type": "int",
+        "default": "65535",
+        "mark": "用户端口池最大值"
     },
     {
         "id": null,
-        "item": "telegram_unbind_kick_member",
+        "item": "free_user_reset_day",
         "value": "0",
-        "class": "telegram",
+        "class": "register",
         "is_public": 0,
-        "type": "bool",
+        "type": "int",
         "default": "0",
-        "mark": "解绑Telegram账户后自动踢出群组"
+        "mark": "免费用戶的流量重置日"
     },
     {
         "id": null,
-        "item": "telegram_group_bound_user",
+        "item": "free_user_reset_bandwidth",
         "value": "0",
-        "class": "telegram",
+        "class": "register",
         "is_public": 0,
-        "type": "bool",
+        "type": "int",
         "default": "0",
-        "mark": "是否仅允许已绑定Telegram账户的用户加入群组"
+        "mark": "需要重置的免费流量"
     },
     {
         "id": null,
-        "item": "telegram_show_group_link",
-        "value": "0",
-        "class": "telegram",
+        "item": "sign_up_for_free_traffic",
+        "value": "20",
+        "class": "register",
         "is_public": 0,
-        "type": "bool",
-        "default": "0",
-        "mark": "是否启用Telegram机器人显示用户群组链接"
+        "type": "int",
+        "default": "20",
+        "mark": "注册时赠送的流量(GB)"
     },
     {
         "id": null,
-        "item": "telegram_group_link",
-        "value": "https://t.me/joinchat/XXXXX",
-        "class": "telegram",
+        "item": "sign_up_for_free_time",
+        "value": "365",
+        "class": "register",
         "is_public": 0,
-        "type": "string",
-        "default": "https://t.me/joinchat/XXXXX",
-        "mark": "用户群组链接"
+        "type": "int",
+        "default": "365",
+        "mark": "注册时设定的账户有效期(天)"
     },
     {
         "id": null,
-        "item": "enable_welcome_message",
+        "item": "connection_ip_limit",
         "value": "0",
-        "class": "telegram",
+        "class": "register",
         "is_public": 0,
-        "type": "bool",
+        "type": "int",
         "default": "0",
-        "mark": "Telegram 机器人发送欢迎消息"
+        "mark": "注册时设定的连接 IP 限制"
     },
     {
         "id": null,
-        "item": "telegram_group_quiet",
-        "value": "1",
-        "class": "telegram",
+        "item": "connection_rate_limit",
+        "value": "0",
+        "class": "register",
         "is_public": 0,
-        "type": "bool",
-        "default": "1",
-        "mark": "Telegram 机器人在群组中不回应"
+        "type": "int",
+        "default": "0",
+        "mark": "注册时设定的使用速率限制"
     },
     {
         "id": null,
-        "item": "allow_to_join_new_groups",
+        "item": "sign_up_for_class",
         "value": "0",
-        "class": "telegram",
+        "class": "register",
         "is_public": 0,
-        "type": "bool",
+        "type": "int",
         "default": "0",
-        "mark": "允许 Bot 加入下方配置之外的群组"
+        "mark": "注册时设定的等级"
     },
     {
         "id": null,
-        "item": "group_id_allowed_to_join",
-        "value": "[]",
-        "class": "telegram",
+        "item": "sign_up_for_class_time",
+        "value": "7",
+        "class": "register",
         "is_public": 0,
-        "type": "array",
-        "default": "[]",
-        "mark": "允许加入的群组 ID"
+        "type": "int",
+        "default": "7",
+        "mark": "注册时设定的等级过期时间(天)"
     },
     {
         "id": null,
-        "item": "telegram_admins",
-        "value": "[]",
-        "class": "telegram",
+        "item": "sign_up_for_method",
+        "value": "aes-128-gcm",
+        "class": "register",
         "is_public": 0,
-        "type": "array",
-        "default": "[]",
-        "mark": "额外的 Telegram 管理员 ID"
+        "type": "string",
+        "default": "aes-128-gcm",
+        "mark": "默认加密"
     },
     {
         "id": null,
-        "item": "enable_not_admin_reply",
+        "item": "sign_up_for_daily_report",
         "value": "0",
-        "class": "telegram",
+        "class": "register",
         "is_public": 0,
         "type": "bool",
         "default": "0",
-        "mark": "非管理员操作管理员功能是否回复"
+        "mark": "注册后是否默认接收每日用量邮件推送"
     },
     {
         "id": null,
-        "item": "not_admin_reply_msg",
-        "value": "",
-        "class": "telegram",
+        "item": "sign_up_for_invitation_codes",
+        "value": "10",
+        "class": "register",
         "is_public": 0,
-        "type": "string",
-        "default": "",
-        "mark": "非管理员操作管理员功能的回复内容"
+        "type": "int",
+        "default": "10",
+        "mark": "初始邀请注册链接使用次数限制"
     },
     {
         "id": null,
-        "item": "no_user_found",
-        "value": "",
-        "class": "telegram",
-        "is_public": 0,
-        "type": "string",
-        "default": "",
-        "mark": "管理员操作时,找不到用户的回复"
+        "item": "invitation_to_register_balance_reward",
+        "value": "1",
+        "class": "invite",
+        "is_public": 1,
+        "type": "int",
+        "default": "1",
+        "mark": "邀请注册余额奖励(元)"
     },
     {
         "id": null,
-        "item": "data_method_not_found",
-        "value": "",
-        "class": "telegram",
-        "is_public": 0,
-        "type": "string",
-        "default": "",
-        "mark": "管理员操作时,修改数据的字段没有找到的回复"
+        "item": "invitation_to_register_traffic_reward",
+        "value": "10",
+        "class": "invite",
+        "is_public": 1,
+        "type": "int",
+        "default": "10",
+        "mark": "邀请注册流量奖励(GB)"
     },
     {
         "id": null,
-        "item": "help_any_command",
-        "value": "0",
-        "class": "telegram",
+        "item": "invitation_mode",
+        "value": "after_paid",
+        "class": "invite",
         "is_public": 0,
-        "type": "bool",
-        "default": "0",
-        "mark": "允许任意未知的命令触发 /help 的回复"
+        "type": "string",
+        "default": "after_paid",
+        "mark": "邀请模式"
     },
     {
         "id": null,
-        "item": "enable_user_email_group_show",
-        "value": "0",
-        "class": "telegram",
+        "item": "invite_rebate_mode",
+        "value": "limit_amount",
+        "class": "invite",
         "is_public": 0,
-        "type": "bool",
-        "default": "0",
-        "mark": "开启在群组搜寻用户信息时显示用户完整邮箱,关闭则会对邮箱中间内容打码"
+        "type": "string",
+        "default": "limit_amount",
+        "mark": "返利模式"
     },
     {
         "id": null,
-        "item": "user_not_bind_reply",
-        "value": "您未绑定本站账号,您可以进入网站的 **资料编辑**,在右下方绑定您的账号。",
-        "class": "telegram",
+        "item": "rebate_frequency_limit",
+        "value": "3",
+        "class": "invite",
         "is_public": 0,
         "type": "string",
-        "default": "您未绑定本站账号,您可以进入网站的 **资料编辑**,在右下方绑定您的账号。",
-        "mark": "未绑定账户的回复"
+        "default": "3",
+        "mark": "返利总次数限制"
     },
     {
         "id": null,
-        "item": "telegram_general_pricing",
-        "value": "",
-        "class": "telegram",
+        "item": "rebate_amount_limit",
+        "value": "100",
+        "class": "invite",
         "is_public": 0,
+        "type": "int",
+        "default": "100",
+        "mark": "返利总金额限制"
+    },
+    {
+        "id": null,
+        "item": "rebate_ratio",
+        "value": "0.2",
+        "class": "invite",
+        "is_public": 1,
         "type": "string",
-        "default": "",
-        "mark": "面向游客的产品介绍"
+        "default": "0.2",
+        "mark": "返利比例"
     },
     {
         "id": null,
-        "item": "telegram_general_terms",
-        "value": "",
-        "class": "telegram",
+        "item": "rebate_time_range_limit",
+        "value": "180",
+        "class": "invite",
         "is_public": 0,
-        "type": "string",
-        "default": "",
-        "mark": "面向游客的服务条款"
+        "type": "int",
+        "default": "180",
+        "mark": "返利时间范围限制(天)"
     },
     {
         "id": null,

+ 67 - 74
resources/views/tabler/admin/setting/im.tpl

@@ -31,22 +31,22 @@
                     <div class="card-header">
                     <ul class="nav nav-tabs card-header-tabs" data-bs-toggle="tabs">
                         <li class="nav-item">
-                            <a href="#telegram_notification" class="nav-link active" data-bs-toggle="tab">Telegram 通知设定</a>
+                            <a href="#notification" class="nav-link active" data-bs-toggle="tab">通知设定</a>
                         </li>
                         <li class="nav-item">
-                            <a href="#telegram_bot" class="nav-link" data-bs-toggle="tab">Telegram Bot</a>
+                            <a href="#telegram" class="nav-link" data-bs-toggle="tab">Telegram Bot</a>
                         </li>
                         <li class="nav-item">
-                            <a href="#discord_bot" class="nav-link" data-bs-toggle="tab">Discord Bot</a>
+                            <a href="#discord" class="nav-link" data-bs-toggle="tab">Discord Bot</a>
                         </li>
                         <li class="nav-item">
-                            <a href="#slack_bot" class="nav-link" data-bs-toggle="tab">Slack Bot</a>
+                            <a href="#slack" class="nav-link" data-bs-toggle="tab">Slack Bot</a>
                         </li>
                     </ul>
                 </div>
                 <div class="card-body">
                     <div class="tab-content">
-                        <div class="tab-pane active show" id="telegram_notification">
+                        <div class="tab-pane active show" id="notification">
                             <div class="card-body">
                                 <div class="form-group mb-3 row">
                                     <label class="form-label col-3 col-form-label">添加节点通知</label>
@@ -185,39 +185,57 @@
                                 </div>
                             </div>
                         </div>
-                        <div class="tab-pane" id="telegram_bot">
+                        <div class="tab-pane" id="telegram">
                             <div class="card-body">
                                 <div class="form-group mb-3 row">
-                                    <label class="form-label col-3 col-form-label">解绑 Telegram 账户后自动踢出群组</label>
+                                    <label class="form-label col-3 col-form-label">是否启用 Telegram 机器人</label>
                                     <div class="col">
-                                        <select id="telegram_unbind_kick_member" class="col form-select" value="{$settings['telegram_unbind_kick_member']}">
-                                            <option value="0" {if ! $settings['telegram_unbind_kick_member']}selected{/if}>关闭</option>
-                                            <option value="1" {if $settings['telegram_unbind_kick_member']}selected{/if}>开启</option>
+                                        <select id="enable_telegram" class="col form-select" value="{$settings['enable_telegram']}">
+                                            <option value="0" {if ! $settings['enable_telegram']}selected{/if}>关闭</option>
+                                            <option value="1" {if $settings['enable_telegram']}selected{/if}>开启</option>
                                         </select>
                                     </div>
                                 </div>
                                 <div class="form-group mb-3 row">
-                                    <label class="form-label col-3 col-form-label">仅允许已绑定 Telegram 账户的用户加入群组</label>
+                                    <label class="form-label col-3 col-form-label">Bot Token</label>
                                     <div class="col">
-                                        <select id="telegram_group_bound_user" class="col form-select" value="{$settings['telegram_group_bound_user']}">
-                                            <option value="0" {if ! $settings['telegram_group_bound_user']}selected{/if}>关闭</option>
-                                            <option value="1" {if $settings['telegram_group_bound_user']}selected{/if}>开启</option>
-                                        </select>
+                                        <input id="telegram_token" type="text" class="form-control" value="{$settings['telegram_token']}">
                                     </div>
                                 </div>
                                 <div class="form-group mb-3 row">
-                                    <label class="form-label col-3 col-form-label">启用 Telegram 机器人显示用户群组链接</label>
+                                    <label class="form-label col-3 col-form-label">Telegram 群组会话 ID</label>
                                     <div class="col">
-                                        <select id="telegram_show_group_link" class="col form-select" value="{$settings['telegram_show_group_link']}">
-                                            <option value="0" {if ! $settings['telegram_show_group_link']}selected{/if}>关闭</option>
-                                            <option value="1" {if $settings['telegram_show_group_link']}selected{/if}>开启</option>
+                                        <input id="telegram_chatid" type="text" class="form-control" value="{$settings['telegram_chatid']}">
+                                    </div>
+                                </div>
+                                <div class="form-group mb-3 row">
+                                    <label class="form-label col-3 col-form-label">Telegram 机器人账号</label>
+                                    <div class="col">
+                                        <input id="telegram_bot" type="text" class="form-control" value="{$settings['telegram_bot']}">
+                                    </div>
+                                </div>
+                                <div class="form-group mb-3 row">
+                                    <label class="form-label col-3 col-form-label">Telegram Webhook 密钥</label>
+                                    <div class="col">
+                                        <input id="telegram_request_token" type="text" class="form-control" value="{$settings['telegram_request_token']}">
+                                    </div>
+                                </div>
+                                <div class="form-group mb-3 row">
+                                    <label class="form-label col-3 col-form-label">解绑 Telegram 账户后自动踢出群组</label>
+                                    <div class="col">
+                                        <select id="telegram_unbind_kick_member" class="col form-select" value="{$settings['telegram_unbind_kick_member']}">
+                                            <option value="0" {if ! $settings['telegram_unbind_kick_member']}selected{/if}>关闭</option>
+                                            <option value="1" {if $settings['telegram_unbind_kick_member']}selected{/if}>开启</option>
                                         </select>
                                     </div>
                                 </div>
                                 <div class="form-group mb-3 row">
-                                    <label class="form-label col-3 col-form-label">用户群组链接</label>
+                                    <label class="form-label col-3 col-form-label">仅允许已绑定 Telegram 账户的用户加入群组</label>
                                     <div class="col">
-                                        <input id="telegram_group_link" type="text" class="form-control" value="{$settings['telegram_group_link']}">
+                                        <select id="telegram_group_bound_user" class="col form-select" value="{$settings['telegram_group_bound_user']}">
+                                            <option value="0" {if ! $settings['telegram_group_bound_user']}selected{/if}>关闭</option>
+                                            <option value="1" {if $settings['telegram_group_bound_user']}selected{/if}>开启</option>
+                                        </select>
                                     </div>
                                 </div>
                                 <div class="form-group mb-3 row">
@@ -253,39 +271,6 @@
                                         <input id="group_id_allowed_to_join" type="text" class="form-control" value="{$settings['group_id_allowed_to_join']}">
                                     </div>
                                 </div>
-                                <div class="form-group mb-3 row">
-                                    <label class="form-label col-3 col-form-label">额外的 Telegram 管理员 ID</label>
-                                    <div class="col">
-                                        <input id="telegram_admins" type="text" class="form-control" value="{$settings['telegram_admins']}">
-                                    </div>
-                                </div>
-                                <div class="form-group mb-3 row">
-                                    <label class="form-label col-3 col-form-label">非管理员操作管理员功能是否回复</label>
-                                    <div class="col">
-                                        <select id="enable_not_admin_reply" class="col form-select" value="{$settings['enable_not_admin_reply']}">
-                                            <option value="0" {if ! $settings['enable_not_admin_reply']}selected{/if}>关闭</option>
-                                            <option value="1" {if $settings['enable_not_admin_reply']}selected{/if}>开启</option>
-                                        </select>
-                                    </div>
-                                </div>
-                                <div class="form-group mb-3 row">
-                                    <label class="form-label col-3 col-form-label">非管理员操作管理员功能的回复内容</label>
-                                    <div class="col">
-                                        <input id="not_admin_reply_msg" type="text" class="form-control" value="{$settings['not_admin_reply_msg']}">
-                                    </div>
-                                </div>
-                                <div class="form-group mb-3 row">
-                                    <label class="form-label col-3 col-form-label">管理员操作时,找不到用户的回复</label>
-                                    <div class="col">
-                                        <input id="no_user_found" type="text" class="form-control" value="{$settings['no_user_found']}">
-                                    </div>
-                                </div>
-                                <div class="form-group mb-3 row">
-                                    <label class="form-label col-3 col-form-label">管理员操作时,修改数据的字段没有找到的回复</label>
-                                    <div class="col">
-                                        <input id="data_method_not_found" type="text" class="form-control" value="{$settings['data_method_not_found']}">
-                                    </div>
-                                </div>
                                 <div class="form-group mb-3 row">
                                     <label class="form-label col-3 col-form-label">允许任意未知的命令触发 /help 的回复</label>
                                     <div class="col">
@@ -295,15 +280,6 @@
                                         </select>
                                     </div>
                                 </div>
-                                <div class="form-group mb-3 row">
-                                    <label class="form-label col-3 col-form-label">开启在群组搜寻用户信息时显示用户完整邮箱,关闭则会对邮箱中间内容打码</label>
-                                    <div class="col">
-                                        <select id="enable_user_email_group_show" class="col form-select" value="{$settings['enable_user_email_group_show']}">
-                                            <option value="0" {if ! $settings['enable_user_email_group_show']}selected{/if}>关闭</option>
-                                            <option value="1" {if $settings['enable_user_email_group_show']}selected{/if}>开启</option>
-                                        </select>
-                                    </div>
-                                </div>
                                 <div class="form-group mb-3 row">
                                     <label class="form-label col-3 col-form-label">未绑定账户的回复</label>
                                     <div class="col">
@@ -311,20 +287,17 @@
                                     </div>
                                 </div>
                                 <div class="form-group mb-3 row">
-                                    <label class="form-label col-3 col-form-label">面向游客的产品介绍</label>
-                                    <div class="col">
-                                        <input id="telegram_general_pricing" type="text" class="form-control" value="{$settings['telegram_general_pricing']}">
-                                    </div>
-                                </div>
-                                <div class="form-group mb-3 row">
-                                    <label class="form-label col-3 col-form-label">面向游客的服务条款</label>
-                                    <div class="col">
-                                        <input id="telegram_general_terms" type="text" class="form-control" value="{$settings['telegram_general_terms']}">
+                                    <label class="form-label col-3 col-form-label">Telegram 用户 ID</label>
+                                    <input type="text" class="form-control" id="telegram_user_id" value="">
+                                    <div class="row my-3">
+                                        <div class="col">
+                                            <button id="test-telegram" class="btn btn-primary">发送测试信息</button>
+                                        </div>
                                     </div>
                                 </div>
                             </div>
                         </div>
-                        <div class="tab-pane" id="discord_bot">
+                        <div class="tab-pane" id="discord">
                             <div class="card-body">
                                 <div class="form-group mb-3 row">
                                     <label class="form-label col-3 col-form-label">Bot Token</label>
@@ -343,7 +316,7 @@
                                 </div>
                             </div>
                         </div>
-                        <div class="tab-pane" id="slack_bot">
+                        <div class="tab-pane" id="slack">
                             <div class="card-body">
                                 <div class="form-group mb-3 row">
                                     <label class="form-label col-3 col-form-label">App Token</label>
@@ -392,6 +365,26 @@
         })
     });
 
+    $("#test-telegram").click(function() {
+        $.ajax({
+            url: '/admin/setting/test_telegram',
+            type: 'POST',
+            dataType: "json",
+            data: {
+                telegram_user_id: $('#telegram_user_id').val(),
+            },
+            success: function(data) {
+                if (data.ret === 1) {
+                    $('#success-noreload-message').text(data.msg);
+                    $('#success-noreload-dialog').modal('show');
+                } else {
+                    $('#fail-message').text(data.msg);
+                    $('#fail-dialog').modal('show');
+                }
+            }
+        })
+    });
+
     $("#test-discord").click(function() {
         $.ajax({
             url: '/admin/setting/test_discord',

+ 7 - 8
resources/views/tabler/user/edit.tpl

@@ -103,8 +103,7 @@
                                                     </div>
                                                     <div class="mb-3">
                                                         <input id="imvalue" type="text" class="form-control" 
-                                                            {if $user->im_type === 4} disabled="" {/if}
-                                                            value="{$user->im_value}" placeholder="社交账户">
+                                                            disabled="" value="{$user->im_value}" placeholder="社交账户">
                                                     </div>
                                                 </div>
                                                 <div class="card-footer">
@@ -131,7 +130,7 @@
                                                 </div>
                                             </div>
                                         </div>
-                                        {if $config['enable_telegram']}
+                                        {if $public_setting['enable_telegram']}
                                         <div class="col-sm-12 col-md-6">
                                             {if $user->telegram_id !== 0}
                                             <div class="card">
@@ -163,7 +162,7 @@
                                                             手机电脑平板等如已安装 Telegram 可点击
                                                         </div>
                                                         <div class="col-6 col-sm-2 col-md-2 col-sm mb-3">
-                                                            <a href="https://t.me/{$telegram_bot}?start={$bind_token}"
+                                                            <a href="https://t.me/{$public_setting['telegram_bot']}?start={$bind_token}"
                                                                 class="btn btn-primary w-100">
                                                                 一键绑定
                                                             </a>
@@ -172,7 +171,7 @@
                                                     <div class="row">
                                                         <div class="col-6 col-sm-2 col-md-2 col-xl mb-3">
                                                             向机器人 <a
-                                                                href="https://t.me/{$telegram_bot}">@{$telegram_bot}</a>
+                                                                href="https://t.me/{$public_setting['telegram_bot']}">@{$public_setting['telegram_bot']}</a>
                                                             发送验证码绑定
                                                         </div>
                                                         <div class="col-6 col-sm-2 col-md-2 col-sm mb-3">
@@ -194,18 +193,18 @@
                                         <div class="col-sm-12 col-md-6">
                                             <div class="card">
                                                 <div class="card-body">
-                                                    <h3 class="card-title">两步认证</h3>
+                                                    <h3 class="card-title">多因素认证</h3>
                                                     <div class="col-md-12">
                                                         <div class="col-sm-6 col-md-6">
                                                             <p>
                                                                 <i class="ti ti-brand-apple"></i>
                                                                 <a target="view_window"
-                                                                    href="https://apps.apple.com/us/app/google-authenticator/id388497605">苹果客户端
+                                                                    href="https://apps.apple.com/us/app/google-authenticator/id388497605">iOS 客户端
                                                                 </a>
                                                                 &nbsp;&nbsp;&nbsp;
                                                                 <i class="ti ti-brand-android"></i>
                                                                 <a target="view_window"
-                                                                    href="https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2&hl=zh&gl=US">安卓客户端
+                                                                    href="https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2">Android 客户端
                                                                 </a>
                                                             </p>
                                                         </div>

+ 2 - 2
src/Command/Tool.php

@@ -72,8 +72,8 @@ EOL;
      */
     public function setTelegram(): void
     {
-        $WebhookUrl = $_ENV['baseUrl'] . '/telegram_callback?token=' . $_ENV['telegram_request_token'];
-        $telegram = new Api($_ENV['telegram_token']);
+        $WebhookUrl = $_ENV['baseUrl'] . '/telegram_callback?token=' . Setting::obtain('telegram_request_token');
+        $telegram = new Api(Setting::obtain('telegram_token'));
         $telegram->removeWebhook();
 
         if ($telegram->setWebhook(['url' => $WebhookUrl])) {

+ 3 - 2
src/Controllers/Admin/AnnController.php

@@ -6,6 +6,7 @@ namespace App\Controllers\Admin;
 
 use App\Controllers\BaseController;
 use App\Models\Ann;
+use App\Models\Setting;
 use App\Models\User;
 use App\Services\IM\Telegram;
 use App\Utils\Tools;
@@ -113,7 +114,7 @@ final class AnnController extends BaseController
             }
         }
 
-        if ($_ENV['enable_telegram']) {
+        if (Setting::obtain('enable_telegram')) {
             try {
                 (new Telegram())->sendHtml('新公告:' . PHP_EOL . $content);
             } catch (TelegramSDKException $e) {
@@ -163,7 +164,7 @@ final class AnnController extends BaseController
             ]);
         }
 
-        if ($_ENV['enable_telegram']) {
+        if (Setting::obtain('enable_telegram')) {
             try {
                 (new Telegram())->sendHtml('公告更新:' . PHP_EOL . $request->getParam('content'));
             } catch (TelegramSDKException $e) {

+ 26 - 10
src/Controllers/Admin/Setting/ImController.php

@@ -8,6 +8,7 @@ use App\Controllers\BaseController;
 use App\Models\Setting;
 use App\Services\IM\Discord;
 use App\Services\IM\Slack;
+use App\Services\IM\Telegram;
 use Exception;
 use GuzzleHttp\Exception\GuzzleException;
 use function json_encode;
@@ -15,6 +16,11 @@ use function json_encode;
 final class ImController extends BaseController
 {
     public static array $update_field = [
+        'enable_telegram',
+        'telegram_token',
+        'telegram_chatid',
+        'telegram_bot',
+        'telegram_request_token',
         'telegram_add_node',
         'telegram_add_node_text',
         'telegram_update_node',
@@ -35,22 +41,12 @@ final class ImController extends BaseController
         'telegram_diary_text',
         'telegram_unbind_kick_member',
         'telegram_group_bound_user',
-        'telegram_show_group_link',
-        'telegram_group_link',
         'enable_welcome_message',
         'telegram_group_quiet',
         'allow_to_join_new_groups',
         'group_id_allowed_to_join',
-        'telegram_admins',
-        'enable_not_admin_reply',
-        'not_admin_reply_msg',
-        'no_user_found',
-        'data_method_not_found',
         'help_any_command',
-        'enable_user_email_group_show',
         'user_not_bind_reply',
-        'telegram_general_pricing',
-        'telegram_general_terms',
         'discord_bot_token',
         'slack_token',
     ];
@@ -106,6 +102,26 @@ final class ImController extends BaseController
         ]);
     }
 
+    public function testTelegram($request, $response, $args)
+    {
+        try {
+            (new Telegram())->send(
+                $request->getParam('telegram_user_id'),
+                '这是一条测试消息',
+            );
+        } catch (GuzzleException|Exception $e) {
+            return $response->withJson([
+                'ret' => 0,
+                'msg' => '测试信息发送失败 ' . $e->getMessage(),
+            ]);
+        }
+
+        return $response->withJson([
+            'ret' => 1,
+            'msg' => '测试信息发送成功',
+        ]);
+    }
+
     public function testDiscord($request, $response, $args)
     {
         try {

+ 2 - 1
src/Controllers/HomeController.php

@@ -4,6 +4,7 @@ declare(strict_types=1);
 
 namespace App\Controllers;
 
+use App\Models\Setting;
 use App\Services\Auth;
 use App\Utils\Telegram\Process;
 use Exception;
@@ -81,7 +82,7 @@ final class HomeController extends BaseController
     {
         $token = $request->getQueryParam('token');
 
-        if ($_ENV['enable_telegram'] && $token === $_ENV['telegram_request_token']) {
+        if (Setting::obtain('enable_telegram') && $token === Setting::obtain('telegram_request_token')) {
             Process::index($request);
             $result = '1';
         } else {

+ 2 - 3
src/Controllers/User/InfoController.php

@@ -38,7 +38,7 @@ final class InfoController extends BaseController
     public function index(ServerRequest $request, Response $response, array $args): Response|ResponseInterface
     {
         $themes = Tools::getDir(BASE_PATH . '/resources/views');
-        $bind_token = TelegramTools::addBindSession($this->user);
+        $bind_token = $this->user->telegram_id === 0 ? TelegramTools::addBindSession($this->user) : '';
         $methods = Config::getSupportParam('method');
         $gaurl = MFA::getGaUrl($this->user);
 
@@ -48,7 +48,6 @@ final class InfoController extends BaseController
             ->assign('bind_token', $bind_token)
             ->assign('methods', $methods)
             ->assign('gaurl', $gaurl)
-            ->assign('telegram_bot', $_ENV['telegram_bot'])
             ->registerClass('Config', Config::class)
             ->fetch('user/edit.tpl'));
     }
@@ -217,7 +216,7 @@ final class InfoController extends BaseController
 
         $user = $this->user;
 
-        if ($value === 2 && ! $_ENV['enable_telegram']) {
+        if ($value === 2 && ! Setting::obtain('enable_telegram')) {
             return ResponseHelper::error(
                 $response,
                 '修改失败,当前无法使用 Telegram 接收每日报告'

+ 2 - 2
src/Models/User.php

@@ -348,7 +348,7 @@ final class User extends Model
         $this->telegram_id = 0;
 
         if ($this->save()) {
-            if ($_ENV['enable_telegram']
+            if (Setting::obtain('enable_telegram')
                 &&
                 Setting::obtain('telegram_group_bound_user')
                 &&
@@ -359,7 +359,7 @@ final class User extends Model
                 TelegramTools::SendPost(
                     'kickChatMember',
                     [
-                        'chat_id' => $_ENV['telegram_chatid'],
+                        'chat_id' => Setting::obtain('telegram_chatid'),
                         'user_id' => $telegram_id,
                     ]
                 );

+ 0 - 3
src/Services/Config.php

@@ -23,9 +23,6 @@ final class Config
             'enable_kill' => $_ENV['enable_kill'],
             'enable_change_email' => $_ENV['enable_change_email'],
 
-            'enable_telegram' => $_ENV['enable_telegram'],
-            'telegram_bot' => $_ENV['telegram_bot'],
-
             'subscribeLog' => $_ENV['subscribeLog'],
             'subscribeLog_keep_days' => $_ENV['subscribeLog_keep_days'],
 

+ 6 - 5
src/Services/IM/Telegram.php

@@ -4,6 +4,7 @@ declare(strict_types=1);
 
 namespace App\Services\IM;
 
+use App\Models\Setting;
 use Telegram\Bot\Api;
 use Telegram\Bot\Exceptions\TelegramSDKException;
 use function strip_tags;
@@ -17,7 +18,7 @@ final class Telegram extends Base
      */
     public function __construct()
     {
-        $this->bot = new Api($_ENV['telegram_token'], $async);
+        $this->bot = new Api(Setting::obtain('telegram_token'), $async);
     }
 
     /**
@@ -28,7 +29,7 @@ final class Telegram extends Base
     public function send($to = 0, $msg = ''): void
     {
         if ($to === 0) {
-            $to = $_ENV['telegram_chatid'];
+            $to = Setting::obtain('telegram_chatid');
         }
 
         $sendMessage = [
@@ -51,7 +52,7 @@ final class Telegram extends Base
     public function sendHtml($to = 0, $msg = ''): void
     {
         if ($to === 0) {
-            $to = $_ENV['telegram_chatid'];
+            $to = Setting::obtain('telegram_chatid');
         }
 
         $sendMessage = [
@@ -79,7 +80,7 @@ final class Telegram extends Base
     public function sendMarkdown($to = 0, $msg = ''): void
     {
         if ($to === 0) {
-            $to = $_ENV['telegram_chatid'];
+            $to = Setting::obtain('telegram_chatid');
         }
 
         $sendMessage = [
@@ -102,7 +103,7 @@ final class Telegram extends Base
     public function sendMarkdownV2($to = 0, $msg = ''): void
     {
         if ($to === 0) {
-            $to = $_ENV['telegram_chatid'];
+            $to = Setting::obtain('telegram_chatid');
         }
 
         $sendMessage = [

+ 2 - 93
src/Utils/Telegram/Callback.php

@@ -95,36 +95,7 @@ final class Callback
         if (str_starts_with($this->CallbackData, 'user.')) {
             // 用户相关
             $this->userCallback();
-            return;
         }
-        //游客回调数据处理
-        $this->guestCallback();
-    }
-
-    /**
-     * 游客的回复
-     *
-     * @return array
-     */
-    public static function getGuestIndexKeyboard(): array
-    {
-        $Keyboard = [
-            [
-                [
-                    'text' => '产品介绍',
-                    'callback_data' => 'general.pricing',
-                ],
-                [
-                    'text' => '服务条款',
-                    'callback_data' => 'general.terms',
-                ],
-            ],
-        ];
-        $text = '游客你好,以下是 BOT 菜单:' . PHP_EOL . PHP_EOL . '本站用户请前往用户中心进行 Telegram 绑定操作。';
-        return [
-            'text' => $text,
-            'keyboard' => $Keyboard,
-        ];
     }
 
     /**
@@ -174,60 +145,6 @@ final class Callback
         TelegramTools::sendPost('answerCallbackQuery', $sendMessage);
     }
 
-    /**
-     * 回调数据处理
-     *
-     * @throws TelegramSDKException
-     */
-    public function guestCallback(): void
-    {
-        $CallbackDataExplode = explode('|', $this->CallbackData);
-        switch ($CallbackDataExplode[0]) {
-            case 'general.pricing':
-                // 产品介绍
-                $sendMessage = [
-                    'text' => Setting::obtain('telegram_general_pricing'),
-                    'disable_web_page_preview' => false,
-                    'reply_to_message_id' => null,
-                    'reply_markup' => json_encode(
-                        [
-                            'inline_keyboard' => self::getGuestIndexKeyboard()['keyboard'],
-                        ]
-                    ),
-                ];
-                break;
-            case 'general.terms':
-                // 服务条款
-                $sendMessage = [
-                    'text' => Setting::obtain('telegram_general_terms'),
-                    'disable_web_page_preview' => false,
-                    'reply_to_message_id' => null,
-                    'reply_markup' => json_encode(
-                        [
-                            'inline_keyboard' => self::getGuestIndexKeyboard()['keyboard'],
-                        ]
-                    ),
-                ];
-                break;
-            default:
-                // 主菜单
-                $temp = self::getGuestIndexKeyboard();
-                $sendMessage = [
-                    'text' => $temp['text'],
-                    'disable_web_page_preview' => false,
-                    'reply_to_message_id' => null,
-                    'reply_markup' => json_encode(
-                        [
-                            'inline_keyboard' => $temp['keyboard'],
-                        ]
-                    ),
-                ];
-                break;
-        }
-
-        $this->replyWithMessage($sendMessage);
-    }
-
     public static function getUserIndexKeyboard($user): array
     {
         $checkin = (! $user->isAbleToCheckin() ? '已签到' : '签到');
@@ -262,14 +179,7 @@ final class Callback
         $text = Reply::getUserTitle($user);
         $text .= PHP_EOL . PHP_EOL;
         $text .= Reply::getUserInfo($user);
-        if (Setting::obtain('telegram_show_group_link')) {
-            $Keyboard[] = [
-                [
-                    'text' => '加入用户群',
-                    'url' => Setting::obtain('telegram_group_link'),
-                ],
-            ];
-        }
+
         return [
             'text' => $text,
             'keyboard' => $Keyboard,
@@ -292,7 +202,6 @@ final class Callback
                     'show_alert' => true,
                 ]);
             }
-            $this->guestCallback();
         }
         $CallbackDataExplode = explode('|', $this->CallbackData);
         $Operate = explode('.', $CallbackDataExplode[0]);
@@ -776,7 +685,7 @@ final class Callback
                 TelegramTools::sendPost(
                     'unbanChatMember',
                     [
-                        'chat_id' => $_ENV['telegram_chatid'],
+                        'chat_id' => Setting::obtain('telegram_chatid'),
                         'user_id' => $this->triggerUser['id'],
                     ]
                 );

+ 1 - 1
src/Utils/Telegram/Commands/CheckinCommand.php

@@ -40,7 +40,7 @@ final class CheckinCommand extends Command
                 // 群组中不回应
                 return null;
             }
-            if ($ChatID !== $_ENV['telegram_chatid']) {
+            if ($ChatID !== Setting::obtain('telegram_chatid')) {
                 // 非我方群组
                 return null;
             }

+ 7 - 2
src/Utils/Telegram/Commands/HelpCommand.php

@@ -27,20 +27,25 @@ final class HelpCommand extends Command
     {
         $Update = $this->getUpdate();
         $Message = $Update->getMessage();
+
         if ($Message->getChat()->getId() < 0 && Setting::obtain('telegram_group_quiet')) {
             return;
         }
-        if (! preg_match('/^\/help\s?(@' . $_ENV['telegram_bot'] . ')?.*/i', $Message->getText()) &&
-            Setting::obtain('help_any_command') === false) {
+
+        if (! preg_match('/^\/help\s?(@' . Setting::obtain('telegram_bot') . ')?.*/i', $Message->getText()) &&
+            ! Setting::obtain('help_any_command')) {
             return;
         }
+
         $this->replyWithChatAction(['action' => Actions::TYPING]);
         $commands = $this->telegram->getCommands();
         $text = '系统中可用的所有命令.';
         $text .= PHP_EOL . PHP_EOL;
+
         foreach ($commands as $name => $handler) {
             $text .= '/' . $name . PHP_EOL . '`    - ' . $handler->getDescription() . '`' . PHP_EOL;
         }
+
         $this->replyWithMessage(
             [
                 'text' => $text,

+ 0 - 96
src/Utils/Telegram/Commands/InfoCommand.php

@@ -1,96 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace App\Utils\Telegram\Commands;
-
-use App\Models\Setting;
-use App\Models\User;
-use App\Utils\Telegram\Reply;
-use App\Utils\Telegram\TelegramTools;
-use Telegram\Bot\Actions;
-use Telegram\Bot\Commands\Command;
-use function in_array;
-use function json_decode;
-
-/**
- * Class InfoCommand.
- */
-final class InfoCommand extends Command
-{
-    /**
-     * @var string Command Name
-     */
-    protected string $name = 'info';
-
-    /**
-     * @var string Command Description
-     */
-    protected string $description = '[群组]     获取被回复消息的用户信息,管理员命令.';
-
-    public function handle(): void
-    {
-        $Update = $this->getUpdate();
-        $Message = $Update->getMessage();
-
-        // 消息会话 ID
-        $ChatID = $Message->getChat()->getId();
-
-        // 消息 ID
-        $MessageID = $Message->getMessageId();
-
-        if ($ChatID < 0) {
-            // 发送 '输入中' 会话状态
-            $this->replyWithChatAction(['action' => Actions::TYPING]);
-            // 触发用户
-            $SendUser = [
-                'id' => $Message->getFrom()->getId(),
-            ];
-            if (! in_array($SendUser['id'], json_decode(Setting::obtain('telegram_admins')))) {
-                $AdminUser = User::where('is_admin', 1)->where('telegram_id', $SendUser['id'])->first();
-                if ($AdminUser === null) {
-                    // 非管理员回复消息
-                    if (Setting::obtain('enable_not_admin_reply') && Setting::obtain('not_admin_reply_msg') !== '') {
-                        $this->replyWithMessage(
-                            [
-                                'text' => Setting::obtain('not_admin_reply_msg'),
-                                'parse_mode' => 'HTML',
-                                'reply_to_message_id' => $MessageID,
-                            ]
-                        );
-                    }
-                    return;
-                }
-            }
-            if ($Message->getReplyToMessage() !== null) {
-                // 回复源消息用户
-                $FindUser = [
-                    'id' => $Message->getReplyToMessage()->getFrom()->getId(),
-                ];
-                $User = TelegramTools::getUser($FindUser['id']);
-                if ($User === null) {
-                    $this->replyWithMessage(
-                        [
-                            'text' => Setting::obtain('no_user_found'),
-                            'reply_to_message_id' => $MessageID,
-                        ]
-                    );
-                } else {
-                    $this->replyWithMessage(
-                        [
-                            'text' => Reply::getUserInfoFromAdmin($User, $ChatID),
-                            'reply_to_message_id' => $MessageID,
-                        ]
-                    );
-                }
-            } else {
-                $this->replyWithMessage(
-                    [
-                        'text' => '请回复消息使用.',
-                        'reply_to_message_id' => $MessageID,
-                    ]
-                );
-            }
-        }
-    }
-}

+ 1 - 1
src/Utils/Telegram/Commands/MenuCommand.php

@@ -49,7 +49,7 @@ final class MenuCommand extends Command
 
             $user = TelegramTools::getUser($SendUser['id']);
             if ($user === null) {
-                $reply = Callback::getGuestIndexKeyboard();
+                $reply = null;
             } else {
                 $reply = Callback::getUserIndexKeyboard($user);
             }

+ 1 - 1
src/Utils/Telegram/Commands/MyCommand.php

@@ -45,7 +45,7 @@ final class MyCommand extends Command
                 // 群组中不回应
                 return null;
             }
-            if ($ChatID !== $_ENV['telegram_chatid']) {
+            if ($ChatID !== Setting::obtain('telegram_chatid')) {
                 // 非我方群组
                 return null;
             }

+ 2 - 15
src/Utils/Telegram/Message.php

@@ -8,7 +8,6 @@ use App\Models\Setting;
 use RedisException;
 use Telegram\Bot\Api;
 use Telegram\Bot\Exceptions\TelegramSDKException;
-use function count;
 use function in_array;
 use function json_decode;
 use function strlen;
@@ -138,7 +137,7 @@ final class Message
             'name' => $NewChatMember->getFirstName() . ' ' . $NewChatMember->getLastName(),
         ];
 
-        if ($NewChatMember->getUsername() === $_ENV['telegram_bot']) {
+        if ($NewChatMember->getUsername() === Setting::obtain('telegram_bot')) {
             // 机器人加入新群组
             if (! Setting::obtain('allow_to_join_new_groups')
                 &&
@@ -158,18 +157,6 @@ final class Message
                         'user_id' => $Member['id'],
                     ]
                 );
-
-                if (count(json_decode(Setting::obtain('telegram_admins'))) >= 1) {
-                    foreach (json_decode(Setting::obtain('telegram_admins')) as $id) {
-                        $this->bot->sendMessage(
-                            [
-                                'text' => '根据你的设定,Bot 退出了一个群组.' . PHP_EOL .
-                                    '群组名称:' . $this->Message->getChat()->getTitle(),
-                                'chat_id' => $id,
-                            ]
-                        );
-                    }
-                }
             } else {
                 $this->replyWithMessage(
                     [
@@ -183,7 +170,7 @@ final class Message
 
             if (Setting::obtain('telegram_group_bound_user')
                 &&
-                $this->ChatID === $_ENV['telegram_chatid']
+                $this->ChatID === Setting::obtain('telegram_chatid')
                 &&
                 $NewUser === null
                 &&

+ 2 - 2
src/Utils/Telegram/Process.php

@@ -4,6 +4,7 @@ declare(strict_types=1);
 
 namespace App\Utils\Telegram;
 
+use App\Models\Setting;
 use MaxMind\Db\Reader\InvalidDatabaseException;
 use Psr\Http\Message\RequestInterface;
 use RedisException;
@@ -19,12 +20,11 @@ final class Process
      */
     public static function index(RequestInterface $request): void
     {
-        $bot = new Api($_ENV['telegram_token']);
+        $bot = new Api(Setting::obtain('telegram_token'));
 
         $bot->addCommands([
             new Commands\MyCommand(),
             new Commands\HelpCommand(),
-            new Commands\InfoCommand(),
             new Commands\MenuCommand(),
             new Commands\PingCommand(),
             new Commands\StartCommand(),

+ 0 - 19
src/Utils/Telegram/Reply.php

@@ -51,23 +51,4 @@ final class Reply
         }
         return $text;
     }
-
-    /**
-     * [admin]获取用户信息
-     */
-    public static function getUserInfoFromAdmin(User $user, int $ChatID): string
-    {
-        $strArray = [
-            '#' . $user->id . ' ' . $user->user_name . ' 的用户信息',
-            '',
-            '用户邮箱:' . TelegramTools::getUserEmail($user->email, $ChatID),
-            '账户余额:' . $user->money,
-            '账户状态:' . ((int) $user->is_banned === 1 ? '封禁' : '正常'),
-            '用户等级:' . $user->class,
-            '剩余流量:' . $user->unusedTraffic(),
-            '等级到期:' . $user->class_expire,
-            '账户到期:' . $user->expire_in,
-        ];
-        return implode(PHP_EOL, $strArray);
-    }
 }

+ 1 - 23
src/Utils/Telegram/TelegramTools.php

@@ -15,9 +15,6 @@ use function curl_exec;
 use function curl_init;
 use function curl_setopt;
 use function json_encode;
-use function str_pad;
-use function strpos;
-use function substr;
 use const CURLOPT_HTTPHEADER;
 use const CURLOPT_POST;
 use const CURLOPT_POSTFIELDS;
@@ -46,7 +43,7 @@ final class TelegramTools
      */
     public static function sendPost($Method, $Params): void
     {
-        $URL = 'https://api.telegram.org/bot' . $_ENV['telegram_token'] . '/' . $Method;
+        $URL = 'https://api.telegram.org/bot' . Setting::obtain('telegram_token') . '/' . $Method;
         $POSTData = json_encode($Params);
         $C = curl_init();
         curl_setopt($C, CURLOPT_URL, $URL);
@@ -58,25 +55,6 @@ final class TelegramTools
         curl_close($C);
     }
 
-    /**
-     * 获取用户邮箱
-     *
-     * @param string $email  邮箱
-     * @param int    $ChatID 会话 ID
-     */
-    public static function getUserEmail(string $email, int $ChatID): string
-    {
-        if (Setting::obtain('enable_user_email_group_show') || $ChatID > 0) {
-            return $email;
-        }
-        $a = strpos($email, '@');
-        if ($a === false) {
-            return $email;
-        }
-        $string = substr($email, $a);
-        return $a === 1 ? '*' . $string : substr($email, 0, 1) . str_pad('', $a - 1, '*') . $string;
-    }
-
     /**
      * @param $token
      *

+ 0 - 6
tests/App/Services/ConfigTest.php

@@ -24,8 +24,6 @@ class ConfigTest extends TestCase
             'enable_analytics_code' => false,
             'enable_kill' => true,
             'enable_change_email' => false,
-            'enable_telegram' => true,
-            'telegram_bot' => 'my_bot',
             'subscribeLog' => true,
             'subscribeLog_keep_days' => 30,
             'enable_r2_client_download' => true,
@@ -42,8 +40,6 @@ class ConfigTest extends TestCase
             'enable_analytics_code' => false,
             'enable_kill' => true,
             'enable_change_email' => false,
-            'enable_telegram' => true,
-            'telegram_bot' => 'my_bot',
             'subscribeLog' => true,
             'subscribeLog_keep_days' => 30,
             'enable_r2_client_download' => true,
@@ -61,8 +57,6 @@ class ConfigTest extends TestCase
         $this->assertSame($mockEnv['enable_analytics_code'], $config['enable_analytics_code']);
         $this->assertSame($mockEnv['enable_kill'], $config['enable_kill']);
         $this->assertSame($mockEnv['enable_change_email'], $config['enable_change_email']);
-        $this->assertSame($mockEnv['enable_telegram'], $config['enable_telegram']);
-        $this->assertSame($mockEnv['telegram_bot'], $config['telegram_bot']);
         $this->assertSame($mockEnv['subscribeLog'], $config['subscribeLog']);
         $this->assertSame($mockEnv['subscribeLog_keep_days'], $config['subscribeLog_keep_days']);
         $this->assertSame($mockEnv['enable_r2_client_download'], $config['enable_r2_client_download']);