Commit 05698b7c authored by Markus Seidl's avatar Markus Seidl

Made mplayer command line options accessible in config.json MPlayerCommandLineArgs.

parent 40388caa
package bot
import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"log"
"os"
"rgifbot/config"
"strings"
"time"
......@@ -18,19 +18,11 @@ type Message struct {
File *os.File
}
type TelegramConfig struct {
TelegramToken string
KnownIds map[int]bool
Password string
}
var Config TelegramConfig
const ConfigFile = "./config.json"
var Config config.BotConfig
func CCTelegramLoop(handler func(message Message) error) {
Config = loadConfig()
Config = config.LoadConfig()
if Config.KnownIds == nil {
Config.KnownIds = make(map[int]bool) // necessary?!
}
......@@ -101,7 +93,7 @@ func CCTelegramLoop(handler func(message Message) error) {
Config.KnownIds[m.Sender.ID] = true
_, _ = b.Send(m.Sender, "Welcome back! 😍")
storeConfig(Config)
config.StoreConfig(Config)
})
b.Start()
......@@ -134,23 +126,3 @@ func isAllowed(b *tb.Bot, m *tb.Message) bool {
return false
}
func loadConfig() TelegramConfig {
configFileData, _ := ioutil.ReadFile(ConfigFile)
var config TelegramConfig
err := json.Unmarshal(configFileData, &config)
if err != nil {
storeConfig(TelegramConfig{"token", make(map[int]bool), ""})
log.Fatalf("Unable to load configfile <%s>. Writing empty file.\n", err.Error())
}
return config
}
func storeConfig(config TelegramConfig) {
m, _ := json.Marshal(config)
err := ioutil.WriteFile(ConfigFile, m, 0666)
if err != nil {
log.Printf("Unable to save configfile <%s>\n", err.Error())
}
}
package config
import (
"encoding/json"
"io/ioutil"
"log"
)
const ConfigFile = "./config.json"
type BotConfig struct {
TelegramToken string
KnownIds map[int]bool
Password string
MPlayerCommandLineArgs []string
}
func LoadConfig() BotConfig {
configFileData, _ := ioutil.ReadFile(ConfigFile)
var config BotConfig
err := json.Unmarshal(configFileData, &config)
if err != nil {
StoreConfig(BotConfig{
TelegramToken: "token",
KnownIds: make(map[int]bool),
MPlayerCommandLineArgs: make([]string, 0),
})
log.Fatalf("Unable to load configfile <%s>. Writing empty file.\n", err.Error())
}
return config
}
func StoreConfig(config BotConfig) {
m, _ := json.Marshal(config)
err := ioutil.WriteFile(ConfigFile, m, 0666)
if err != nil {
log.Printf("Unable to save configfile <%s>\n", err.Error())
}
}
......@@ -3,6 +3,7 @@ package display
import (
"log"
"os/exec"
"rgifbot/config"
"rgifbot/mplayer"
"rgifbot/simpledb"
"runtime"
......@@ -12,10 +13,12 @@ import (
func DisplayLoop(db *simpledb.Database) {
var addArgs []string
addArgs = append(addArgs, "-nosound")
if runtime.GOOS == "linux" {
addArgs = append(addArgs, "-vo", "directfb", "-zoom")
conf := config.LoadConfig()
if conf.MPlayerCommandLineArgs != nil && len(conf.MPlayerCommandLineArgs) > 0 {
addArgs = append(addArgs, conf.MPlayerCommandLineArgs...)
}
mplayer.StartSlave(func(err error) {
log.Printf("Error while communicating with mplayer <%v>", err)
}, addArgs...)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment