From e6c10221e6fbbc71b748a89375ca4b3b239c0ed9 Mon Sep 17 00:00:00 2001 From: Carson Yang Date: Tue, 6 Dec 2022 22:54:51 +0800 Subject: [PATCH 1/5] add support for groups react only for mention in group or for all messages directly in private chats --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 2431a64..44fb026 100644 --- a/main.go +++ b/main.go @@ -87,7 +87,7 @@ func main() { } bot.Request(tgbotapi.NewChatAction(update.Message.Chat.ID, "typing")) - if !update.Message.IsCommand() { + if !update.Message.IsCommand() && (update.Message.Chat.IsPrivate() || (update.Message.Chat.Type == "group" || update.Message.Chat.Type == "supergroup") && strings.HasPrefix(update.Message.Text, "@" + bot.Self.UserName)) { feed, err := chatGPT.SendMessage(update.Message.Text, userConversations[update.Message.Chat.ID].ConversationID, userConversations[update.Message.Chat.ID].LastMessageID) if err != nil { msg.Text = fmt.Sprintf("Error: %v", err) From 939d62049c1901e9f26a09887fed019c42a32d2b Mon Sep 17 00:00:00 2001 From: Carson Yang Date: Tue, 6 Dec 2022 22:57:25 +0800 Subject: [PATCH 2/5] fix typo Signed-off-by: Administrator --- main.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 44fb026..f18b8bc 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "log" "os" "os/signal" + "strings" "strconv" "syscall" "time" @@ -87,7 +88,7 @@ func main() { } bot.Request(tgbotapi.NewChatAction(update.Message.Chat.ID, "typing")) - if !update.Message.IsCommand() && (update.Message.Chat.IsPrivate() || (update.Message.Chat.Type == "group" || update.Message.Chat.Type == "supergroup") && strings.HasPrefix(update.Message.Text, "@" + bot.Self.UserName)) { + if !update.Message.IsCommand() && (update.Message.Chat.IsPrivate() || ((update.Message.Chat.Type == "group" || update.Message.Chat.Type == "supergroup") && strings.HasPrefix(update.Message.Text, "@" + bot.Self.UserName))) { feed, err := chatGPT.SendMessage(update.Message.Text, userConversations[update.Message.Chat.ID].ConversationID, userConversations[update.Message.Chat.ID].LastMessageID) if err != nil { msg.Text = fmt.Sprintf("Error: %v", err) From 5c52676836554740cebce4f225e048d1e0319870 Mon Sep 17 00:00:00 2001 From: Carson Yang Date: Wed, 7 Dec 2022 11:07:02 +0800 Subject: [PATCH 3/5] fix typo --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index f18b8bc..83ef182 100644 --- a/main.go +++ b/main.go @@ -5,7 +5,7 @@ import ( "log" "os" "os/signal" - "strings" + "strings" "strconv" "syscall" "time" From 61c87ce3c51d1219afca3b32bcee2232d89ad1f1 Mon Sep 17 00:00:00 2001 From: Carson Yang Date: Sun, 11 Dec 2022 00:07:14 +0800 Subject: [PATCH 4/5] fix typo --- main.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 996621d..ee132cc 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "os" "os/signal" "strconv" + "strings" "syscall" "time" @@ -113,4 +114,4 @@ func main() { log.Printf("Error sending message: %v", err) } } -} \ No newline at end of file +} From 5acf0e235d3e1e71c8aba4e7be03e391bac6d9df Mon Sep 17 00:00:00 2001 From: Carson Yang Date: Sun, 11 Dec 2022 14:18:34 +0800 Subject: [PATCH 5/5] Support Suffix --- main.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 7b46f21..e4de701 100644 --- a/main.go +++ b/main.go @@ -69,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) { @@ -77,7 +80,7 @@ func main() { continue } - if !update.Message.IsCommand() && (update.Message.Chat.IsPrivate() || ((update.Message.Chat.IsGroup() || update.Message.Chat.IsSuperGroup()) && strings.HasPrefix(update.Message.Text, "@" + bot.Username))) { + if !update.Message.IsCommand() && (isPrivateChat || (isChatBotInGroup && isAtChatBot)) { bot.SendTyping(updateChatID) feed, err := chatGPT.SendMessage(updateText, updateChatID)