mirror of
https://github.com/stryan/mumble-discord-bridge.git
synced 2024-11-14 19:45:41 -05:00
send message in mumble when user joins in discord
This commit is contained in:
parent
ba29c23cae
commit
f63b9d005c
20
bridge.go
20
bridge.go
@ -14,6 +14,16 @@ import (
|
|||||||
"layeh.com/gumble/gumble"
|
"layeh.com/gumble/gumble"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type BridgeState struct {
|
||||||
|
ActiveConn chan bool
|
||||||
|
Connected bool
|
||||||
|
Client *gumble.Client
|
||||||
|
CurrentChannel *gumble.Channel
|
||||||
|
MumbleUserCount int
|
||||||
|
DiscordUserCount int
|
||||||
|
AutoChan chan bool
|
||||||
|
}
|
||||||
|
|
||||||
func startBridge(discord *discordgo.Session, discordGID string, discordCID string, config *gumble.Config, mumbleAddr string, mumbleInsecure bool, die chan bool) {
|
func startBridge(discord *discordgo.Session, discordGID string, discordCID string, config *gumble.Config, mumbleAddr string, mumbleInsecure bool, die chan bool) {
|
||||||
dgv, err := discord.ChannelVoiceJoin(discordGID, discordCID, false, false)
|
dgv, err := discord.ChannelVoiceJoin(discordGID, discordCID, false, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -43,6 +53,13 @@ func startBridge(discord *discordgo.Session, discordGID string, discordCID strin
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer mumble.Disconnect()
|
defer mumble.Disconnect()
|
||||||
|
Bridge.Client = mumble
|
||||||
|
if BridgeConf.MumbleChannel != "" {
|
||||||
|
//join specified channel
|
||||||
|
startingChannel := mumble.Channels.Find(BridgeConf.MumbleChannel)
|
||||||
|
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
|
||||||
@ -97,6 +114,9 @@ func startBridge(discord *discordgo.Session, discordGID string, discordCID strin
|
|||||||
close(m.Close)
|
close(m.Close)
|
||||||
close(toMumble)
|
close(toMumble)
|
||||||
Bridge.Connected = false
|
Bridge.Connected = false
|
||||||
|
Bridge.Client = nil
|
||||||
|
Bridge.MumbleUserCount = 0
|
||||||
|
Bridge.DiscordUserCount = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,20 +14,13 @@ type BridgeConfig struct {
|
|||||||
Config *gumble.Config
|
Config *gumble.Config
|
||||||
MumbleAddr string
|
MumbleAddr string
|
||||||
MumbleInsecure bool
|
MumbleInsecure bool
|
||||||
|
MumbleChannel string
|
||||||
Auto bool
|
Auto bool
|
||||||
Command string
|
Command string
|
||||||
GID string
|
GID string
|
||||||
CID string
|
CID string
|
||||||
}
|
}
|
||||||
|
|
||||||
type BridgeState struct {
|
|
||||||
ActiveConn chan bool
|
|
||||||
Connected bool
|
|
||||||
MumbleUserCount int
|
|
||||||
DiscordUserCount int
|
|
||||||
AutoChan chan bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func lookupEnvOrString(key string, defaultVal string) string {
|
func lookupEnvOrString(key string, defaultVal string) string {
|
||||||
if val, ok := os.LookupEnv(key); ok {
|
if val, ok := os.LookupEnv(key); ok {
|
||||||
return val
|
return val
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -139,6 +140,12 @@ func voiceUpdate(s *discordgo.Session, event *discordgo.VoiceStateUpdate) {
|
|||||||
if event.GuildID == BridgeConf.GID {
|
if event.GuildID == BridgeConf.GID {
|
||||||
if event.ChannelID == BridgeConf.CID {
|
if event.ChannelID == BridgeConf.CID {
|
||||||
log.Println("user joined watched discord channel")
|
log.Println("user joined watched discord channel")
|
||||||
|
u, err := s.User(event.UserID)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("error looking up user for uid %v", event.UserID)
|
||||||
|
} else {
|
||||||
|
Bridge.CurrentChannel.Send(fmt.Sprintf("%v has joined Discord channel\n", u.Username), false)
|
||||||
|
}
|
||||||
Bridge.DiscordUserCount = Bridge.DiscordUserCount + 1
|
Bridge.DiscordUserCount = Bridge.DiscordUserCount + 1
|
||||||
}
|
}
|
||||||
if event.ChannelID == "" {
|
if event.ChannelID == "" {
|
||||||
|
Loading…
Reference in New Issue
Block a user