|
|
|
@ -28,6 +28,55 @@ type UserEmoji struct {
|
|
|
|
Name 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
|
|
|
|
// User is the structure for a single bot user
|
|
|
|
type User struct {
|
|
|
|
type User struct {
|
|
|
|
AltVRUserID string
|
|
|
|
AltVRUserID string
|
|
|
|
@ -36,6 +85,7 @@ type User struct {
|
|
|
|
DiscordEmoji UserEmoji
|
|
|
|
DiscordEmoji UserEmoji
|
|
|
|
Role Roles
|
|
|
|
Role Roles
|
|
|
|
MsgMode msgMode
|
|
|
|
MsgMode msgMode
|
|
|
|
|
|
|
|
Privacy userPrivacy
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetDiscordEmoji If it exists, builds a discord emoji for the user
|
|
|
|
// GetDiscordEmoji If it exists, builds a discord emoji for the user
|
|
|
|
@ -190,15 +240,23 @@ func (b *Type) periodicTicker() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (b *Type) userConnected(u altvr.User) {
|
|
|
|
func (b *Type) userConnected(u altvr.User) {
|
|
|
|
|
|
|
|
uu, err := b.getUserByAltVRUserID(u.UserID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
s := fmt.Sprintf("%s**%s is now online in %s!**", b.getUserEmojiByAltVRUser(u), u.GetDisplayName(), u.CurrentSpace.Name)
|
|
|
|
s := fmt.Sprintf("%s**%s is now online in %s!**", b.getUserEmojiByAltVRUser(u), u.GetDisplayName(), u.CurrentSpace.Name)
|
|
|
|
if !b.isQuiet {
|
|
|
|
if !b.isQuiet && !upHas(uu.Privacy, userPrivacyJoin) {
|
|
|
|
b.dg.Session.ChannelMessageSend(b.DGcID, s)
|
|
|
|
b.dg.Session.ChannelMessageSend(b.DGcID, s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (b *Type) userDisconnected(u altvr.User) {
|
|
|
|
func (b *Type) userDisconnected(u altvr.User) {
|
|
|
|
|
|
|
|
uu, err := b.getUserByAltVRUserID(u.UserID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
s := fmt.Sprintf("%s_%s is now offline!_", b.getUserEmojiByAltVRUser(u), u.GetDisplayName())
|
|
|
|
s := fmt.Sprintf("%s_%s is now offline!_", b.getUserEmojiByAltVRUser(u), u.GetDisplayName())
|
|
|
|
if !b.isQuiet {
|
|
|
|
if !b.isQuiet && !upHas(uu.Privacy, userPrivacyPart) {
|
|
|
|
b.dg.Session.ChannelMessageSend(b.DGcID, s)
|
|
|
|
b.dg.Session.ChannelMessageSend(b.DGcID, s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -294,34 +352,34 @@ func (b *Type) getUserEmojiByAltVRUser(au altvr.User) string {
|
|
|
|
return ""
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (b *Type) getUserByAltVRUserID(avrID string) (User, error) {
|
|
|
|
func (b *Type) getUserByAltVRUserID(avrID string) (*User, error) {
|
|
|
|
for _, u := range b.users {
|
|
|
|
for k, u := range b.users {
|
|
|
|
if u.AltVRUserID == avrID {
|
|
|
|
if u.AltVRUserID == avrID {
|
|
|
|
return u, nil
|
|
|
|
return &b.users[k], nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return User{}, errors.New("User not found")
|
|
|
|
return &User{}, errors.New("User not found")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (b *Type) getUserByDiscordID(discordID string) (User, error) {
|
|
|
|
func (b *Type) getUserByDiscordID(discordID string) (*User, error) {
|
|
|
|
for _, u := range b.users {
|
|
|
|
for k, u := range b.users {
|
|
|
|
if u.DiscordID == discordID {
|
|
|
|
if u.DiscordID == discordID {
|
|
|
|
return u, nil
|
|
|
|
return &b.users[k], nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return User{}, errors.New("User not found")
|
|
|
|
return &User{}, errors.New("User not found")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (b *Type) getUserByDiscordName(discordName string) (User, error) {
|
|
|
|
func (b *Type) getUserByDiscordName(discordName string) (*User, error) {
|
|
|
|
for _, u := range b.users {
|
|
|
|
for k, u := range b.users {
|
|
|
|
if u.DiscordName == discordName {
|
|
|
|
if u.DiscordName == discordName {
|
|
|
|
return u, nil
|
|
|
|
return &b.users[k], nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return User{}, errors.New("User not found")
|
|
|
|
return &User{}, errors.New("User not found")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (b *Type) buildMention(uu User) string {
|
|
|
|
func (b *Type) buildMention(uu *User) string {
|
|
|
|
var msg string
|
|
|
|
var msg string
|
|
|
|
if uu.DiscordEmoji.Name != "" {
|
|
|
|
if uu.DiscordEmoji.Name != "" {
|
|
|
|
msg = fmt.Sprintf("<:%s:%s> ", uu.DiscordEmoji.Name, uu.DiscordEmoji.ID)
|
|
|
|
msg = fmt.Sprintf("<:%s:%s> ", uu.DiscordEmoji.Name, uu.DiscordEmoji.ID)
|
|
|
|
|