Skip to content

Commit

Permalink
Removed unknown command message when not tagged in groups
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelemusiani committed Jan 25, 2024
1 parent 682727e commit 5ffdfde
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,34 @@ func handleUnknown(bot *tgbotapi.BotAPI, update *tgbotapi.Update, _ string) bool
func handleCommand(bot *tgbotapi.BotAPI, update *tgbotapi.Update) {
commandName := strings.ToLower(update.Message.Command())

// Check if the command is for me
commandWithAt := update.Message.CommandWithAt()
atIndex := strings.Index(commandWithAt, "@")
if atIndex != -1 {
forName := commandWithAt[atIndex+1:]
log.Println(forName)

if bot.Self.UserName != forName {
return
// If the bot in is a group and the command does NOT have the recipient bot:
// If is the command is not correct nothing is done
//
// If the bot in is a group and the command does HAVE the recipient bot:
// If the command is not correct the bot returns unknown command message

permitUnknownCommandMessage := true

if !update.Message.Chat.IsPrivate() {
// Check if the command is for me
commandWithAt := update.Message.CommandWithAt()
atIndex := strings.Index(commandWithAt, "@")
if atIndex != -1 {
forName := commandWithAt[atIndex+1:]

if bot.Self.UserName != forName {
return
}
} else {
permitUnknownCommandMessage = false
}
}

for _, h := range handlers {
if !permitUnknownCommandMessage && h.string == "unknown" {
continue
}

if h.handlerBehavior(bot, update, commandName) {
log.Printf("@%s: \t%s -> %s", update.Message.From.UserName, update.Message.Text, h.string)
return
Expand Down

0 comments on commit 5ffdfde

Please sign in to comment.