code update
This commit is contained in:
parent
7135e39beb
commit
34dd715985
1 changed files with 28 additions and 42 deletions
62
main.go
62
main.go
|
|
@ -170,14 +170,22 @@ func (bot *Bot) handleCallbackQuery(query *api.CallbackQuery) {
|
|||
return
|
||||
}
|
||||
|
||||
switch action {
|
||||
case "approve":
|
||||
userString := ""
|
||||
if user.From.UserName != "" {
|
||||
userString = "@" + user.From.UserName
|
||||
} else {
|
||||
userString = fmt.Sprintf("%s %s (no username)", user.From.FirstName, user.From.LastName)
|
||||
}
|
||||
|
||||
adminUserString := ""
|
||||
if query.From.UserName != "" {
|
||||
adminUserString = "@" + query.From.UserName
|
||||
} else {
|
||||
adminUserString = fmt.Sprintf("%s %s", query.From.FirstName, query.From.LastName)
|
||||
}
|
||||
|
||||
switch action {
|
||||
case "approve":
|
||||
r := api.ApproveChatJoinRequestConfig{
|
||||
ChatConfig: api.ChatConfig{
|
||||
ChatID: user.ChatJoinRequest.Chat.ID,
|
||||
|
|
@ -187,26 +195,13 @@ func (bot *Bot) handleCallbackQuery(query *api.CallbackQuery) {
|
|||
_, e := bot.API.Request(r)
|
||||
if e != nil {
|
||||
log.Println(e.Error())
|
||||
edit := api.NewEditMessageText(bot.Config.AdminChatId, user.JoinRequestMessageID,
|
||||
fmt.Sprintf(AdminFailedMsg, userString, user.From.ID, user.JoinReason, "User not found in requests."))
|
||||
edit.ParseMode = api.ModeHTML
|
||||
bot.API.Send(edit)
|
||||
|
||||
callback := api.NewCallback(query.ID, "Join request failed.")
|
||||
bot.API.Request(callback)
|
||||
bot.sendFailureMessage(user, query, userString)
|
||||
return
|
||||
}
|
||||
|
||||
approveUserString := ""
|
||||
if query.From.UserName != "" {
|
||||
approveUserString = "@" + query.From.UserName
|
||||
} else {
|
||||
approveUserString = fmt.Sprintf("%s %s", query.From.FirstName, query.From.LastName)
|
||||
}
|
||||
|
||||
edit := api.NewEditMessageText(bot.Config.AdminChatId, user.JoinRequestMessageID,
|
||||
fmt.Sprintf(AdminApprovedMsg,
|
||||
userString, user.From.ID, user.JoinReason, approveUserString, time.Now().Format("2006-01-02 15:04:05")))
|
||||
userString, user.From.ID, user.JoinReason, adminUserString, time.Now().Format("2006-01-02 15:04:05")))
|
||||
edit.ParseMode = api.ModeHTML
|
||||
bot.API.Send(edit)
|
||||
|
||||
|
|
@ -220,12 +215,6 @@ func (bot *Bot) handleCallbackQuery(query *api.CallbackQuery) {
|
|||
bot.API.Request(callback)
|
||||
|
||||
case "decline":
|
||||
userString := ""
|
||||
if user.From.UserName != "" {
|
||||
userString = "@" + user.From.UserName
|
||||
} else {
|
||||
userString = fmt.Sprintf("%s %s (no username)", user.From.FirstName, user.From.LastName)
|
||||
}
|
||||
r := api.DeclineChatJoinRequest{
|
||||
ChatConfig: api.ChatConfig{
|
||||
ChatID: user.ChatJoinRequest.Chat.ID,
|
||||
|
|
@ -235,26 +224,13 @@ func (bot *Bot) handleCallbackQuery(query *api.CallbackQuery) {
|
|||
_, e := bot.API.Request(r)
|
||||
if e != nil {
|
||||
log.Println(e.Error())
|
||||
edit := api.NewEditMessageText(bot.Config.AdminChatId, user.JoinRequestMessageID,
|
||||
fmt.Sprintf(AdminFailedMsg, userString, user.From.ID, user.JoinReason, "User not found in requests."))
|
||||
edit.ParseMode = api.ModeHTML
|
||||
bot.API.Send(edit)
|
||||
|
||||
callback := api.NewCallback(query.ID, "Join request failed.")
|
||||
bot.API.Request(callback)
|
||||
bot.sendFailureMessage(user, query, userString)
|
||||
return
|
||||
}
|
||||
|
||||
declinedUserString := ""
|
||||
if query.From.UserName != "" {
|
||||
declinedUserString = "@" + query.From.UserName
|
||||
} else {
|
||||
declinedUserString = fmt.Sprintf("%s %s", query.From.FirstName, query.From.LastName)
|
||||
}
|
||||
|
||||
edit := api.NewEditMessageText(bot.Config.AdminChatId, user.JoinRequestMessageID,
|
||||
fmt.Sprintf(AdminDeclinedMsg,
|
||||
userString, user.From.ID, user.JoinReason, declinedUserString, time.Now().Format("2006-01-02 15:04:05"),
|
||||
userString, user.From.ID, user.JoinReason, adminUserString, time.Now().Format("2006-01-02 15:04:05"),
|
||||
"(no reason provided, reply to this to send one, prepend with + to also send to user)"))
|
||||
edit.ParseMode = api.ModeHTML
|
||||
bot.API.Send(edit)
|
||||
|
|
@ -277,6 +253,16 @@ func (bot *Bot) handleCallbackQuery(query *api.CallbackQuery) {
|
|||
}
|
||||
}
|
||||
|
||||
func (bot *Bot) sendFailureMessage(user *ExtendedChatJoinRequest, query *api.CallbackQuery, userString string) {
|
||||
edit := api.NewEditMessageText(bot.Config.AdminChatId, user.JoinRequestMessageID,
|
||||
fmt.Sprintf(AdminFailedMsg, userString, user.From.ID, user.JoinReason, "User not found in requests."))
|
||||
edit.ParseMode = api.ModeHTML
|
||||
bot.API.Send(edit)
|
||||
|
||||
callback := api.NewCallback(query.ID, "Join request failed.")
|
||||
bot.API.Request(callback)
|
||||
}
|
||||
|
||||
func escapeMarkdown(s string) string {
|
||||
toEscape := []string{"*", "_", "`", "[", "]", "(", ")", "\\", "#", "-"}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue