52 lines
1.9 KiB
Go
52 lines
1.9 KiB
Go
package handlers
|
|
|
|
import (
|
|
"sync"
|
|
|
|
config "git.zio.sh/astra/telegram-approval-join/config"
|
|
api "github.com/OvyFlash/telegram-bot-api"
|
|
)
|
|
|
|
const (
|
|
AdminJoinRequestMsg = "New join #request from %s [<code>%d</code>]\n\n<b>Join reason</b>: %s"
|
|
AdminApprovedMsg = "✅ Join #request approved for %s [<code>%d</code>]\n\n<b>Join reason</b>: %s\n<b>Approved by</b>: %s\n<b>Approved at</b>: %s"
|
|
AdminDeclinedMsg = "❌ Join #request declined for %s [<code>%d</code>]\n\n<b>Join reason</b>: %s\n<b>Declined by</b>: %s\n<b>Declined at</b>: %s\n<b>Declined reason</b>: %s"
|
|
AdminBannedMsg = "🚫 Join #request banned for %s [<code>%d</code>]\n\n<b>Join reason</b>: %s\n<b>Banned by</b>: %s\n<b>Banned at</b>: %s"
|
|
AdminFailedMsg = "⚠️ Join #request failed for %s [<code>%d</code>]\n\n<b>Join reason</b>: %s\n<b>Failure reason</b>: %s"
|
|
defaultReason = "(no reason provided, reply to this to set one, prepend with + to also send to user)"
|
|
)
|
|
|
|
// Types shared by handler files
|
|
type ExtendedChatJoinRequest struct {
|
|
*api.ChatJoinRequest
|
|
JoinReason string
|
|
JoinRequestMessageID int
|
|
}
|
|
|
|
type Bot struct {
|
|
API *api.BotAPI
|
|
Config config.Config
|
|
mu sync.RWMutex
|
|
WaitingForApproval map[int64]*ExtendedChatJoinRequest
|
|
}
|
|
|
|
// GetPendingUser retrieves a pending user request (read-safe).
|
|
func (bot *Bot) GetPendingUser(userID int64) *ExtendedChatJoinRequest {
|
|
bot.mu.RLock()
|
|
defer bot.mu.RUnlock()
|
|
return bot.WaitingForApproval[userID]
|
|
}
|
|
|
|
// SetPendingUser stores a pending user request (write-safe).
|
|
func (bot *Bot) SetPendingUser(userID int64, user *ExtendedChatJoinRequest) {
|
|
bot.mu.Lock()
|
|
defer bot.mu.Unlock()
|
|
bot.WaitingForApproval[userID] = user
|
|
}
|
|
|
|
// DeletePendingUser removes a pending user request (write-safe).
|
|
func (bot *Bot) DeletePendingUser(userID int64) {
|
|
bot.mu.Lock()
|
|
defer bot.mu.Unlock()
|
|
delete(bot.WaitingForApproval, userID)
|
|
}
|