db = $db; $this->wallet = $wallet; } public function handle(string $command, array $args, array $context): void { $method = 'cmd_' . ltrim($command, '/'); if (method_exists($this, $method)) { $response = $this->$method($args, $context); } else { //$response = "Unknown command."; $response = ""; } sendMessage($context['chat_id'], $response); $this->db->logMessage($context['chat_id'], $context['chat_name'], $context['username'], $context['raw'], $response); } private function cmd_start(array $args, array $ctx): string { if (!empty($ctx['username'])) { $this->db->updateUsername($ctx['user_id'], $ctx['username']); } return "Welcome to the Salvium Tip Bot! Use /deposit to get started."; } private function cmd_deposit(array $args, array $ctx): string { $user = $this->db->getUserByTelegramId($ctx['user_id']); if (!$user) { $sub = $this->wallet->getNewSubaddress(); if (!$sub) return "Error generating subaddress."; $this->db->createUser($ctx['user_id'], $sub); if (!empty($ctx['username'])) { $this->db->updateUsername($ctx['user_id'], $ctx['username']); } return "Your deposit address: $sub"; } return "Your deposit address: {$user['salvium_subaddress']}"; } private function cmd_balance(array $args, array $ctx): string { $user = $this->db->getUserByTelegramId($ctx['user_id']); return $user ? "Your balance: {$user['tip_balance']} SAL" : "No account found. Use /deposit first."; } private function cmd_withdraw(array $args, array $ctx): string { if (count($args) < 3) return "Usage: /withdraw