Noah Petherbridge
fd82a463f3
* Deadlock detection: the chatbot handlers will spin off a background goroutine to ping DMs at itself and test for responsiveness. If the echoes don't return for a minute, issue a /api/shutdown command to the HTTP server to force a reboot. * New admin API endpoint: /api/shutdown, equivalent to the operator '/shutdown' command sent in chat. Requires your AdminAPIKey to call it. Used by the chatbot as part of deadlock detection. * Adjust some uses of mutexes to hopefully mitigate deadlocks a bit. * Do Not Disturb: if users opt to "Ignore unsolicited DMs" they will set a DND status on the server which will grey-out their DM icon for other chatters. * Bring back an option for ChatServer to notify you when somebody begins watching your camera (on by default). * Automatically focus the message entry box when changing channels. * Lower webcam resolution hints to 480p to test performance implications.
87 lines
2.2 KiB
Go
87 lines
2.2 KiB
Go
package commands
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"time"
|
|
|
|
"git.kirsle.net/apps/barertc/client"
|
|
"git.kirsle.net/apps/barertc/client/config"
|
|
"git.kirsle.net/apps/barertc/pkg/jwt"
|
|
"git.kirsle.net/apps/barertc/pkg/log"
|
|
xjwt "github.com/golang-jwt/jwt/v4"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
// Run implements `BareBot run`
|
|
var Run *cli.Command
|
|
|
|
func init() {
|
|
Run = &cli.Command{
|
|
Name: "run",
|
|
Usage: "run the BareBot client program and connect to your chat room",
|
|
ArgsUsage: "<chatbot directory>",
|
|
Flags: []cli.Flag{},
|
|
Action: func(c *cli.Context) error {
|
|
// Chatbot directory
|
|
var botdir = c.Args().First()
|
|
if botdir == "" {
|
|
botdir = "."
|
|
}
|
|
|
|
// Check for the chatbot.toml file.
|
|
if _, err := os.Stat(filepath.Join(botdir, "chatbot.toml")); os.IsNotExist(err) {
|
|
return cli.Exit(fmt.Errorf(
|
|
"Did not find chatbot.toml in your chatbot directory (%s): did you run `BareBot init`?",
|
|
botdir,
|
|
), 1)
|
|
}
|
|
|
|
// Enter the directory.
|
|
if err := os.Chdir(botdir); err != nil {
|
|
log.Error("Couldn't enter directory %s: %s", botdir, err)
|
|
return cli.Exit("Exited", 1)
|
|
}
|
|
|
|
// Load the settings.
|
|
if err := config.LoadSettings(); err != nil {
|
|
return cli.Exit(fmt.Sprintf(
|
|
"Couldn't load chatbot.toml: %s", err,
|
|
), 1)
|
|
}
|
|
|
|
log.Info("Initializing BareBot")
|
|
|
|
// Get the JWT auth token.
|
|
log.Info("Authenticating with BareRTC (getting JWT token)")
|
|
client, err := client.NewClient(config.Current.BareRTC.URL, jwt.Claims{
|
|
IsAdmin: config.Current.Profile.IsAdmin,
|
|
Avatar: config.Current.Profile.AvatarURL,
|
|
ProfileURL: config.Current.Profile.ProfileURL,
|
|
Nick: config.Current.Profile.Nickname,
|
|
Emoji: config.Current.Profile.Emoji,
|
|
Gender: config.Current.Profile.Gender,
|
|
RegisteredClaims: xjwt.RegisteredClaims{
|
|
Subject: config.Current.Profile.Username,
|
|
},
|
|
})
|
|
if err != nil {
|
|
return cli.Exit(err, 1)
|
|
}
|
|
|
|
// Register handler funcs for the chatbot.
|
|
client.SetupChatbot()
|
|
|
|
// Run!
|
|
log.Info("Connecting to ChatServer")
|
|
err = client.Run()
|
|
if err != nil {
|
|
log.Error("Error: %s (and sleeping 5 seconds before exit)", err)
|
|
time.Sleep(5 * time.Second)
|
|
}
|
|
return cli.Exit(client.Run(), 1)
|
|
},
|
|
}
|
|
}
|