Browse Source

Merge pull request #527 from v2board/dev

1.6.0
tokumeikoi 3 years ago
parent
commit
7a64038133
2 changed files with 19 additions and 1 deletions
  1. 18 0
      app/Http/Controllers/Guest/TelegramController.php
  2. 1 1
      config/app.php

+ 18 - 0
app/Http/Controllers/Guest/TelegramController.php

@@ -28,6 +28,17 @@ class TelegramController extends Controller
     public function handle()
     public function handle()
     {
     {
         $msg = $this->msg;
         $msg = $this->msg;
+
+        $commandName = explode('@', $msg->command);
+
+        // To reduce request, only commands contains @ will get the bot name
+        if (count($commandName) == 2) {
+            $botName = $this->getBotName();
+            if ($commandName[1] === $botName){
+                $msg->command = $commandName[0];
+            }
+        }
+
         try {
         try {
             foreach (glob(base_path('app//Plugins//Telegram//Commands') . '/*.php') as $file) {
             foreach (glob(base_path('app//Plugins//Telegram//Commands') . '/*.php') as $file) {
                 $command = basename($file, '.php');
                 $command = basename($file, '.php');
@@ -53,6 +64,13 @@ class TelegramController extends Controller
         }
         }
     }
     }
 
 
+    public function getBotName()
+    {
+        $telegramService = new TelegramService();
+        $response = $telegramService->getMe();
+        return $response->result->username;
+    }
+
     private function getMessage(array $data)
     private function getMessage(array $data)
     {
     {
         if (!isset($data['message'])) return false;
         if (!isset($data['message'])) return false;

+ 1 - 1
config/app.php

@@ -237,5 +237,5 @@ return [
     | The only modification by laravel config
     | The only modification by laravel config
     |
     |
     */
     */
-    'version' => '1.5.6.1652111181640'
+    'version' => '1.6.0'
 ];
 ];