diff --git a/channels/leaveduserchecker.go b/channels/leaveduserchecker.go index f8c56b1..d4252cd 100644 --- a/channels/leaveduserchecker.go +++ b/channels/leaveduserchecker.go @@ -2,6 +2,7 @@ package channels import ( "git.dragon-labs.de/alphyron/group_helper/logic" + "git.dragon-labs.de/alphyron/group_helper/message" "git.dragon-labs.de/alphyron/group_helper/models" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api" "log" @@ -87,7 +88,7 @@ func checkGroupUser(group *models.Group, groupHelperService logic.GroupHelperSer } leaveMessage := group.UserLeaveMessage - //TODO Replace placeholder + leaveMessage = message.ReplaceMessage(leaveMessage, member.User) msg := tgbotapi.NewMessage(group.GroupID, leaveMessage) msg.ParseMode = "Markdown" diff --git a/channels/verifiychecker.go b/channels/verifiychecker.go index 0e12394..8b3dc34 100644 --- a/channels/verifiychecker.go +++ b/channels/verifiychecker.go @@ -2,6 +2,7 @@ package channels import ( "git.dragon-labs.de/alphyron/group_helper/logic" + "git.dragon-labs.de/alphyron/group_helper/message" "git.dragon-labs.de/alphyron/group_helper/models" "git.dragon-labs.de/alphyron/group_helper/obj" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api" @@ -73,7 +74,7 @@ func CheckUnverifiedUser(ticker *time.Ticker, quitChannel <-chan struct{}, group } kickMessage := groups[user.GroupID].UserKickMessage - //TODO Replace placeholder + kickMessage = message.ReplaceMessage(kickMessage, member.User) msg := tgbotapi.NewMessage(user.GroupID, kickMessage) msg.ParseMode = "Markdown" diff --git a/cli/commands/joinmessage.go b/cli/commands/joinmessage.go index 5a82763..68e1e1a 100644 --- a/cli/commands/joinmessage.go +++ b/cli/commands/joinmessage.go @@ -3,6 +3,7 @@ package commands import ( "git.dragon-labs.de/alphyron/group_helper/cli" "git.dragon-labs.de/alphyron/group_helper/logic" + message2 "git.dragon-labs.de/alphyron/group_helper/message" "git.dragon-labs.de/alphyron/group_helper/models" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api" "strings" @@ -61,8 +62,7 @@ func (j joinMessage) ExecuteCommand(api *tgbotapi.BotAPI, update *tgbotapi.Updat return false, err } - //TODO Create a replace for placeholder - msg := tgbotapi.NewMessage(update.Message.Chat.ID, group.UserJoinMessage) + msg := tgbotapi.NewMessage(update.Message.Chat.ID, message2.ReplaceMessage(group.UserJoinMessage, update.Message.From)) msg.ParseMode = "Markdown" api.Send(tgbotapi.NewMessage(update.Message.Chat.ID, "Example JoinMessage")) _, err = api.Send(msg) diff --git a/cli/commands/kickmessage.go b/cli/commands/kickmessage.go index f32adfe..0720e82 100644 --- a/cli/commands/kickmessage.go +++ b/cli/commands/kickmessage.go @@ -3,6 +3,7 @@ package commands import ( "git.dragon-labs.de/alphyron/group_helper/cli" "git.dragon-labs.de/alphyron/group_helper/logic" + message2 "git.dragon-labs.de/alphyron/group_helper/message" "git.dragon-labs.de/alphyron/group_helper/models" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api" "strings" @@ -61,8 +62,7 @@ func (j kickMessage) ExecuteCommand(api *tgbotapi.BotAPI, update *tgbotapi.Updat return false, err } - //TODO Create a replace for placeholder - msg := tgbotapi.NewMessage(update.Message.Chat.ID, group.UserKickMessage) + msg := tgbotapi.NewMessage(update.Message.Chat.ID, message2.ReplaceMessage(group.UserKickMessage, update.Message.From)) msg.ParseMode = "Markdown" api.Send(tgbotapi.NewMessage(update.Message.Chat.ID, "Example KickMessage")) _, err = api.Send(msg) diff --git a/cli/commands/leavemessage.go b/cli/commands/leavemessage.go index 944a405..cec2cd5 100644 --- a/cli/commands/leavemessage.go +++ b/cli/commands/leavemessage.go @@ -3,6 +3,7 @@ package commands import ( "git.dragon-labs.de/alphyron/group_helper/cli" "git.dragon-labs.de/alphyron/group_helper/logic" + message2 "git.dragon-labs.de/alphyron/group_helper/message" "git.dragon-labs.de/alphyron/group_helper/models" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api" "strings" @@ -61,8 +62,7 @@ func (j leaveMessage) ExecuteCommand(api *tgbotapi.BotAPI, update *tgbotapi.Upda return false, err } - //TODO Create a replace for placeholder - msg := tgbotapi.NewMessage(update.Message.Chat.ID, group.UserLeaveMessage) + msg := tgbotapi.NewMessage(update.Message.Chat.ID, message2.ReplaceMessage(group.UserLeaveMessage, update.Message.From)) msg.ParseMode = "Markdown" api.Send(tgbotapi.NewMessage(update.Message.Chat.ID, "Example LeaveMessage")) _, err = api.Send(msg) diff --git a/cli/commands/verifiedmessage.go b/cli/commands/verifiedmessage.go index 95d7620..affaed3 100644 --- a/cli/commands/verifiedmessage.go +++ b/cli/commands/verifiedmessage.go @@ -3,6 +3,7 @@ package commands import ( "git.dragon-labs.de/alphyron/group_helper/cli" "git.dragon-labs.de/alphyron/group_helper/logic" + message2 "git.dragon-labs.de/alphyron/group_helper/message" "git.dragon-labs.de/alphyron/group_helper/models" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api" "strings" @@ -61,8 +62,7 @@ func (j verifiedMessage) ExecuteCommand(api *tgbotapi.BotAPI, update *tgbotapi.U return false, err } - //TODO Create a replace for placeholder - msg := tgbotapi.NewMessage(update.Message.Chat.ID, group.UserVerifiedMessage) + msg := tgbotapi.NewMessage(update.Message.Chat.ID, message2.ReplaceMessage(group.UserVerifiedMessage, update.Message.From)) msg.ParseMode = "Markdown" api.Send(tgbotapi.NewMessage(update.Message.Chat.ID, "Example VerifiedMessage")) _, err = api.Send(msg) diff --git a/message/replace.go b/message/replace.go new file mode 100644 index 0000000..83e0732 --- /dev/null +++ b/message/replace.go @@ -0,0 +1,16 @@ +package message + +import ( + tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api" + "strconv" + "strings" +) + +func ReplaceMessage(message string, user *tgbotapi.User) string { + message = strings.Replace(message, "{{user.firstname}}", user.FirstName, -1) + message = strings.Replace(message, "{{user.lastname}}", user.LastName, -1) + message = strings.Replace(message, "{{user.username}}", user.UserName, -1) + message = strings.Replace(message, "{{user.name}}", user.UserName, -1) + message = strings.Replace(message, "{{user.id}}", strconv.Itoa(user.ID), -1) + return message +} diff --git a/telegram/routines/joinchecker.go b/telegram/routines/joinchecker.go index 3151f16..4dc101f 100644 --- a/telegram/routines/joinchecker.go +++ b/telegram/routines/joinchecker.go @@ -1,6 +1,7 @@ package routines import ( + message2 "git.dragon-labs.de/alphyron/group_helper/message" "git.dragon-labs.de/alphyron/group_helper/models" "git.dragon-labs.de/alphyron/group_helper/obj" "git.dragon-labs.de/alphyron/group_helper/telegram" @@ -47,8 +48,7 @@ func (j joinCheckerRoutine) Update(botAPI *tgbotapi.BotAPI, update *tgbotapi.Upd markup := tgbotapi.NewInlineKeyboardMarkup(tasks...) - msg := tgbotapi.NewMessage(update.Message.Chat.ID, group.UserJoinMessage) - //TODO Replace placeholder + msg := tgbotapi.NewMessage(update.Message.Chat.ID, message2.ReplaceMessage(group.UserJoinMessage, update.Message.From)) msg.ParseMode = "Markdown" msg.ReplyMarkup = markup diff --git a/telegram/routines/verifier.go b/telegram/routines/verifier.go index 6d94cec..1411515 100644 --- a/telegram/routines/verifier.go +++ b/telegram/routines/verifier.go @@ -2,6 +2,7 @@ package routines import ( "git.dragon-labs.de/alphyron/group_helper/logic" + message2 "git.dragon-labs.de/alphyron/group_helper/message" "git.dragon-labs.de/alphyron/group_helper/models" "git.dragon-labs.de/alphyron/group_helper/obj" "git.dragon-labs.de/alphyron/group_helper/telegram" @@ -52,9 +53,7 @@ func (v verifierRoutine) Update(botAPI *tgbotapi.BotAPI, update *tgbotapi.Update botAPI.AnswerCallbackQuery(tgbotapi.NewCallback(update.CallbackQuery.ID, "You are now verified. Welcome to the chat!")) verifyMessage := group.UserVerifiedMessage - //TODO Replace placeholder - - msg := tgbotapi.NewMessage(update.CallbackQuery.Message.Chat.ID, verifyMessage) + msg := tgbotapi.NewMessage(update.CallbackQuery.Message.Chat.ID, message2.ReplaceMessage(verifyMessage, update.Message.From)) msg.ParseMode = "Markdown" _, err := botAPI.Send(msg)