diff --git a/pkg/bot/bot.go b/pkg/bot/bot.go index 590dbe0..b7d4128 100644 --- a/pkg/bot/bot.go +++ b/pkg/bot/bot.go @@ -22,90 +22,6 @@ const ( tickerIntervalUpdateGuildEmojis = 24 * 60 ) -// UserEmoji holds a guild emoji information for a user -type UserEmoji struct { - ID string - Name string -} - -type userPrivacy uint8 - -const ( - userPrivacyNone userPrivacy = 0 - userPrivacyPart userPrivacy = 1 << iota - userPrivacyJoin userPrivacy = 1 << iota - userPrivacyStatus userPrivacy = 1 << iota - userPrivacyAll userPrivacy = 0xFF -) - -func upSet(b, flag userPrivacy) userPrivacy { return b | flag } -func upClear(b, flag userPrivacy) userPrivacy { return b &^ flag } -func upToggle(b, flag userPrivacy) userPrivacy { return b ^ flag } -func upHas(b, flag userPrivacy) bool { return b&flag != 0 } - -func (up userPrivacy) String() string { - switch up { - case userPrivacyPart: - return "part" - case userPrivacyJoin: - return "join" - case userPrivacyStatus: - return "status" - case userPrivacyAll: - return "all" - case userPrivacyNone: - return "none" - } - return "none" -} - -func userPrivacyFromString(up string) userPrivacy { - switch up { - case userPrivacyPart.String(): - return userPrivacyPart - case userPrivacyJoin.String(): - return userPrivacyJoin - case userPrivacyStatus.String(): - return userPrivacyStatus - case userPrivacyAll.String(): - return userPrivacyAll - case userPrivacyNone.String(): - return userPrivacyNone - } - return userPrivacyNone -} - -const userPrivacyDefault = userPrivacyNone - -// User is the structure for a single bot user -type User struct { - AltVRUserID string - DiscordID string - DiscordName string - DiscordEmoji UserEmoji - Role Roles - MsgMode msgMode - Privacy userPrivacy -} - -// GetDiscordEmoji If it exists, builds a discord emoji for the user -func (u *User) GetDiscordEmoji() string { - if u.DiscordEmoji.ID != "" { - return fmt.Sprintf("<:%s:%s> ", u.DiscordEmoji.Name, u.DiscordEmoji.ID) - } - return "" -} - -// Roles determines the bot user roles -type Roles uint - -// Bot user roles -const ( - RoleUser Roles = iota - RoleModerator - RoleAdmin -) - // FriendshipRequestPending data for a pending friendship request type FriendshipRequestPending struct { Friendship altvr.Friendship diff --git a/pkg/bot/user.go b/pkg/bot/user.go new file mode 100644 index 0000000..287b109 --- /dev/null +++ b/pkg/bot/user.go @@ -0,0 +1,87 @@ +package bot + +import "fmt" + +// UserEmoji holds a guild emoji information for a user +type UserEmoji struct { + ID string + Name string +} + +type userPrivacy uint8 + +const ( + userPrivacyNone userPrivacy = 0 + userPrivacyPart userPrivacy = 1 << iota + userPrivacyJoin userPrivacy = 1 << iota + userPrivacyStatus userPrivacy = 1 << iota + userPrivacyAll userPrivacy = 0xFF +) + +func upSet(b, flag userPrivacy) userPrivacy { return b | flag } +func upClear(b, flag userPrivacy) userPrivacy { return b &^ flag } +func upToggle(b, flag userPrivacy) userPrivacy { return b ^ flag } +func upHas(b, flag userPrivacy) bool { return b&flag != 0 } + +func (up userPrivacy) String() string { + switch up { + case userPrivacyPart: + return "part" + case userPrivacyJoin: + return "join" + case userPrivacyStatus: + return "status" + case userPrivacyAll: + return "all" + case userPrivacyNone: + return "none" + } + return "none" +} + +func userPrivacyFromString(up string) userPrivacy { + switch up { + case userPrivacyPart.String(): + return userPrivacyPart + case userPrivacyJoin.String(): + return userPrivacyJoin + case userPrivacyStatus.String(): + return userPrivacyStatus + case userPrivacyAll.String(): + return userPrivacyAll + case userPrivacyNone.String(): + return userPrivacyNone + } + return userPrivacyNone +} + +const userPrivacyDefault = userPrivacyNone + +// User is the structure for a single bot user +type User struct { + AltVRUserID string + DiscordID string + DiscordName string + DiscordEmoji UserEmoji + Role Roles + MsgMode msgMode + Privacy userPrivacy +} + +// GetDiscordEmoji If it exists, builds a discord emoji for the user +func (u *User) GetDiscordEmoji() string { + if u.DiscordEmoji.ID != "" { + return fmt.Sprintf("<:%s:%s> ", u.DiscordEmoji.Name, u.DiscordEmoji.ID) + } + return "" +} + +// Roles determines the bot user roles +type Roles uint + +// Bot user roles +const ( + RoleUser Roles = iota + RoleModerator + RoleAdmin +)