Fix linking between telegram username and telegram id

This commit is contained in:
t1amak
2025-05-30 13:31:06 +00:00
parent 12bcaa60bb
commit 02dce3692e

View File

@@ -146,28 +146,38 @@ class SalviumTipBotCommands {
$recipient = $this->db->getUserByUsername($cleanUsername); $recipient = $this->db->getUserByUsername($cleanUsername);
// If recipient not known, create placeholder // If recipient not known, create placeholder
if (!$recipient) { if (!$recipient) {
$syntheticId = 100000 + (crc32($cleanUsername) % 900000);// Use a consistent pseudo-ID $syntheticId = 100000 + (crc32($cleanUsername) % 900000);
$subaddress = $this->wallet->getNewSubaddress(); $subaddress = $this->wallet->getNewSubaddress();
if (!$subaddress) { if (!$subaddress) {
return "Failed to create deposit address for {$cleanUsername}."; return "Failed to create deposit address for {$cleanUsername}.";
} }
$existing = $this->db->getUserByTelegramId($syntheticId); $existing = $this->db->getUserByTelegramId($syntheticId);
if (!$existing) { if (!$existing) {
if (!$this->db->createUser($syntheticId, $subaddress)) { if (!$this->db->createUser($syntheticId, $subaddress)) {
return "Failed to create recipient account for {$cleanUsername}."; return "Failed to create recipient account for {$cleanUsername}.";
} }
$this->db->updateUsername($syntheticId, $cleanUsername);
} }
// Ensure username is correct (could be NULL in DB even if user exists)
$this->db->updateUsername($syntheticId, $cleanUsername);
// Now safely fetch the recipient
$recipient = $this->db->getUserByUsername($cleanUsername); $recipient = $this->db->getUserByUsername($cleanUsername);
// Send a message to the group telling recipient to DM bot // Notify group
sendMessage($ctx['chat_id'], "Hey @$cleanUsername, you just got a tip from @$ctx[username]!"); sendMessage($ctx['chat_id'], "Hey @$cleanUsername, you just got a tip from @$ctx[username]!");
sendGif($ctx['chat_id'], 'CgACAgQAAxkBAAOQaDjcu6ftEKHp3ZCCKX8p6hTkqxEAAtYaAAL4YMlR4yZwk_GMuWg2BA', "DM me and run /claim to receive it."); sendGif(
$ctx['chat_id'],
'CgACAgQAAxkBAAOQaDjcu6ftEKHp3ZCCKX8p6hTkqxEAAtYaAAL4YMlR4yZwk_GMuWg2BA',
"DM me and run /claim to receive it."
);
} }
$this->db->updateUserTipBalance($sender['id'], $amount, 'subtract'); $this->db->updateUserTipBalance($sender['id'], $amount, 'subtract');
$this->db->addTip($sender['id'], $recipient['id'], $amount, $ctx['chat_id']); $this->db->addTip($sender['id'], $recipient['id'], $amount, $ctx['chat_id']);