Add delete request message config, update reason text

This commit is contained in:
Astra 2026-01-30 11:44:46 +00:00
parent 9605e894eb
commit 71b12970df
2 changed files with 30 additions and 14 deletions

View file

@ -8,12 +8,13 @@ import (
) )
type Config struct { type Config struct {
BotToken string `yaml:"bot_token"` BotToken string `yaml:"bot_token"`
AdminChatId int64 `yaml:"admin_chat_id"` AdminChatId int64 `yaml:"admin_chat_id"`
AdminChatTopicId int `yaml:"admin_chat_topic_id"` AdminChatTopicId int `yaml:"admin_chat_topic_id"`
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"`
DeleteRequestAfterDecision bool `yaml:"delete_request_after_decision"`
} }
func (c *Config) LoadConfig() error { func (c *Config) LoadConfig() error {
@ -37,11 +38,12 @@ func (c *Config) CreateConfig() error {
defer f.Close() defer f.Close()
defaultConfig := Config{ defaultConfig := Config{
BotToken: "YOUR_BOT_TOKEN_HERE", BotToken: "YOUR_BOT_TOKEN_HERE",
AdminChatId: 0, AdminChatId: 0,
TargetChatId: 0, TargetChatId: 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.",
ApprovalMessage: "", ApprovalMessage: "",
DeleteRequestAfterDecision: false,
} }
encoder := yaml.NewEncoder(f) encoder := yaml.NewEncoder(f)

20
main.go
View file

@ -76,14 +76,18 @@ func main() {
if update.Message.Chat.ID == b.Config.AdminChatId && update.Message.ReplyToMessage != nil { if update.Message.Chat.ID == b.Config.AdminChatId && update.Message.ReplyToMessage != nil {
// handle admin declineion reason // handle admin declineion reason
repliedMsg := update.Message.ReplyToMessage repliedMsg := update.Message.ReplyToMessage
if strings.Contains(repliedMsg.Text, "(no reason provided, reply to this to send one)") { if strings.Contains(repliedMsg.Text, "(no reason provided, reply to this to send one, prepend with + to also send to user)") {
// now we need to make sure the one that declined it is the one replying // now we need to make sure the one that declined it is the one replying
lines := strings.Split(repliedMsg.Text, "\n") lines := strings.Split(repliedMsg.Text, "\n")
if strings.TrimPrefix(lines[3], "Declined by: ") == update.Message.From.String() { if strings.TrimPrefix(lines[3], "Declined by: ") == update.Message.From.String() {
reason := escapeHTML(update.Message.Text)
if after, ok := strings.CutPrefix(update.Message.Text, "+"); ok {
reason = escapeHTML(after)
}
userID, username, joinReason, declinedBy, declinedAt := GetInfoFromMsg(repliedMsg.Text) userID, username, joinReason, declinedBy, declinedAt := GetInfoFromMsg(repliedMsg.Text)
edit := api.NewEditMessageText(b.Config.AdminChatId, repliedMsg.MessageID, edit := api.NewEditMessageText(b.Config.AdminChatId, repliedMsg.MessageID,
fmt.Sprintf(AdminDeclinedMsg, fmt.Sprintf(AdminDeclinedMsg,
username, userID, joinReason, declinedBy, declinedAt, escapeHTML(update.Message.Text))) username, userID, joinReason, declinedBy, declinedAt, reason))
edit.ParseMode = api.ModeHTML edit.ParseMode = api.ModeHTML
b.API.Send(edit) b.API.Send(edit)
m := api.NewMessage(userID, fmt.Sprintf("Your join request was declined for the following reason:\n\n%s", m := api.NewMessage(userID, fmt.Sprintf("Your join request was declined for the following reason:\n\n%s",
@ -213,7 +217,7 @@ func (bot *Bot) handleCallbackQuery(query *api.CallbackQuery) {
} }
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, query.From.String(), time.Now().Format("2006-01-02 15:04:05"), "(no reason provided, reply to this to send one)")) userString, user.From.ID, user.JoinReason, query.From.String(), 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 edit.ParseMode = api.ModeHTML
bot.API.Send(edit) bot.API.Send(edit)
@ -221,6 +225,16 @@ func (bot *Bot) handleCallbackQuery(query *api.CallbackQuery) {
bot.API.Request(callback) bot.API.Request(callback)
} }
if bot.Config.DeleteRequestAfterDecision {
deleteTimer := time.NewTimer(10 * time.Second)
go func() {
<-deleteTimer.C
del := api.NewDeleteMessage(bot.Config.AdminChatId, user.JoinRequestMessageID)
bot.API.Send(del)
}()
}
delete(bot.WaitingForApproval, userId) delete(bot.WaitingForApproval, userId)
} }
} }