readme update

This commit is contained in:
stryan 2021-01-05 12:16:51 -05:00
parent b7b1065abb
commit d75fff08f2
4 changed files with 56 additions and 17 deletions

View File

@ -13,9 +13,9 @@ The binary will also attempt to load .env file located in the working directory.
```bash
Usage of mumble-discord-bridge:
-discord-cid string
DISCORD_CID, discord cid
DISCORD_CID, discord channel ID
-discord-gid string
DISCORD_GID, discord gid
DISCORD_GID, discord guild ID
-discord-token string
DISCORD_TOKEN, discord bot token
-discord-command string
@ -32,13 +32,24 @@ Usage of mumble-discord-bridge:
MUMBLE_INSECURE, allow connection to insecure (invalid TLS cert) mumble server
-mumble-channel string
MUMBLE_CHANNEL, pick what channel the bridge joins in Mumble. Must be a direct child of Root.
-auto-mode bool
AUTO_MODE, enables the bridge to automatically start if there's users in both Discord and Mumble
-mode string
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
Commands the bridge to join the Discord channel the user is in and the Mumble server
!DISCORD_COMMAND unlink
@ -46,7 +57,7 @@ The bridge can be manually controlled in Discord with the following commands:
!DISCORD_COMMAND refresh
Commands the bridge to unlink, then link again.
!DISCORD_COMMAND auto
Toggle AUTO_MODE
Toggle between manual and auto mode
```
## Setup

View File

@ -10,12 +10,20 @@ import (
"layeh.com/gumble/gumble"
)
type BridgeMode int
const (
BridgeModeAuto BridgeMode = iota
BridgeModeManual
BridgeModeConstant
)
type BridgeConfig struct {
Config *gumble.Config
MumbleAddr string
MumbleInsecure bool
MumbleChannel string
Auto bool
Mode BridgeMode
Command string
GID string
CID string

View File

@ -15,9 +15,11 @@ func ready(s *discordgo.Session, event *discordgo.Ready) {
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
if BridgeConf.Mode == BridgeModeConstant {
return
}
// 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 {
return
}
@ -111,13 +113,13 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
}
if strings.HasPrefix(m.Content, prefix+" auto") {
if BridgeConf.Auto == false {
BridgeConf.Auto = true
if BridgeConf.Mode != BridgeModeAuto {
BridgeConf.Mode = BridgeModeAuto
Bridge.AutoChan = make(chan bool)
go AutoBridge(s)
} else {
Bridge.AutoChan <- true
BridgeConf.Auto = false
BridgeConf.Mode = BridgeModeManual
}
}
}

26
main.go
View File

@ -31,7 +31,7 @@ func main() {
discordGID := flag.String("discord-gid", lookupEnvOrString("DISCORD_GID", ""), "DISCORD_GID, discord gid")
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")
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()
log.Printf("app.config %v\n", getConfig(flag.CommandLine))
@ -51,6 +51,9 @@ func main() {
if *discordCID == "" {
log.Fatalln("missing discord cid")
}
if *mode == "" {
log.Fatalln("missing mode set")
}
err := syscall.Setpriority(syscall.PRIO_PROCESS, os.Getpid(), -5)
if err != nil {
log.Println("Unable to set priority. ", err)
@ -82,6 +85,7 @@ func main() {
log.Println("Discord Bot Connected")
log.Printf("Discord bot looking for command !%v", *discordCommand)
// Mumble setup
config := gumble.NewConfig()
config.Username = *mumbleUsername
config.Password = *mumblePassword
@ -92,7 +96,7 @@ func main() {
MumbleAddr: *mumbleAddr + ":" + strconv.Itoa(*mumblePort),
MumbleInsecure: *mumbleInsecure,
MumbleChannel: *mumbleChannel,
Auto: *autoMode,
Mode: -1,
Command: *discordCommand,
GID: *discordGID,
CID: *discordCID,
@ -104,11 +108,25 @@ func main() {
DiscordUserCount: 0,
DiscordUsers: make(map[string]bool),
}
go discordStatusUpdate(discord, *mumbleAddr, strconv.Itoa(*mumblePort))
if *autoMode {
switch *mode {
case "auto":
log.Println("bridge starting in automatic mode")
Bridge.AutoChan = make(chan bool)
BridgeConf.Mode = BridgeModeAuto
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)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
<-sc