15m44z 第三部分续:匿名工单回复去玩家名 + token 保留 + 匿名开关 UI
匿名工单(gh_issue_owner=bot)回复/撤单/完结不再在 GitHub 评论写提单人名字; ghSyncReply 按 gh_issue_owner 判:bot 单省略 [sender] 标签,实名单保留; ticketReply 加 guard:bot 单+玩家 token 不匹配时静默跳过评论推送; gh_cfg.php:切匿名模式时玩家 OAuth token 保留(gh_authorized 兜底 true); player.php:匿名开时授权按钮改保留授权不隐藏,匿名关恢复重新授权。
This commit is contained in:
+26
-4
@@ -317,16 +317,21 @@ function ghSyncCreate($ticketId, $player, $title, $description, $images = [], $t
|
||||
/**
|
||||
* PHP 回复工单 → GitHub issue 评论。
|
||||
* 评论正文带前缀 [工单#id] 防 Webhook 回推循环。
|
||||
* 15m44z 第三部分:按 gh_issue_owner 匿名/实名派发——
|
||||
* bot 建的单 → 评论不写提单人名字(匿名工单,提单信息只记 PHP 后台);
|
||||
* 实名单 → 评论带 [玩家名] 角色标记(提单人是本人,公开无妨)。
|
||||
*/
|
||||
function ghSyncReply($ticketId, $message, $token, $sender) {
|
||||
$cfg = ghGetCfg();
|
||||
if (!$cfg['gh_enabled']) return false;
|
||||
if ($token === '') return false;
|
||||
$repo = $cfg['gh_repo'];
|
||||
// 先查 gh_issue_number
|
||||
// 先查 gh_issue_number + gh_issue_owner(一条 SQL 取回,省一次 DB 查询)
|
||||
$issueNo = '';
|
||||
$owner = '';
|
||||
try {
|
||||
$db = getDB();
|
||||
$st = $db->prepare("SELECT gh_issue_number FROM web_tickets WHERE id = :id");
|
||||
$st = $db->prepare("SELECT gh_issue_number, gh_issue_owner FROM web_tickets WHERE id = :id");
|
||||
$st->bindValue(':id', $ticketId, SQLITE3_INTEGER);
|
||||
$row = $st->execute()->fetchArray(SQLITE3_ASSOC);
|
||||
if (!$row || empty($row['gh_issue_number'])) {
|
||||
@@ -334,12 +339,29 @@ function ghSyncReply($ticketId, $message, $token, $sender) {
|
||||
return false;
|
||||
}
|
||||
$issueNo = (string)$row['gh_issue_number'];
|
||||
$owner = isset($row['gh_issue_owner']) ? (string)$row['gh_issue_owner'] : '';
|
||||
} catch (\Throwable $e) {
|
||||
ghLog('read gh_issue_number: ' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
// 评论带前缀 + 角色标记(Webhook 识别前缀跳过;角色标记供 UI 区分 玩家/管理/服务商)
|
||||
$body = GH_TICKET_PREFIX . $ticketId . '][' . $sender . '] ' . $message;
|
||||
// 15m44z 第三部分:按 issue 归属判定是否写提单人名字。
|
||||
// - gh_issue_owner = 'bot'(匿名工单)→ 不写 [sender] 标签,避免暴露提单人身份。
|
||||
// 提单人信息只记 PHP 后台 web_tickets.requester,仅管理员可见。
|
||||
// - gh_issue_owner = 'realname'(实名工单)→ 写 [玩家名] 角色标记(提单人是本人)。
|
||||
// - 老工单未记录 → 按 token 前缀判定:ghs_=bot 不写,gho_/ghp_=实名写。
|
||||
$isAnonComment = ($owner === 'bot');
|
||||
if ($isAnonComment === false && $owner === '') {
|
||||
// 老工单未记录归属 → 按 token 前缀兜底判定
|
||||
$isAnonComment = (strpos((string)$token, 'ghs_') === 0);
|
||||
}
|
||||
// 构造评论正文
|
||||
if ($isAnonComment) {
|
||||
// 匿名单:只写工单 ID 前缀 + 正文,不写提单人名字
|
||||
$body = GH_TICKET_PREFIX . $ticketId . '] ' . $message;
|
||||
} else {
|
||||
// 实名单:写 [工单#id][玩家名] 角色标记
|
||||
$body = GH_TICKET_PREFIX . $ticketId . '][' . $sender . '] ' . $message;
|
||||
}
|
||||
$r = ghApiRequest('POST', '/repos/' . $repo . '/issues/' . $issueNo . '/comments', ['body' => $body], $token);
|
||||
if (!$r['ok']) ghLog('issue comment failed: ' . $r['msg']);
|
||||
return $r['ok'];
|
||||
|
||||
Reference in New Issue
Block a user