Go generate stuff
Make types more compatible with stringer and include generate commands
This commit is contained in:
parent
0bfbf0f672
commit
c16a4c061d
3 changed files with 7 additions and 142 deletions
|
@ -7,7 +7,7 @@ import (
|
|||
// Auto-generate string names for the various constants
|
||||
//go:generate stringer -type InboundJobSource
|
||||
|
||||
type InboundJobSource uint8
|
||||
type InboundJobSource int
|
||||
|
||||
// TODO: Adjust and expand these constants later, depending on sources
|
||||
const (
|
||||
|
|
|
@ -14,11 +14,11 @@ type NoteTarget uint8
|
|||
|
||||
const (
|
||||
// The note is intended for the public
|
||||
NOTE_TARGET_PUBLIC = NoteTarget(0)
|
||||
NOTE_TARGET_PUBLIC NoteTarget = 0
|
||||
// The note is intended only for the home screen
|
||||
// not really any idea what the difference is compared to public
|
||||
// Maybe home notes don't show up on the server feed but still for everyone's home feed if it reaches them via follow or boost
|
||||
NOTE_TARGET_HOME = NoteTarget(1 << iota)
|
||||
NOTE_TARGET_HOME NoteTarget = 1 << iota
|
||||
// The note is intended only for followers
|
||||
NOTE_TARGET_FOLLOWERS
|
||||
// The note is intended only for a DM to one or more targets
|
||||
|
|
143
storage/roles.go
143
storage/roles.go
|
@ -1,11 +1,13 @@
|
|||
package storage
|
||||
|
||||
import (
|
||||
"slices"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
//go:generate go build -o RolesGenerator ../cmd/RolesColapser/main.go
|
||||
//go:generate ./RolesGenerator -input=roles.go -output=rolesUtil.go
|
||||
//go:generate rm RolesGenerator
|
||||
|
||||
// A role is, in concept, similar to how Discord handles roles
|
||||
// Some permission can be either disallowed (&false), don't care (nil) or allowed (&true)
|
||||
// Don't care just says to use the value from the next lower role where it is set
|
||||
|
@ -180,140 +182,3 @@ func (s *Storage) FindRoleByName(name string) (*Role, error) {
|
|||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func CollapseRolesIntoOne(roles ...*Role) *Role {
|
||||
// TODO: Can I make a fucking script for automating this bullshit function?
|
||||
// I. Do. Not. Want. To. Manually adjust this every time I change something about Roles
|
||||
startingRole := DefaultUserRole
|
||||
slices.SortFunc(roles, func(a, b *Role) int {
|
||||
return int(int64(a.Priority) - int64(b.Priority))
|
||||
})
|
||||
for _, role := range roles {
|
||||
if role.CanSendMedia != nil {
|
||||
*startingRole.CanSendMedia = *role.CanSendMedia
|
||||
}
|
||||
if role.CanSendCustomEmotes != nil {
|
||||
*startingRole.CanSendCustomEmotes = *role.CanSendCustomEmotes
|
||||
}
|
||||
if role.CanSendCustomReactions != nil {
|
||||
*startingRole.CanSendCustomReactions = *role.CanSendCustomReactions
|
||||
}
|
||||
if role.CanSendPublicNotes != nil {
|
||||
*startingRole.CanSendPublicNotes = *role.CanSendPublicNotes
|
||||
}
|
||||
if role.CanSendLocalNotes != nil {
|
||||
*startingRole.CanSendLocalNotes = *role.CanSendLocalNotes
|
||||
}
|
||||
if role.CanSendFollowerOnlyNotes != nil {
|
||||
*startingRole.CanSendFollowerOnlyNotes = *role.CanSendFollowerOnlyNotes
|
||||
}
|
||||
if role.CanSendPrivateNotes != nil {
|
||||
*startingRole.CanSendPrivateNotes = *role.CanSendPrivateNotes
|
||||
}
|
||||
if role.CanSendReplies != nil {
|
||||
*startingRole.CanSendReplies = *role.CanSendReplies
|
||||
}
|
||||
if role.CanQuote != nil {
|
||||
*startingRole.CanQuote = *role.CanQuote
|
||||
}
|
||||
if role.CanBoost != nil {
|
||||
*startingRole.CanBoost = *role.CanBoost
|
||||
}
|
||||
if role.CanIncludeLinks != nil {
|
||||
*startingRole.CanIncludeLinks = *role.CanIncludeLinks
|
||||
}
|
||||
if role.CanIncludeSurvey != nil {
|
||||
*startingRole.CanIncludeSurvey = *role.CanIncludeSurvey
|
||||
}
|
||||
if role.CanChangeDisplayName != nil {
|
||||
*startingRole.CanChangeDisplayName = *role.CanChangeDisplayName
|
||||
}
|
||||
if role.BlockedUsers != nil {
|
||||
startingRole.BlockedUsers = append(startingRole.BlockedUsers, role.BlockedUsers...)
|
||||
}
|
||||
if role.CanSubmitReports != nil {
|
||||
*startingRole.CanSubmitReports = *role.CanSubmitReports
|
||||
}
|
||||
if role.CanLogin != nil {
|
||||
*startingRole.CanLogin = *role.CanLogin
|
||||
}
|
||||
if role.CanMentionOthers != nil {
|
||||
*startingRole.CanMentionOthers = *role.CanMentionOthers
|
||||
}
|
||||
if role.HasMentionCountLimit != nil {
|
||||
*startingRole.HasMentionCountLimit = *role.HasMentionCountLimit
|
||||
*startingRole.MentionLimit = *role.MentionLimit
|
||||
}
|
||||
if role.AutoNsfwMedia != nil {
|
||||
*startingRole.AutoNsfwMedia = *role.AutoNsfwMedia
|
||||
}
|
||||
if role.AutoCwPosts != nil {
|
||||
*startingRole.AutoCwPosts = *role.AutoCwPosts
|
||||
}
|
||||
if role.AutoCwPostsText != nil {
|
||||
*startingRole.AutoCwPostsText = *role.AutoCwPostsText
|
||||
}
|
||||
if role.ScanCreatedPublicNotes != nil {
|
||||
*startingRole.ScanCreatedPublicNotes = *role.ScanCreatedPublicNotes
|
||||
}
|
||||
if role.ScanCreatedLocalNotes != nil {
|
||||
*startingRole.ScanCreatedLocalNotes = *role.ScanCreatedLocalNotes
|
||||
}
|
||||
if role.ScanCreatedFollowerOnlyNotes != nil {
|
||||
*startingRole.ScanCreatedFollowerOnlyNotes = *role.ScanCreatedFollowerOnlyNotes
|
||||
}
|
||||
if role.ScanCreatedPrivateNotes != nil {
|
||||
*startingRole.ScanCreatedPrivateNotes = *role.ScanCreatedPrivateNotes
|
||||
}
|
||||
if role.DisallowInteractionsWith != nil {
|
||||
startingRole.DisallowInteractionsWith = append(startingRole.DisallowInteractionsWith, role.DisallowInteractionsWith...)
|
||||
}
|
||||
if role.WithholdNotesForManualApproval != nil {
|
||||
*startingRole.WithholdNotesForManualApproval = *role.WithholdNotesForManualApproval
|
||||
}
|
||||
if role.WithholdNotesBasedOnRegex != nil {
|
||||
*startingRole.WithholdNotesBasedOnRegex = *role.WithholdNotesBasedOnRegex
|
||||
startingRole.WithholdNotesRegexes = append(startingRole.WithholdNotesRegexes, role.WithholdNotesRegexes...)
|
||||
}
|
||||
if role.FullAdmin != nil {
|
||||
*startingRole.FullAdmin = *role.FullAdmin
|
||||
}
|
||||
if role.CanAffectOtherAdmins != nil {
|
||||
*startingRole.CanAffectOtherAdmins = *role.CanAffectOtherAdmins
|
||||
}
|
||||
if role.CanDeleteNotes != nil {
|
||||
*startingRole.CanDeleteNotes = *role.CanDeleteNotes
|
||||
}
|
||||
if role.CanConfirmWithheldNotes != nil {
|
||||
*startingRole.CanConfirmWithheldNotes = *role.CanConfirmWithheldNotes
|
||||
}
|
||||
if role.CanAssignRoles != nil {
|
||||
*startingRole.CanAssignRoles = *role.CanAssignRoles
|
||||
}
|
||||
if role.CanSupressInteractionsBetweenUsers != nil {
|
||||
*startingRole.CanSupressInteractionsBetweenUsers = *role.CanSupressInteractionsBetweenUsers
|
||||
}
|
||||
if role.CanOverwriteDisplayNames != nil {
|
||||
*startingRole.CanOverwriteDisplayNames = *role.CanOverwriteDisplayNames
|
||||
}
|
||||
if role.CanManageCustomEmotes != nil {
|
||||
*startingRole.CanManageCustomEmotes = *role.CanManageCustomEmotes
|
||||
}
|
||||
if role.CanViewDeletedNotes != nil {
|
||||
*startingRole.CanViewDeletedNotes = *role.CanViewDeletedNotes
|
||||
}
|
||||
if role.CanRecoverDeletedNotes != nil {
|
||||
*startingRole.CanRecoverDeletedNotes = *role.CanRecoverDeletedNotes
|
||||
}
|
||||
if role.CanManageAvatarDecorations != nil {
|
||||
*startingRole.CanManageAvatarDecorations = *role.CanManageAvatarDecorations
|
||||
}
|
||||
if role.CanManageAds != nil {
|
||||
*startingRole.CanManageAds = *role.CanManageAds
|
||||
}
|
||||
if role.CanSendAnnouncements != nil {
|
||||
*startingRole.CanSendAnnouncements = *role.CanSendAnnouncements
|
||||
}
|
||||
}
|
||||
return &startingRole
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue