diff --git a/env.sample.php b/env.sample.php index 528bb10..860eb99 100644 --- a/env.sample.php +++ b/env.sample.php @@ -6,3 +6,5 @@ $bot_api_key = '1234567890:Telegram_bot_api_key'; $bot_username = 'telegram_bot_username'; $hook_url = 'https://my.server.com/path/to/hook.php'; putenv('DEEPL_API_KEY=some-uuid-12345-abcde:fx'); +$deepl_api_key = 'some-uuid-12345-abcde:fx'; +$allowed_chat_ids = [123, 456, -123]; diff --git a/src/Commands/GenericmessageCommand.php b/src/Commands/GenericmessageCommand.php index 590a338..78b1a0c 100644 --- a/src/Commands/GenericmessageCommand.php +++ b/src/Commands/GenericmessageCommand.php @@ -19,9 +19,6 @@ class GenericmessageCommand extends SystemCommand protected $version = '1.0.0'; private Translator $translator; - private const ALLOWED_CHAT_ID = [ - 123, 456, 789 - ]; private const ZH_TO_EN = [ '兽设' => 'fursona', '兽人' => 'furry character', @@ -50,10 +47,12 @@ class GenericmessageCommand extends SystemCommand public function execute(): ServerResponse { + global $deepl_api_key, $allowed_chat_ids; + $message = $this->getMessage(); $chat_id = $message->getChat()->getId(); - if(!in_array($chat_id, self::ALLOWED_CHAT_ID)) { + if(!in_array($chat_id, $allowed_chat_ids)) { return Request::sendMessage([ 'chat_id' => $chat_id, 'text' => "Chat ID $chat_id not allowed", @@ -82,7 +81,7 @@ class GenericmessageCommand extends SystemCommand $text = str_replace($search, $replace, $text); } - $this->translator = new Translator(getenv('DEEPL_API_KEY')); + $this->translator = new Translator($deepl_api_key); try { $translated = $this->translator->translateText($text, $sourceLang, $targetLang); } catch (\Exception $e) {