4
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2025-09-10 21:12:30 +00:00
Files
.github
bridge
ci
contrib
docker
gateway
hook
img
internal
matterclient
matterhook
vendor
github.com
42wim
Baozisoftware
Jeffail
Philipp15b
go-steam
cryptoutil
netutil
protocol
rwu
socialcache
chats.go
friends.go
groups.go
steamid
.gitignore
.gitmodules
LICENSE.txt
README.md
auth.go
auth_events.go
client.go
client_events.go
connection.go
doc.go
gamecoordinator.go
keys.go
notifications.go
notifications_events.go
servers.go
social.go
social_events.go
steam_directory.go
trading.go
trading_events.go
web.go
web_events.go
Rhymen
bwmarrin
d5
davecgh
dfordsoft
dgrijalva
fsnotify
go-telegram-bot-api
golang
google
gopackage
gorilla
hashicorp
jpillora
kardianos
keybase
konsorten
labstack
lrstanley
magiconair
matterbridge
mattermost
mattn
mgutz
mitchellh
mreiferson
mrexodia
nelsonken
nicksnyder
nlopes
paulrosania
pborman
pelletier
peterhellberg
pkg
pmezard
rs
russross
saintfish
shazow
sirupsen
skip2
spf13
stretchr
technoweenie
valyala
zfjagann
gitlab.com
go.uber.org
golang.org
gopkg.in
modules.txt
.fixmie.yml
.gitignore
.golangci.yaml
.goreleaser.yml
.travis.yml
Dockerfile
LICENSE
README.md
changelog.md
go.mod
go.sum
matterbridge.go
matterbridge.toml.sample
matterbridge.toml.simple
matterbridge/vendor/github.com/Philipp15b/go-steam/socialcache/groups.go
2017-06-22 01:00:27 +02:00

146 lines
3.3 KiB
Go

package socialcache
import (
"errors"
. "github.com/Philipp15b/go-steam/protocol/steamlang"
. "github.com/Philipp15b/go-steam/steamid"
"sync"
)
// Groups list is a thread safe map
// They can be iterated over like so:
// for id, group := range client.Social.Groups.GetCopy() {
// log.Println(id, group.Name)
// }
type GroupsList struct {
mutex sync.RWMutex
byId map[SteamId]*Group
}
// Returns a new groups list
func NewGroupsList() *GroupsList {
return &GroupsList{byId: make(map[SteamId]*Group)}
}
// Adds a group to the group list
func (list *GroupsList) Add(group Group) {
list.mutex.Lock()
defer list.mutex.Unlock()
_, exists := list.byId[group.SteamId]
if !exists { //make sure this doesnt already exist
list.byId[group.SteamId] = &group
}
}
// Removes a group from the group list
func (list *GroupsList) Remove(id SteamId) {
list.mutex.Lock()
defer list.mutex.Unlock()
delete(list.byId, id)
}
// Returns a copy of the groups map
func (list *GroupsList) GetCopy() map[SteamId]Group {
list.mutex.RLock()
defer list.mutex.RUnlock()
glist := make(map[SteamId]Group)
for key, group := range list.byId {
glist[key] = *group
}
return glist
}
// Returns a copy of the group of a given SteamId
func (list *GroupsList) ById(id SteamId) (Group, error) {
list.mutex.RLock()
defer list.mutex.RUnlock()
id = id.ChatToClan()
if val, ok := list.byId[id]; ok {
return *val, nil
}
return Group{}, errors.New("Group not found")
}
// Returns the number of groups
func (list *GroupsList) Count() int {
list.mutex.RLock()
defer list.mutex.RUnlock()
return len(list.byId)
}
//Setter methods
func (list *GroupsList) SetName(id SteamId, name string) {
list.mutex.Lock()
defer list.mutex.Unlock()
id = id.ChatToClan()
if val, ok := list.byId[id]; ok {
val.Name = name
}
}
func (list *GroupsList) SetAvatar(id SteamId, hash string) {
list.mutex.Lock()
defer list.mutex.Unlock()
id = id.ChatToClan()
if val, ok := list.byId[id]; ok {
val.Avatar = hash
}
}
func (list *GroupsList) SetRelationship(id SteamId, relationship EClanRelationship) {
list.mutex.Lock()
defer list.mutex.Unlock()
id = id.ChatToClan()
if val, ok := list.byId[id]; ok {
val.Relationship = relationship
}
}
func (list *GroupsList) SetMemberTotalCount(id SteamId, count uint32) {
list.mutex.Lock()
defer list.mutex.Unlock()
id = id.ChatToClan()
if val, ok := list.byId[id]; ok {
val.MemberTotalCount = count
}
}
func (list *GroupsList) SetMemberOnlineCount(id SteamId, count uint32) {
list.mutex.Lock()
defer list.mutex.Unlock()
id = id.ChatToClan()
if val, ok := list.byId[id]; ok {
val.MemberOnlineCount = count
}
}
func (list *GroupsList) SetMemberChattingCount(id SteamId, count uint32) {
list.mutex.Lock()
defer list.mutex.Unlock()
id = id.ChatToClan()
if val, ok := list.byId[id]; ok {
val.MemberChattingCount = count
}
}
func (list *GroupsList) SetMemberInGameCount(id SteamId, count uint32) {
list.mutex.Lock()
defer list.mutex.Unlock()
id = id.ChatToClan()
if val, ok := list.byId[id]; ok {
val.MemberInGameCount = count
}
}
// A Group
type Group struct {
SteamId SteamId `json:",string"`
Name string
Avatar string
Relationship EClanRelationship
MemberTotalCount uint32
MemberOnlineCount uint32
MemberChattingCount uint32
MemberInGameCount uint32
}