feat(controller): enhance message handling and user options for automatic notifications

This commit is contained in:
2026-09-03 11:57:20 +08:00
parent 2a1f5e11f8
commit 6c819f8c52
6 changed files with 134 additions and 34 deletions
+19 -8
View File
@@ -221,18 +221,29 @@ func (q *QQController) trustedGroupIDs() []string {
return nil
}
// SendMessage sends an arbitrary message (e.g. the bot initialization message)
// to all QQ trusted groups and admins.
func (q *QQController) SendMessage(message string) error {
// SendMessage sends an automatic message (e.g. the bot initialization message
// and the startup server list) to all QQ trusted groups and admins. Each
// member's opt-out options in bot_user_config.json (e.g. EventBotStarted for
// event_bot_started messages) are honored per recipient.
func (q *QQController) SendMessage(message controller.Message) error {
if !q.cfg.Enabled {
return nil
}
for _, groupID := range q.trustedGroupIDs() {
q.sendGroupMessage(groupID, message)
}
for _, adminID := range q.adminIDs() {
q.sendPrivateMessage(adminID, message)
// Only notify trusted groups and admins whose options allow this message type.
if uc := config.C_botUserConfig; uc != nil {
for groupID, opts := range uc.QQ.TrustedGroups {
if !controller.MemberReceives(opts, message.Type) {
continue
}
q.sendGroupMessage(groupID, message.Content)
}
for adminID, opts := range uc.QQ.Admins {
if !controller.MemberReceives(opts, message.Type) {
continue
}
q.sendPrivateMessage(adminID, message.Content)
}
}
return nil
}