mirror of
https://github.com/stryan/mumble-discord-bridge.git
synced 2024-11-23 05:45:41 -05:00
commit
bf166f7a9c
25
README.md
25
README.md
@ -13,9 +13,9 @@ The binary will also attempt to load .env file located in the working directory.
|
|||||||
```bash
|
```bash
|
||||||
Usage of mumble-discord-bridge:
|
Usage of mumble-discord-bridge:
|
||||||
-discord-cid string
|
-discord-cid string
|
||||||
DISCORD_CID, discord cid
|
DISCORD_CID, discord channel ID
|
||||||
-discord-gid string
|
-discord-gid string
|
||||||
DISCORD_GID, discord gid
|
DISCORD_GID, discord guild ID
|
||||||
-discord-token string
|
-discord-token string
|
||||||
DISCORD_TOKEN, discord bot token
|
DISCORD_TOKEN, discord bot token
|
||||||
-discord-command string
|
-discord-command string
|
||||||
@ -32,13 +32,24 @@ Usage of mumble-discord-bridge:
|
|||||||
MUMBLE_INSECURE, allow connection to insecure (invalid TLS cert) mumble server
|
MUMBLE_INSECURE, allow connection to insecure (invalid TLS cert) mumble server
|
||||||
-mumble-channel string
|
-mumble-channel string
|
||||||
MUMBLE_CHANNEL, pick what channel the bridge joins in Mumble. Must be a direct child of Root.
|
MUMBLE_CHANNEL, pick what channel the bridge joins in Mumble. Must be a direct child of Root.
|
||||||
-auto-mode bool
|
-mode string
|
||||||
AUTO_MODE, enables the bridge to automatically start if there's users in both Discord and Mumble
|
MODE, determines what mode the bridge starts in
|
||||||
```
|
```
|
||||||
|
|
||||||
The bridge can be manually controlled in Discord with the following commands:
|
The bridge can be run with the follow modes:
|
||||||
|
```bash
|
||||||
|
auto
|
||||||
|
The bridge starts up but does not connect immediately. It can be either manually linked (see below) or will join the voice channels when there's at least one person on each side.
|
||||||
|
The bridge will leave both voice channels once there is no one on either end
|
||||||
|
manual
|
||||||
|
The bridge starts up but does not connect immediately. It will join the voice channels when issued the link command and will leave with the unlink command
|
||||||
|
constant
|
||||||
|
The bridge starts up and immediately connects to both Discord and Mumble voice channels. It can not be controlled in this mode and quits when the program is stopped
|
||||||
```
|
```
|
||||||
|
|
||||||
|
In "auto" or "manual" modes, the bridge can be controlled in Discord with the following commands:
|
||||||
|
|
||||||
|
```bash
|
||||||
!DISCORD_COMMAND link
|
!DISCORD_COMMAND link
|
||||||
Commands the bridge to join the Discord channel the user is in and the Mumble server
|
Commands the bridge to join the Discord channel the user is in and the Mumble server
|
||||||
!DISCORD_COMMAND unlink
|
!DISCORD_COMMAND unlink
|
||||||
@ -46,7 +57,7 @@ The bridge can be manually controlled in Discord with the following commands:
|
|||||||
!DISCORD_COMMAND refresh
|
!DISCORD_COMMAND refresh
|
||||||
Commands the bridge to unlink, then link again.
|
Commands the bridge to unlink, then link again.
|
||||||
!DISCORD_COMMAND auto
|
!DISCORD_COMMAND auto
|
||||||
Toggle AUTO_MODE
|
Toggle between manual and auto mode
|
||||||
```
|
```
|
||||||
## Setup
|
## Setup
|
||||||
|
|
||||||
|
10
config.go
10
config.go
@ -10,12 +10,20 @@ import (
|
|||||||
"layeh.com/gumble/gumble"
|
"layeh.com/gumble/gumble"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type BridgeMode int
|
||||||
|
|
||||||
|
const (
|
||||||
|
BridgeModeAuto BridgeMode = iota
|
||||||
|
BridgeModeManual
|
||||||
|
BridgeModeConstant
|
||||||
|
)
|
||||||
|
|
||||||
type BridgeConfig struct {
|
type BridgeConfig struct {
|
||||||
Config *gumble.Config
|
Config *gumble.Config
|
||||||
MumbleAddr string
|
MumbleAddr string
|
||||||
MumbleInsecure bool
|
MumbleInsecure bool
|
||||||
MumbleChannel string
|
MumbleChannel string
|
||||||
Auto bool
|
Mode BridgeMode
|
||||||
Command string
|
Command string
|
||||||
GID string
|
GID string
|
||||||
CID string
|
CID string
|
||||||
|
12
handlers.go
12
handlers.go
@ -15,9 +15,11 @@ func ready(s *discordgo.Session, event *discordgo.Ready) {
|
|||||||
|
|
||||||
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
|
|
||||||
|
if BridgeConf.Mode == BridgeModeConstant {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Ignore all messages created by the bot itself
|
// Ignore all messages created by the bot itself
|
||||||
// This isn't required in this specific example but it's a good practice.
|
|
||||||
log.Println("Checking message")
|
|
||||||
if m.Author.ID == s.State.User.ID {
|
if m.Author.ID == s.State.User.ID {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -111,13 +113,13 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(m.Content, prefix+" auto") {
|
if strings.HasPrefix(m.Content, prefix+" auto") {
|
||||||
if BridgeConf.Auto == false {
|
if BridgeConf.Mode != BridgeModeAuto {
|
||||||
BridgeConf.Auto = true
|
BridgeConf.Mode = BridgeModeAuto
|
||||||
Bridge.AutoChan = make(chan bool)
|
Bridge.AutoChan = make(chan bool)
|
||||||
go AutoBridge(s)
|
go AutoBridge(s)
|
||||||
} else {
|
} else {
|
||||||
Bridge.AutoChan <- true
|
Bridge.AutoChan <- true
|
||||||
BridgeConf.Auto = false
|
BridgeConf.Mode = BridgeModeManual
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
26
main.go
26
main.go
@ -31,7 +31,7 @@ func main() {
|
|||||||
discordGID := flag.String("discord-gid", lookupEnvOrString("DISCORD_GID", ""), "DISCORD_GID, discord gid")
|
discordGID := flag.String("discord-gid", lookupEnvOrString("DISCORD_GID", ""), "DISCORD_GID, discord gid")
|
||||||
discordCID := flag.String("discord-cid", lookupEnvOrString("DISCORD_CID", ""), "DISCORD_CID, discord cid")
|
discordCID := flag.String("discord-cid", lookupEnvOrString("DISCORD_CID", ""), "DISCORD_CID, discord cid")
|
||||||
discordCommand := flag.String("discord-command", lookupEnvOrString("DISCORD_COMMAND", "mumble-discord"), "Discord command string, env alt DISCORD_COMMAND, optional, defaults to mumble-discord")
|
discordCommand := flag.String("discord-command", lookupEnvOrString("DISCORD_COMMAND", "mumble-discord"), "Discord command string, env alt DISCORD_COMMAND, optional, defaults to mumble-discord")
|
||||||
autoMode := flag.Bool("auto-mode", lookupEnvOrBool("AUTO_MODE", false), "bridge starts in auto mode")
|
mode := flag.String("mode", lookupEnvOrString("MODE", "manual"), "determine which mode the bridge starts in")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
log.Printf("app.config %v\n", getConfig(flag.CommandLine))
|
log.Printf("app.config %v\n", getConfig(flag.CommandLine))
|
||||||
|
|
||||||
@ -51,6 +51,9 @@ func main() {
|
|||||||
if *discordCID == "" {
|
if *discordCID == "" {
|
||||||
log.Fatalln("missing discord cid")
|
log.Fatalln("missing discord cid")
|
||||||
}
|
}
|
||||||
|
if *mode == "" {
|
||||||
|
log.Fatalln("missing mode set")
|
||||||
|
}
|
||||||
err := syscall.Setpriority(syscall.PRIO_PROCESS, os.Getpid(), -5)
|
err := syscall.Setpriority(syscall.PRIO_PROCESS, os.Getpid(), -5)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Unable to set priority. ", err)
|
log.Println("Unable to set priority. ", err)
|
||||||
@ -82,6 +85,7 @@ func main() {
|
|||||||
|
|
||||||
log.Println("Discord Bot Connected")
|
log.Println("Discord Bot Connected")
|
||||||
log.Printf("Discord bot looking for command !%v", *discordCommand)
|
log.Printf("Discord bot looking for command !%v", *discordCommand)
|
||||||
|
// Mumble setup
|
||||||
config := gumble.NewConfig()
|
config := gumble.NewConfig()
|
||||||
config.Username = *mumbleUsername
|
config.Username = *mumbleUsername
|
||||||
config.Password = *mumblePassword
|
config.Password = *mumblePassword
|
||||||
@ -92,7 +96,7 @@ func main() {
|
|||||||
MumbleAddr: *mumbleAddr + ":" + strconv.Itoa(*mumblePort),
|
MumbleAddr: *mumbleAddr + ":" + strconv.Itoa(*mumblePort),
|
||||||
MumbleInsecure: *mumbleInsecure,
|
MumbleInsecure: *mumbleInsecure,
|
||||||
MumbleChannel: *mumbleChannel,
|
MumbleChannel: *mumbleChannel,
|
||||||
Auto: *autoMode,
|
Mode: -1,
|
||||||
Command: *discordCommand,
|
Command: *discordCommand,
|
||||||
GID: *discordGID,
|
GID: *discordGID,
|
||||||
CID: *discordCID,
|
CID: *discordCID,
|
||||||
@ -104,11 +108,25 @@ func main() {
|
|||||||
DiscordUserCount: 0,
|
DiscordUserCount: 0,
|
||||||
DiscordUsers: make(map[string]bool),
|
DiscordUsers: make(map[string]bool),
|
||||||
}
|
}
|
||||||
go discordStatusUpdate(discord, *mumbleAddr, strconv.Itoa(*mumblePort))
|
switch *mode {
|
||||||
if *autoMode {
|
case "auto":
|
||||||
|
log.Println("bridge starting in automatic mode")
|
||||||
Bridge.AutoChan = make(chan bool)
|
Bridge.AutoChan = make(chan bool)
|
||||||
|
BridgeConf.Mode = BridgeModeAuto
|
||||||
go AutoBridge(discord)
|
go AutoBridge(discord)
|
||||||
|
case "manual":
|
||||||
|
log.Println("bridge starting in manual mode")
|
||||||
|
BridgeConf.Mode = BridgeModeManual
|
||||||
|
case "constant":
|
||||||
|
log.Println("bridge starting in constant mode")
|
||||||
|
BridgeConf.Mode = BridgeModeConstant
|
||||||
|
go startBridge(discord, *discordGID, *discordCID, config, BridgeConf.MumbleAddr, *mumbleInsecure, make(chan bool))
|
||||||
|
default:
|
||||||
|
discord.Close()
|
||||||
|
log.Fatalln("invalid bridge mode set")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
go discordStatusUpdate(discord, *mumbleAddr, strconv.Itoa(*mumblePort))
|
||||||
sc := make(chan os.Signal, 1)
|
sc := make(chan os.Signal, 1)
|
||||||
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
|
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
|
||||||
<-sc
|
<-sc
|
||||||
|
Loading…
Reference in New Issue
Block a user