✨ Notify punishments
This commit is contained in:
parent
a5033c0fb0
commit
de28ae027f
@ -7,5 +7,12 @@
|
||||
"subjectLoginAlert": "Login alert",
|
||||
"shortBodyLoginAlert": "Your account got logged in from %s. If it's not your device, please deal with it immediately.",
|
||||
"subjectAbuseReportUpdated": "Abuse report status has been changed",
|
||||
"shortBodyAbuseReportUpdated": "Report #%d has been changed to %s. Moderator message: %s"
|
||||
}
|
||||
"shortBodyAbuseReportUpdated": "Report #%d has been changed to %s. Moderator message: %s",
|
||||
"subtitlePunishment": "Case #%d Moderated by %s",
|
||||
"subjectPunishmentCreated": "You have been punished",
|
||||
"shortBodyPunishmentCreated": "You have been punished for %s. Learn more inside the app.",
|
||||
"subjectPunishmentUpdated": "Your punishment has been updated",
|
||||
"shortBodyPunishmentUpdated": "Your punishment #%s has been updated. Learn more inside the app.",
|
||||
"subjectPunishmentDeleted": "Your punishment has been revoked",
|
||||
"shortBodyPunishmentDeleted": "Your punishment #%s has been revoked."
|
||||
}
|
||||
|
@ -7,5 +7,12 @@
|
||||
"subjectLoginAlert": "登陆提醒",
|
||||
"shortBodyLoginAlert": "您的帐户在 %s 登录,若它不是你的设备,请立即处理。",
|
||||
"subjectAbuseReportUpdated": "举报状态已更新",
|
||||
"shortBodyAbuseReportUpdated": "举报 #%d 已更新为 %s。管理员回复:%s"
|
||||
}
|
||||
"shortBodyAbuseReportUpdated": "举报 #%d 已更新为 %s。管理员回复:%s",
|
||||
"subtitlePunishment": "案件 #%d 由 %s 处理",
|
||||
"subjectPunishmentCreated": "你收到了一份处分",
|
||||
"shortBodyPunishmentCreated": "你因为 %s 而被处分,详情请在应用内查看。",
|
||||
"subjectPunishmentUpdated": "你的处分已更新",
|
||||
"shortBodyPunishmentUpdated": "你的处分 #%s 已更新。详情请在应用内查看。",
|
||||
"subjectPunishmentDeleted": "你的处分已撤销",
|
||||
"shortBodyPunishmentDeleted": "你的处分 #%s 已撤销。"
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ var AutoMaintainRange = []any{
|
||||
&models.AbuseReport{},
|
||||
&models.Program{},
|
||||
&models.ProgramMember{},
|
||||
&models.Punishment{},
|
||||
}
|
||||
|
||||
func RunMigration(source *gorm.DB) error {
|
||||
|
@ -4,8 +4,10 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/localize"
|
||||
"git.solsynth.dev/hypernet/passport/pkg/authkit/models"
|
||||
"git.solsynth.dev/hypernet/passport/pkg/internal/database"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func NewPunishment(in models.Punishment, moderator ...models.Account) (models.Punishment, error) {
|
||||
@ -29,21 +31,72 @@ func NewPunishment(in models.Punishment, moderator ...models.Account) (models.Pu
|
||||
|
||||
if err := database.C.Create(&in).Error; err != nil {
|
||||
return in, err
|
||||
} else {
|
||||
var moderator = "System"
|
||||
if in.Moderator != nil {
|
||||
moderator = fmt.Sprintf("@%s", in.Moderator.Name)
|
||||
}
|
||||
err = NewNotification(models.Notification{
|
||||
Topic: "passport.punishments",
|
||||
Title: localize.L.GetLocalizedString("subjectPunishmentCreated", in.Account.Language),
|
||||
Subtitle: fmt.Sprintf(localize.L.GetLocalizedString("subtitlePunishment", in.Account.Language), in.ID, moderator),
|
||||
Body: fmt.Sprintf(localize.L.GetLocalizedString("shortBodyPunishmentCreated", in.Account.Language), in.Reason),
|
||||
Account: in.Account,
|
||||
AccountID: in.Account.ID,
|
||||
Metadata: map[string]any{"punishment": in},
|
||||
})
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Uint("case", in.ID).Msg("Failed to delivery punishment via notify...")
|
||||
}
|
||||
}
|
||||
|
||||
return in, nil
|
||||
}
|
||||
|
||||
func EditPunishment(punishment models.Punishment) (models.Punishment, error) {
|
||||
if err := database.C.Save(&punishment).Error; err != nil {
|
||||
return punishment, err
|
||||
func EditPunishment(in models.Punishment) (models.Punishment, error) {
|
||||
if err := database.C.Save(&in).Error; err != nil {
|
||||
return in, err
|
||||
} else {
|
||||
var moderator = "System"
|
||||
if in.Moderator != nil {
|
||||
moderator = fmt.Sprintf("@%s", in.Moderator.Name)
|
||||
}
|
||||
err = NewNotification(models.Notification{
|
||||
Topic: "passport.punishments",
|
||||
Title: localize.L.GetLocalizedString("subjectPunishmentUpdated", in.Account.Language),
|
||||
Subtitle: fmt.Sprintf(localize.L.GetLocalizedString("subtitlePunishment", in.Account.Language), in.ID, moderator),
|
||||
Body: fmt.Sprintf(localize.L.GetLocalizedString("shortBodyPunishmentUpdated", in.Account.Language), in.ID),
|
||||
Account: in.Account,
|
||||
AccountID: in.Account.ID,
|
||||
Metadata: map[string]any{"punishment": in},
|
||||
})
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Uint("case", in.ID).Msg("Failed to delivery punishment via notify...")
|
||||
}
|
||||
}
|
||||
return punishment, nil
|
||||
return in, nil
|
||||
}
|
||||
|
||||
func DeletePunishment(punishment models.Punishment) error {
|
||||
if err := database.C.Delete(&punishment).Error; err != nil {
|
||||
func DeletePunishment(in models.Punishment) error {
|
||||
if err := database.C.Delete(&in).Error; err != nil {
|
||||
return err
|
||||
} else {
|
||||
var moderator = "System"
|
||||
if in.Moderator != nil {
|
||||
moderator = fmt.Sprintf("@%s", in.Moderator.Name)
|
||||
}
|
||||
err = NewNotification(models.Notification{
|
||||
Topic: "passport.punishments",
|
||||
Title: localize.L.GetLocalizedString("subjectPunishmentDeleted", in.Account.Language),
|
||||
Subtitle: fmt.Sprintf(localize.L.GetLocalizedString("subtitlePunishment", in.Account.Language), in.ID, moderator),
|
||||
Body: fmt.Sprintf(localize.L.GetLocalizedString("shortBodyPunishmentDeleted", in.Account.Language), in.ID),
|
||||
Account: in.Account,
|
||||
AccountID: in.Account.ID,
|
||||
Metadata: map[string]any{"punishment": in},
|
||||
})
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Uint("case", in.ID).Msg("Failed to delivery punishment via notify...")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user