diff --git a/main.go b/main.go index ccc1e77..e4de701 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,8 @@ import ( "log" "os" "os/signal" + "strconv" + "strings" "syscall" "time" @@ -67,6 +69,9 @@ func main() { updateChatID = update.Message.Chat.ID updateMessageID = update.Message.MessageID updateUserID = update.Message.From.ID + isChatBotInGroup = update.Message.Chat.IsGroup() || update.Message.Chat.IsSuperGroup() + isAtChatBot = strings.HasPrefix(update.Message.Text, "@"+bot.Username) || strings.HasSuffix(update.Message.Text, "@"+bot.Username) + isPrivateChat = update.Message.Chat.IsPrivate() ) if len(envConfig.TelegramID) != 0 && !envConfig.HasTelegramID(updateUserID) { @@ -75,7 +80,7 @@ func main() { continue } - if !update.Message.IsCommand() { + if !update.Message.IsCommand() && (isPrivateChat || (isChatBotInGroup && isAtChatBot)) { bot.SendTyping(updateChatID) feed, err := chatGPT.SendMessage(updateText, updateChatID)