58 lines
1 KiB
Go
58 lines
1 KiB
Go
|
package cli
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"io/ioutil"
|
||
|
"log"
|
||
|
|
||
|
"forge.lightcrystal.systems/lightcrystal/underbbs/adapter"
|
||
|
"forge.lightcrystal.systems/lightcrystal/underbbs/models"
|
||
|
)
|
||
|
|
||
|
func Process(args ...string) error {
|
||
|
// allocate storage for the settings array
|
||
|
var settings []models.Settings
|
||
|
var s models.Settings
|
||
|
|
||
|
// get adapter from first arg
|
||
|
adapterName := args[0]
|
||
|
args = args[1:]
|
||
|
|
||
|
// get config from config fle based on adapter
|
||
|
content, err := ioutil.ReadFile("./config.json")
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
err = json.Unmarshal(content, settings)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
for _, x := range settings {
|
||
|
if x.Nickname == adapterName {
|
||
|
s = x
|
||
|
break
|
||
|
}
|
||
|
}
|
||
|
// instantiate adapter with config
|
||
|
var a adapter.Adapter
|
||
|
switch s.Protocol {
|
||
|
case "nostr":
|
||
|
a = &adapter.NostrAdapter{}
|
||
|
case "mastodon":
|
||
|
a = &adapter.MastoAdapter{}
|
||
|
case "misskey":
|
||
|
a = &adapter.MisskeyAdapter{}
|
||
|
default:
|
||
|
break
|
||
|
}
|
||
|
a.Init(s, nil)
|
||
|
// process remaining args and execute
|
||
|
|
||
|
switch args[0] {
|
||
|
default:
|
||
|
log.Print(args)
|
||
|
}
|
||
|
return nil
|
||
|
}
|