code update
This commit is contained in:
parent
7135e39beb
commit
34dd715985
1 changed files with 28 additions and 42 deletions
70
main.go
70
main.go
|
|
@ -170,14 +170,22 @@ func (bot *Bot) handleCallbackQuery(query *api.CallbackQuery) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
switch action {
|
||||||
case "approve":
|
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)
|
|
||||||
}
|
|
||||||
r := api.ApproveChatJoinRequestConfig{
|
r := api.ApproveChatJoinRequestConfig{
|
||||||
ChatConfig: api.ChatConfig{
|
ChatConfig: api.ChatConfig{
|
||||||
ChatID: user.ChatJoinRequest.Chat.ID,
|
ChatID: user.ChatJoinRequest.Chat.ID,
|
||||||
|
|
@ -187,26 +195,13 @@ func (bot *Bot) handleCallbackQuery(query *api.CallbackQuery) {
|
||||||
_, e := bot.API.Request(r)
|
_, e := bot.API.Request(r)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
log.Println(e.Error())
|
log.Println(e.Error())
|
||||||
edit := api.NewEditMessageText(bot.Config.AdminChatId, user.JoinRequestMessageID,
|
bot.sendFailureMessage(user, query, userString)
|
||||||
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)
|
|
||||||
return
|
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,
|
edit := api.NewEditMessageText(bot.Config.AdminChatId, user.JoinRequestMessageID,
|
||||||
fmt.Sprintf(AdminApprovedMsg,
|
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
|
edit.ParseMode = api.ModeHTML
|
||||||
bot.API.Send(edit)
|
bot.API.Send(edit)
|
||||||
|
|
||||||
|
|
@ -220,12 +215,6 @@ func (bot *Bot) handleCallbackQuery(query *api.CallbackQuery) {
|
||||||
bot.API.Request(callback)
|
bot.API.Request(callback)
|
||||||
|
|
||||||
case "decline":
|
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{
|
r := api.DeclineChatJoinRequest{
|
||||||
ChatConfig: api.ChatConfig{
|
ChatConfig: api.ChatConfig{
|
||||||
ChatID: user.ChatJoinRequest.Chat.ID,
|
ChatID: user.ChatJoinRequest.Chat.ID,
|
||||||
|
|
@ -235,26 +224,13 @@ func (bot *Bot) handleCallbackQuery(query *api.CallbackQuery) {
|
||||||
_, e := bot.API.Request(r)
|
_, e := bot.API.Request(r)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
log.Println(e.Error())
|
log.Println(e.Error())
|
||||||
edit := api.NewEditMessageText(bot.Config.AdminChatId, user.JoinRequestMessageID,
|
bot.sendFailureMessage(user, query, userString)
|
||||||
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)
|
|
||||||
return
|
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,
|
edit := api.NewEditMessageText(bot.Config.AdminChatId, user.JoinRequestMessageID,
|
||||||
fmt.Sprintf(AdminDeclinedMsg,
|
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)"))
|
"(no reason provided, reply to this to send one, prepend with + to also send to user)"))
|
||||||
edit.ParseMode = api.ModeHTML
|
edit.ParseMode = api.ModeHTML
|
||||||
bot.API.Send(edit)
|
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 {
|
func escapeMarkdown(s string) string {
|
||||||
toEscape := []string{"*", "_", "`", "[", "]", "(", ")", "\\", "#", "-"}
|
toEscape := []string{"*", "_", "`", "[", "]", "(", ")", "\\", "#", "-"}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue