1
0
mirror of https://github.com/stryan/mumble-discord-bridge.git synced 2024-11-14 19:45:41 -05:00

use mumble client more,finally get user count right

This commit is contained in:
stryan 2021-01-05 11:41:33 -05:00
parent 2aa1a32d64
commit b7b1065abb
3 changed files with 17 additions and 11 deletions

View File

@ -18,7 +18,6 @@ type BridgeState struct {
ActiveConn chan bool
Connected bool
Client *gumble.Client
CurrentChannel *gumble.Channel
DiscordUsers map[string]bool
MumbleUserCount int
DiscordUserCount int
@ -33,7 +32,6 @@ func startBridge(discord *discordgo.Session, discordGID string, discordCID strin
}
defer dgv.Speaking(false)
defer dgv.Close()
Bridge.Connected = true
discord.ShouldReconnectOnError = true
// MUMBLE Setup
@ -58,10 +56,10 @@ func startBridge(discord *discordgo.Session, discordGID string, discordCID strin
if BridgeConf.MumbleChannel != "" {
//join specified channel
startingChannel := mumble.Channels.Find(BridgeConf.MumbleChannel)
mumble.Self.Move(startingChannel)
Bridge.CurrentChannel = startingChannel
if startingChannel != nil {
mumble.Self.Move(startingChannel)
}
}
// Shared Channels
// Shared channels pass PCM information in 10ms chunks [480]int16
var toMumble = mumble.AudioOutgoing()
@ -106,7 +104,6 @@ func startBridge(discord *discordgo.Session, discordGID string, discordCID strin
//Setup initial discord state
g, err := discord.State.Guild(discordGID)
Bridge.DiscordUsers = make(map[string]bool)
if err != nil {
log.Println("error finding guild")
panic(err)
@ -118,10 +115,11 @@ func startBridge(discord *discordgo.Session, discordGID string, discordCID strin
if err != nil {
log.Println("error looking up username")
Bridge.DiscordUsers[u.Username] = true
Bridge.CurrentChannel.Send(fmt.Sprintf("%v has joined Discord channel\n", u.Username), false)
Bridge.Client.Self.Channel.Send(fmt.Sprintf("%v has joined Discord channel\n", u.Username), false)
}
}
}
Bridge.Connected = true
select {
case sig := <-c:
@ -137,7 +135,7 @@ func startBridge(discord *discordgo.Session, discordGID string, discordCID strin
Bridge.Client = nil
Bridge.MumbleUserCount = 0
Bridge.DiscordUserCount = 0
Bridge.DiscordUsers = nil
Bridge.DiscordUsers = make(map[string]bool)
}
}

View File

@ -151,9 +151,10 @@ func voiceUpdate(s *discordgo.Session, event *discordgo.VoiceStateUpdate) {
}
log.Println("user joined watched discord channel")
if Bridge.Connected {
Bridge.CurrentChannel.Send(fmt.Sprintf("%v has joined Discord channel\n", u.Username), false)
Bridge.DiscordUsers[u.Username] = true
Bridge.Client.Self.Channel.Send(fmt.Sprintf("%v has joined Discord channel\n", u.Username), false)
}
Bridge.DiscordUsers[u.Username] = true
log.Println(Bridge.DiscordUsers)
Bridge.DiscordUserCount = Bridge.DiscordUserCount + 1
}
if event.ChannelID == "" {
@ -179,7 +180,9 @@ func voiceUpdate(s *discordgo.Session, event *discordgo.VoiceStateUpdate) {
}
delete(Bridge.DiscordUsers, u.Username)
log.Println("user left watched discord channel")
Bridge.CurrentChannel.Send(fmt.Sprintf("%v has left Discord channel\n", u.Username), false)
if Bridge.Connected {
Bridge.Client.Self.Channel.Send(fmt.Sprintf("%v has left Discord channel\n", u.Username), false)
}
Bridge.DiscordUserCount = count
}
}

View File

@ -51,6 +51,10 @@ func main() {
if *discordCID == "" {
log.Fatalln("missing discord cid")
}
err := syscall.Setpriority(syscall.PRIO_PROCESS, os.Getpid(), -5)
if err != nil {
log.Println("Unable to set priority. ", err)
}
// DISCORD Setup
@ -98,6 +102,7 @@ func main() {
Connected: false,
MumbleUserCount: 0,
DiscordUserCount: 0,
DiscordUsers: make(map[string]bool),
}
go discordStatusUpdate(discord, *mumbleAddr, strconv.Itoa(*mumblePort))
if *autoMode {