Start of the run command and the bridge type

This commit is contained in:
Gary Kramlich
2021-11-20 04:59:52 -06:00
parent 8086ad1708
commit 4be28617e0
3 changed files with 90 additions and 0 deletions

53
bridge/bridge.go Normal file
View File

@@ -0,0 +1,53 @@
package bridge
import (
log "maunium.net/go/maulogger/v2"
"maunium.net/go/mautrix/appservice"
"gitlab.com/beeper/discord/config"
"gitlab.com/beeper/discord/version"
)
type Bridge struct {
config *config.Config
log log.Logger
as *appservice.AppService
eventProcessor *appservice.EventProcessor
bot *appservice.IntentAPI
}
func New(cfg *config.Config) (*Bridge, error) {
// Create the logger.
logger, err := cfg.CreateLogger()
if err != nil {
return nil, err
}
logger.Infoln("Initializing version", version.String)
// Create the app service.
appservice, err := cfg.CreateAppService()
if err != nil {
return nil, err
}
appservice.Log = log.Sub("matrix")
// Create the bridge.
bridge := &Bridge{
config: cfg,
log: logger,
as: appservice,
}
return bridge, nil
}
func (b *Bridge) Start() {
b.log.Infoln("bridge started")
}
func (b *Bridge) Stop() {
b.log.Infoln("bridge stopped")
}

View File

@@ -10,6 +10,7 @@ import (
"gitlab.com/beeper/discord/consts"
"gitlab.com/beeper/discord/globals"
"gitlab.com/beeper/discord/registration"
"gitlab.com/beeper/discord/run"
"gitlab.com/beeper/discord/version"
)
@@ -18,6 +19,7 @@ var cli struct {
GenerateConfig config.Cmd `kong:"cmd,help='Generate the default configuration and exit.'"`
GenerateRegistration registration.Cmd `kong:"cmd,help='Generate the registration file for synapse and exit.'"`
Run run.Cmd `kong:"cmd,help='Run the bridge.',default='1'"`
Version version.Cmd `kong:"cmd,help='Display the version and exit.'"`
}

35
run/cmd.go Normal file
View File

@@ -0,0 +1,35 @@
package run
import (
"os"
"os/signal"
"syscall"
"gitlab.com/beeper/discord/bridge"
"gitlab.com/beeper/discord/config"
"gitlab.com/beeper/discord/globals"
)
type Cmd struct{}
func (c *Cmd) Run(g *globals.Globals) error {
cfg, err := config.FromFile(g.Config)
if err != nil {
return err
}
bridge, err := bridge.New(cfg)
if err != nil {
return err
}
bridge.Start()
ch := make(chan os.Signal)
signal.Notify(ch, os.Interrupt, syscall.SIGTERM)
<-ch
bridge.Stop()
return nil
}