Restrict most commands to DM only. Allow tip command everywhere.
This commit is contained in:
@@ -28,6 +28,7 @@ $command = strtolower($args[0] ?? '');
|
||||
$context = [
|
||||
'chat_id' => $message['chat']['id'],
|
||||
'chat_name' => $message['chat']['title'] ?? $message['chat']['first_name'] ?? '',
|
||||
'chat_type' => $message['chat']['type'],
|
||||
'username' => $message['from']['username'] ?? '',
|
||||
'user_id' => (int) $message['from']['id'],
|
||||
'raw' => $message['text'] ?? '',
|
||||
|
||||
@@ -6,6 +6,13 @@ class SalviumTipBotCommands {
|
||||
private SalviumTipBotDB $db;
|
||||
private SalviumWallet $wallet;
|
||||
private array $config;
|
||||
private array $commandAccess = [
|
||||
'start' => ['private'],
|
||||
'deposit' => ['private'],
|
||||
'withdraw' => ['private'],
|
||||
'balance' => ['private'],
|
||||
'tip' => ['private', 'group', 'supergroup'],
|
||||
];
|
||||
|
||||
public function __construct(SalviumTipBotDB $db, SalviumWallet $wallet, array $config) {
|
||||
$this->db = $db;
|
||||
@@ -15,14 +22,24 @@ class SalviumTipBotCommands {
|
||||
|
||||
public function handle(string $command, array $args, array $context): void {
|
||||
$method = 'cmd_' . ltrim($command, '/');
|
||||
|
||||
$cmdKey = ltrim($command, '/');
|
||||
$allowedChats = $this->commandAccess[$cmdKey] ?? [];
|
||||
|
||||
if (!in_array($context['chat_type'], $allowedChats)) {
|
||||
return; // not allowed
|
||||
}
|
||||
|
||||
if (method_exists($this, $method)) {
|
||||
$response = $this->$method($args, $context);
|
||||
} else {
|
||||
//$response = "Unknown command.";
|
||||
$response = "";
|
||||
$response = ""; // Optional fallback
|
||||
}
|
||||
|
||||
if ($response) {
|
||||
sendMessage($context['chat_id'], $response);
|
||||
}
|
||||
|
||||
sendMessage($context['chat_id'], $response);
|
||||
$this->db->logMessage($context['chat_id'], $context['chat_name'], $context['username'], $context['raw'], $response);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user