Apply patch
This commit is contained in:
parent
f9eabae404
commit
334fe2bf8f
4 changed files with 40 additions and 3 deletions
|
|
@ -14,6 +14,7 @@ type Config struct {
|
||||||
TargetChatId *int64 `yaml:"target_chat_id"`
|
TargetChatId *int64 `yaml:"target_chat_id"`
|
||||||
EntryMessage string `yaml:"entry_message"`
|
EntryMessage string `yaml:"entry_message"`
|
||||||
ApprovalMessage string `yaml:"approval_message"`
|
ApprovalMessage string `yaml:"approval_message"`
|
||||||
|
ReminderMessage string `yaml:"reminder_message"`
|
||||||
SendApprovalMessage bool `yaml:"send_approval_message"`
|
SendApprovalMessage bool `yaml:"send_approval_message"`
|
||||||
DeleteRequestAfterDecision bool `yaml:"delete_request_after_decision"`
|
DeleteRequestAfterDecision bool `yaml:"delete_request_after_decision"`
|
||||||
CannedDeclineResponses []string `yaml:"canned_decline_responses"`
|
CannedDeclineResponses []string `yaml:"canned_decline_responses"`
|
||||||
|
|
@ -44,7 +45,8 @@ func (c *Config) CreateConfig() error {
|
||||||
AdminChatId: Int64Ptr(0),
|
AdminChatId: Int64Ptr(0),
|
||||||
AdminChatTopicId: IntPtr(0),
|
AdminChatTopicId: IntPtr(0),
|
||||||
TargetChatId: Int64Ptr(0),
|
TargetChatId: Int64Ptr(0),
|
||||||
EntryMessage: "You have requested to join the group, please write a brief message explaining why you want to join.",
|
EntryMessage: "You have requested to join the group. Please write a brief message explaining why you want to join.",
|
||||||
|
ReminderMessage: "Don't forget to give a one-message response to your join request.",
|
||||||
ApprovalMessage: "",
|
ApprovalMessage: "",
|
||||||
SendApprovalMessage: false,
|
SendApprovalMessage: false,
|
||||||
DeleteRequestAfterDecision: false,
|
DeleteRequestAfterDecision: false,
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,9 @@ func (bot *Bot) HandleCallbackQuery(query *api.CallbackQuery) {
|
||||||
case "banc":
|
case "banc":
|
||||||
bot.handleBanRequest(query, user, userString, adminUserString)
|
bot.handleBanRequest(query, user, userString, adminUserString)
|
||||||
bot.DeletePendingUser(args)
|
bot.DeletePendingUser(args)
|
||||||
|
case "remind":
|
||||||
|
bot.sendReminder(query, user, userString, adminUserString)
|
||||||
|
bot.API.Request(api.NewCallback(query.ID, "Reminder sent!"))
|
||||||
case "cannedrespsel":
|
case "cannedrespsel":
|
||||||
parts := strings.Split(query.Data, "_")
|
parts := strings.Split(query.Data, "_")
|
||||||
if len(parts) >= 3 {
|
if len(parts) >= 3 {
|
||||||
|
|
@ -63,6 +66,22 @@ func (bot *Bot) HandleCallbackQuery(query *api.CallbackQuery) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (bot *Bot) sendReminder(query *api.CallbackQuery, user *ExtendedChatJoinRequest, userString, adminUserString string) {
|
||||||
|
utils.SendMessage(bot.API, user.From.ID, 0, bot.Config.ReminderMessage)
|
||||||
|
|
||||||
|
// Edit admin message to show reminder was sent
|
||||||
|
messageText := fmt.Sprintf(AdminJoinRequestMsg, userString, user.From.ID, user.JoinReason)
|
||||||
|
messageText += fmt.Sprintf("\n\n<b>Reminder sent by</b>: %s\n<b>Reminder sent at</b>: %s",
|
||||||
|
adminUserString, time.Now().Format("2006-01-02 15:04:05"))
|
||||||
|
|
||||||
|
keyboard := utils.NewApprovalKeyboard(user.From.ID)
|
||||||
|
|
||||||
|
edit := api.NewEditMessageText(query.Message.Chat.ID, query.Message.MessageID, messageText)
|
||||||
|
edit.ParseMode = api.ModeHTML
|
||||||
|
edit.ReplyMarkup = &keyboard
|
||||||
|
bot.API.Send(edit)
|
||||||
|
}
|
||||||
|
|
||||||
// handleApproveRequest approves a join request and sends an approval callback.
|
// handleApproveRequest approves a join request and sends an approval callback.
|
||||||
func (bot *Bot) handleApproveRequest(query *api.CallbackQuery, user *ExtendedChatJoinRequest, userString, adminUserString string) {
|
func (bot *Bot) handleApproveRequest(query *api.CallbackQuery, user *ExtendedChatJoinRequest, userString, adminUserString string) {
|
||||||
r := api.ApproveChatJoinRequestConfig{
|
r := api.ApproveChatJoinRequestConfig{
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,10 @@ func (bot *Bot) HandleJoinRequestResponse(user *ExtendedChatJoinRequest, update
|
||||||
userString := utils.BuildUserString(&user.From)
|
userString := utils.BuildUserString(&user.From)
|
||||||
|
|
||||||
keyboard := utils.NewApprovalKeyboard(user.From.ID)
|
keyboard := utils.NewApprovalKeyboard(user.From.ID)
|
||||||
|
if bot.Config.ReminderMessage != "" {
|
||||||
|
newButton := api.NewInlineKeyboardButtonData("Send Reminder", fmt.Sprintf("remind_%d", user.From.ID))
|
||||||
|
keyboard.InlineKeyboard[1] = append([]api.InlineKeyboardButton{newButton}, keyboard.InlineKeyboard[1]...)
|
||||||
|
}
|
||||||
utils.EditMessageWithKeyboard(bot.API, *bot.Config.AdminChatId, user.JoinRequestMessageID,
|
utils.EditMessageWithKeyboard(bot.API, *bot.Config.AdminChatId, user.JoinRequestMessageID,
|
||||||
fmt.Sprintf(AdminJoinRequestMsg, userString, user.From.ID, user.JoinReason), &keyboard)
|
fmt.Sprintf(AdminJoinRequestMsg, userString, user.From.ID, user.JoinReason), &keyboard)
|
||||||
|
|
||||||
|
|
@ -27,12 +31,24 @@ func (bot *Bot) HandleJoinRequestResponse(user *ExtendedChatJoinRequest, update
|
||||||
|
|
||||||
// HandleJoinRequest initiates the join approval flow by sending the entry message and admin notification.
|
// HandleJoinRequest initiates the join approval flow by sending the entry message and admin notification.
|
||||||
func (bot *Bot) HandleJoinRequest(request *api.ChatJoinRequest) {
|
func (bot *Bot) HandleJoinRequest(request *api.ChatJoinRequest) {
|
||||||
|
// Check if user already has a pending request
|
||||||
|
if existingUser := bot.GetPendingUser(request.From.ID); existingUser != nil {
|
||||||
|
utils.SendMessage(bot.API, request.From.ID, 0,
|
||||||
|
"You have already requested to join. Please send a single message as your join reason.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
utils.SendMessage(bot.API, request.From.ID, 0, bot.Config.EntryMessage)
|
utils.SendMessage(bot.API, request.From.ID, 0, bot.Config.EntryMessage)
|
||||||
userString := utils.BuildUserString(&request.From)
|
userString := utils.BuildUserString(&request.From)
|
||||||
|
|
||||||
|
keyboard := utils.NewApprovalKeyboard(request.From.ID)
|
||||||
|
if bot.Config.ReminderMessage != "" {
|
||||||
|
newButton := api.NewInlineKeyboardButtonData("Send Reminder", fmt.Sprintf("remind_%d", request.From.ID))
|
||||||
|
keyboard.InlineKeyboard[1] = append([]api.InlineKeyboardButton{newButton}, keyboard.InlineKeyboard[1]...)
|
||||||
|
}
|
||||||
m := api.NewMessage(*bot.Config.AdminChatId,
|
m := api.NewMessage(*bot.Config.AdminChatId,
|
||||||
fmt.Sprintf(AdminJoinRequestMsg, userString, request.From.ID, "(awaiting user response)"))
|
fmt.Sprintf(AdminJoinRequestMsg, userString, request.From.ID, "(awaiting user response)"))
|
||||||
m.ReplyMarkup = utils.NewApprovalKeyboard(request.From.ID)
|
m.ReplyMarkup = keyboard
|
||||||
m.ParseMode = api.ModeHTML
|
m.ParseMode = api.ModeHTML
|
||||||
m.LinkPreviewOptions = api.LinkPreviewOptions{IsDisabled: true}
|
m.LinkPreviewOptions = api.LinkPreviewOptions{IsDisabled: true}
|
||||||
if topic := *bot.Config.AdminChatTopicId; topic != 0 {
|
if topic := *bot.Config.AdminChatTopicId; topic != 0 {
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ func EscapeHTML(s string) string {
|
||||||
func NewApprovalKeyboard(userID int64) api.InlineKeyboardMarkup {
|
func NewApprovalKeyboard(userID int64) api.InlineKeyboardMarkup {
|
||||||
approveBtn := api.NewInlineKeyboardButtonData("Approve", fmt.Sprintf("approve_%d", userID))
|
approveBtn := api.NewInlineKeyboardButtonData("Approve", fmt.Sprintf("approve_%d", userID))
|
||||||
declineBtn := api.NewInlineKeyboardButtonData("Decline", fmt.Sprintf("decline_%d", userID))
|
declineBtn := api.NewInlineKeyboardButtonData("Decline", fmt.Sprintf("decline_%d", userID))
|
||||||
banBtn := api.NewInlineKeyboardButtonData("Ban (24h)", fmt.Sprintf("ban_%d", userID))
|
banBtn := api.NewInlineKeyboardButtonData("⚠️ Ban (24h)", fmt.Sprintf("ban_%d", userID))
|
||||||
return api.NewInlineKeyboardMarkup(
|
return api.NewInlineKeyboardMarkup(
|
||||||
[]api.InlineKeyboardButton{approveBtn, declineBtn},
|
[]api.InlineKeyboardButton{approveBtn, declineBtn},
|
||||||
[]api.InlineKeyboardButton{banBtn},
|
[]api.InlineKeyboardButton{banBtn},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue