✨ Implement the message placeholder replacer
This commit is contained in:
parent
f2d964a2f3
commit
1a8a0a2db8
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
16
message/replace.go
Normal file
16
message/replace.go
Normal file
@ -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
|
||||
}
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user