mirror of
https://github.com/cwinfo/matterbridge.git
synced 2025-09-10 21:12:30 +00:00
.github
bridge
ci
contrib
docker
gateway
hook
img
matterclient
matterhook
vendor
github.com
42wim
BurntSushi
GeertJohan
Philipp15b
go-steam
community
cryptoutil
dota
economy
generator
gsbot
jsont
netutil
protocol
rwu
socialcache
chats.go
friends.go
groups.go
steamid
tf2
trade
tradeoffer
LICENSE.txt
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
alecthomas
armon
bwmarrin
coreos
daaku
davecgh
dfordsoft
dgrijalva
facebookgo
fsnotify
go-telegram-bot-api
golang
google
gorilla
hashicorp
jpillora
kardianos
kr
labstack
lrstanley
magiconair
matrix-org
matterbridge
mattermost
mattn
mgutz
mitchellh
mreiferson
mrexodia
nicksnyder
nlopes
paulrosania
pborman
pelletier
peterhellberg
pkg
rs
russross
saintfish
satori
shazow
shurcooL
sirupsen
sorcix
spf13
stretchr
technoweenie
tylerb
valyala
x-cray
xordataexchange
zfjagann
golang.org
gopkg.in
manifest
.travis.yml
Dockerfile
LICENSE
README.md
changelog.md
matterbridge.go
matterbridge.toml.sample
matterbridge.toml.simple
146 lines
3.3 KiB
Go
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
|
|
}
|