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:
parent
2aa1a32d64
commit
b7b1065abb
12
bridge.go
12
bridge.go
@ -18,7 +18,6 @@ type BridgeState struct {
|
|||||||
ActiveConn chan bool
|
ActiveConn chan bool
|
||||||
Connected bool
|
Connected bool
|
||||||
Client *gumble.Client
|
Client *gumble.Client
|
||||||
CurrentChannel *gumble.Channel
|
|
||||||
DiscordUsers map[string]bool
|
DiscordUsers map[string]bool
|
||||||
MumbleUserCount int
|
MumbleUserCount int
|
||||||
DiscordUserCount int
|
DiscordUserCount int
|
||||||
@ -33,7 +32,6 @@ func startBridge(discord *discordgo.Session, discordGID string, discordCID strin
|
|||||||
}
|
}
|
||||||
defer dgv.Speaking(false)
|
defer dgv.Speaking(false)
|
||||||
defer dgv.Close()
|
defer dgv.Close()
|
||||||
Bridge.Connected = true
|
|
||||||
discord.ShouldReconnectOnError = true
|
discord.ShouldReconnectOnError = true
|
||||||
|
|
||||||
// MUMBLE Setup
|
// MUMBLE Setup
|
||||||
@ -58,10 +56,10 @@ func startBridge(discord *discordgo.Session, discordGID string, discordCID strin
|
|||||||
if BridgeConf.MumbleChannel != "" {
|
if BridgeConf.MumbleChannel != "" {
|
||||||
//join specified channel
|
//join specified channel
|
||||||
startingChannel := mumble.Channels.Find(BridgeConf.MumbleChannel)
|
startingChannel := mumble.Channels.Find(BridgeConf.MumbleChannel)
|
||||||
|
if startingChannel != nil {
|
||||||
mumble.Self.Move(startingChannel)
|
mumble.Self.Move(startingChannel)
|
||||||
Bridge.CurrentChannel = startingChannel
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Shared Channels
|
// Shared Channels
|
||||||
// Shared channels pass PCM information in 10ms chunks [480]int16
|
// Shared channels pass PCM information in 10ms chunks [480]int16
|
||||||
var toMumble = mumble.AudioOutgoing()
|
var toMumble = mumble.AudioOutgoing()
|
||||||
@ -106,7 +104,6 @@ func startBridge(discord *discordgo.Session, discordGID string, discordCID strin
|
|||||||
|
|
||||||
//Setup initial discord state
|
//Setup initial discord state
|
||||||
g, err := discord.State.Guild(discordGID)
|
g, err := discord.State.Guild(discordGID)
|
||||||
Bridge.DiscordUsers = make(map[string]bool)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("error finding guild")
|
log.Println("error finding guild")
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -118,10 +115,11 @@ func startBridge(discord *discordgo.Session, discordGID string, discordCID strin
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("error looking up username")
|
log.Println("error looking up username")
|
||||||
Bridge.DiscordUsers[u.Username] = true
|
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 {
|
select {
|
||||||
case sig := <-c:
|
case sig := <-c:
|
||||||
@ -137,7 +135,7 @@ func startBridge(discord *discordgo.Session, discordGID string, discordCID strin
|
|||||||
Bridge.Client = nil
|
Bridge.Client = nil
|
||||||
Bridge.MumbleUserCount = 0
|
Bridge.MumbleUserCount = 0
|
||||||
Bridge.DiscordUserCount = 0
|
Bridge.DiscordUserCount = 0
|
||||||
Bridge.DiscordUsers = nil
|
Bridge.DiscordUsers = make(map[string]bool)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,9 +151,10 @@ func voiceUpdate(s *discordgo.Session, event *discordgo.VoiceStateUpdate) {
|
|||||||
}
|
}
|
||||||
log.Println("user joined watched discord channel")
|
log.Println("user joined watched discord channel")
|
||||||
if Bridge.Connected {
|
if Bridge.Connected {
|
||||||
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.DiscordUsers[u.Username] = true
|
|
||||||
}
|
}
|
||||||
|
Bridge.DiscordUsers[u.Username] = true
|
||||||
|
log.Println(Bridge.DiscordUsers)
|
||||||
Bridge.DiscordUserCount = Bridge.DiscordUserCount + 1
|
Bridge.DiscordUserCount = Bridge.DiscordUserCount + 1
|
||||||
}
|
}
|
||||||
if event.ChannelID == "" {
|
if event.ChannelID == "" {
|
||||||
@ -179,7 +180,9 @@ func voiceUpdate(s *discordgo.Session, event *discordgo.VoiceStateUpdate) {
|
|||||||
}
|
}
|
||||||
delete(Bridge.DiscordUsers, u.Username)
|
delete(Bridge.DiscordUsers, u.Username)
|
||||||
log.Println("user left watched discord channel")
|
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
|
Bridge.DiscordUserCount = count
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
5
main.go
5
main.go
@ -51,6 +51,10 @@ func main() {
|
|||||||
if *discordCID == "" {
|
if *discordCID == "" {
|
||||||
log.Fatalln("missing discord cid")
|
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
|
// DISCORD Setup
|
||||||
|
|
||||||
@ -98,6 +102,7 @@ func main() {
|
|||||||
Connected: false,
|
Connected: false,
|
||||||
MumbleUserCount: 0,
|
MumbleUserCount: 0,
|
||||||
DiscordUserCount: 0,
|
DiscordUserCount: 0,
|
||||||
|
DiscordUsers: make(map[string]bool),
|
||||||
}
|
}
|
||||||
go discordStatusUpdate(discord, *mumbleAddr, strconv.Itoa(*mumblePort))
|
go discordStatusUpdate(discord, *mumbleAddr, strconv.Itoa(*mumblePort))
|
||||||
if *autoMode {
|
if *autoMode {
|
||||||
|
Loading…
Reference in New Issue
Block a user