penguin/golifehk

@golifehk bot in Telegram

commit 67e3ec1500f6560cfdf71c047db8891c2323c725

author斟酌 鵬兄 <tgckpg@gmail.com>
date2022-09-15T12:25:29Z
subjectOnly reply to mentions
commit 67e3ec1500f6560cfdf71c047db8891c2323c725
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date:   2022-09-15T12:25:29Z

    Only reply to mentions
---
 main.go | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/main.go b/main.go
index eaa4b66..97ae38f 100644
--- a/main.go
+++ b/main.go
@@ -3,6 +3,7 @@ package main
 import (
     "log"
     "os"
+    "strings"
     mtrbus "github.com/tgckpg/golifehk/datasources/mtr/bus"
     tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
 )
@@ -29,11 +30,13 @@ func main() {
 
         log.Printf( "[%s] %s", update.Message.From.UserName, update.Message.Text )
 
-        result := mtrbus.Query( "zh", update.Message.Text )
+        if strings.Contains( update.Message.Text, "@golifehkbot" ){
+            result := mtrbus.Query( "zh", strings.Replace( update.Message.Text, "@golifehkbot", "", -1 ) )
 
-        msg := tgbotapi.NewMessage( update.Message.Chat.ID, result.Message() )
-        msg.ReplyToMessageID = update.Message.MessageID
+            msg := tgbotapi.NewMessage( update.Message.Chat.ID, result.Message() )
+            msg.ReplyToMessageID = update.Message.MessageID
 
-        bot.Send( msg )
+            bot.Send( msg )
+        }
     }
 }