mirror of
https://github.com/stryan/mumble-discord-bridge.git
synced 2024-11-14 11:45:40 -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"
|
||||
)
|
||||
|
||||
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) {
|
||||
dgv, err := discord.ChannelVoiceJoin(discordGID, discordCID, false, false)
|
||||
if err != nil {
|
||||
@ -43,6 +53,13 @@ func startBridge(discord *discordgo.Session, discordGID string, discordCID strin
|
||||
return
|
||||
}
|
||||
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 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(toMumble)
|
||||
Bridge.Connected = false
|
||||
Bridge.Client = nil
|
||||
Bridge.MumbleUserCount = 0
|
||||
Bridge.DiscordUserCount = 0
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,20 +14,13 @@ type BridgeConfig struct {
|
||||
Config *gumble.Config
|
||||
MumbleAddr string
|
||||
MumbleInsecure bool
|
||||
MumbleChannel string
|
||||
Auto bool
|
||||
Command string
|
||||
GID 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 {
|
||||
if val, ok := os.LookupEnv(key); ok {
|
||||
return val
|
||||
|
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
@ -139,6 +140,12 @@ func voiceUpdate(s *discordgo.Session, event *discordgo.VoiceStateUpdate) {
|
||||
if event.GuildID == BridgeConf.GID {
|
||||
if event.ChannelID == BridgeConf.CID {
|
||||
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
|
||||
}
|
||||
if event.ChannelID == "" {
|
||||
|
Loading…
Reference in New Issue
Block a user