Skip to content

Commit

Permalink
Add utility functions getUserName and reply
Browse files Browse the repository at this point in the history
  • Loading branch information
ryukinix committed Jul 23, 2020
1 parent c2b50a4 commit e015eff
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions troll_shield.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,26 @@ func setupLogging() {
}
}

func getUserName(user tgbotapi.User) string {
username := user.FirstName
if user.UserName != "" {
username = fmt.Sprintf("@%v", user.UserName)
} else if user.LastName != "" {
username = fmt.Sprintf("%s %s", user.FirstName, user.LastName)
}
return username
}

func reply(bot *tgbotapi.BotAPI, update *tgbotapi.Update, text string) {
msg := tgbotapi.NewMessage(update.Message.Chat.ID, text)
msg.ReplyToMessageID = update.Message.MessageID

_, err := bot.Send(msg)
if err != nil {
log.Printf("[!] Send msg failed: %v", err)
}
}

func main() {
setupLogging()
token, exists := os.LookupEnv("TELEGRAM_BOT_TOKEN")
Expand Down

0 comments on commit e015eff

Please sign in to comment.