diff --git a/handlers/callbacks.go b/handlers/callbacks.go
index b7e2d8b..49466d2 100644
--- a/handlers/callbacks.go
+++ b/handlers/callbacks.go
@@ -10,7 +10,7 @@ import (
api "github.com/OvyFlash/telegram-bot-api"
)
-// HandleCallbackQuery processes inline button callbacks (approve/decline/leave).
+// HandleCallbackQuery processes inline button callbacks (approve/decline/ban/leave).
func (bot *Bot) HandleCallbackQuery(query *api.CallbackQuery) {
action, args, err := parseCallbackData(query.Data)
if err != nil {
@@ -38,6 +38,8 @@ func (bot *Bot) HandleCallbackQuery(query *api.CallbackQuery) {
bot.handleApproveRequest(query, user, userString, adminUserString)
case "decline":
bot.handleDeclineRequest(query, user, userString, adminUserString)
+ case "ban":
+ bot.handleBanRequest(query, user, userString, adminUserString)
}
bot.DeletePendingUser(args)
@@ -98,6 +100,32 @@ func (bot *Bot) handleDeclineRequest(query *api.CallbackQuery, user *ExtendedCha
bot.API.Request(api.NewCallback(query.ID, "Join request declined."))
}
+// handleBanRequest bans a user from the chat for 24 hours.
+func (bot *Bot) handleBanRequest(query *api.CallbackQuery, user *ExtendedChatJoinRequest, userString, adminUserString string) {
+ r := api.BanChatMemberConfig{
+ ChatMemberConfig: api.ChatMemberConfig{
+ ChatConfig: api.ChatConfig{ChatID: user.ChatJoinRequest.Chat.ID},
+ UserID: user.ChatJoinRequest.From.ID,
+ },
+ UntilDate: time.Now().Add(24 * time.Hour).Unix(),
+ }
+
+ if _, err := bot.API.Request(r); err != nil {
+ log.Println(err)
+ bot.restoreMessage(query)
+ return
+ }
+
+ utils.EditMessage(bot.API, query.Message.Chat.ID, query.Message.MessageID,
+ fmt.Sprintf(AdminBannedMsg,
+ userString, user.From.ID, user.JoinReason, adminUserString,
+ time.Now().Format("2006-01-02 15:04:05"),
+ ),
+ )
+
+ bot.API.Request(api.NewCallback(query.ID, "User banned."))
+}
+
// HandleDeclineReason allows admins to provide a decline reason by replying to decline messages.
func (bot *Bot) HandleDeclineReason(update *api.Update) {
repliedMsg := update.Message.ReplyToMessage
diff --git a/handlers/handlers.go b/handlers/handlers.go
index ef704a6..ddabeee 100644
--- a/handlers/handlers.go
+++ b/handlers/handlers.go
@@ -11,6 +11,7 @@ const (
AdminJoinRequestMsg = "New join #request from %s [%d]\n\nJoin reason: %s"
AdminApprovedMsg = "✅ Join #request approved for %s [%d]\n\nJoin reason: %s\nApproved by: %s\nApproved at: %s"
AdminDeclinedMsg = "❌ Join #request declined for %s [%d]\n\nJoin reason: %s\nDeclined by: %s\nDeclined at: %s\nDeclined reason: %s"
+ AdminBannedMsg = "🚫 Join #request banned for %s [%d]\n\nJoin reason: %s\nBanned by: %s\nBanned at: %s"
AdminFailedMsg = "⚠️ Join #request failed for %s [%d]\n\nJoin reason: %s\nFailure reason: %s"
defaultReason = "(no reason provided, reply to this to set one, prepend with + to also send to user)"
)
diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go
index 5ec3057..d425d87 100644
--- a/pkg/utils/utils.go
+++ b/pkg/utils/utils.go
@@ -38,7 +38,11 @@ func EscapeHTML(s string) string {
func NewApprovalKeyboard(userID int64) api.InlineKeyboardMarkup {
approveBtn := api.NewInlineKeyboardButtonData("Approve", fmt.Sprintf("approve_%d", userID))
declineBtn := api.NewInlineKeyboardButtonData("Decline", fmt.Sprintf("decline_%d", userID))
- return api.NewInlineKeyboardMarkup([]api.InlineKeyboardButton{approveBtn, declineBtn})
+ banBtn := api.NewInlineKeyboardButtonData("Ban", fmt.Sprintf("ban_%d", userID))
+ return api.NewInlineKeyboardMarkup(
+ []api.InlineKeyboardButton{approveBtn, declineBtn},
+ []api.InlineKeyboardButton{banBtn},
+ )
}
func GetInfoFromMsg(msg string) (userId int64, username, joinReason, declinedBy, declinedAt string) {