Move allowed ChatIDs list to env.php
This commit is contained in:
@@ -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];
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user