aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorXe Iaso <me@xeiaso.net>2023-06-16 11:36:13 -0400
committerXe Iaso <me@xeiaso.net>2023-06-16 11:36:13 -0400
commitf3d2b8386a188041b823d02b65dad347a324a089 (patch)
tree33f54cee9e8da6c48715f310c1279cc215c2d781 /cmd
parent636850d4e9b025d4f799ca5fd2aa7a936c1971f0 (diff)
downloadx-f3d2b8386a188041b823d02b65dad347a324a089.tar.xz
x-f3d2b8386a188041b823d02b65dad347a324a089.zip
fix the bot
Signed-off-by: Xe Iaso <me@xeiaso.net>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/marabot/.gitignore3
-rw-r--r--cmd/marabot/main.go68
-rw-r--r--cmd/marabot/schema.sql10
3 files changed, 80 insertions, 1 deletions
diff --git a/cmd/marabot/.gitignore b/cmd/marabot/.gitignore
new file mode 100644
index 0000000..81e8b4d
--- /dev/null
+++ b/cmd/marabot/.gitignore
@@ -0,0 +1,3 @@
+*.db
+*.db-shm
+*.db-wal
diff --git a/cmd/marabot/main.go b/cmd/marabot/main.go
index 12c0b1a..2d94bc5 100644
--- a/cmd/marabot/main.go
+++ b/cmd/marabot/main.go
@@ -2,12 +2,16 @@ package main
import (
"context"
+ "database/sql"
+ _ "embed"
"flag"
"os"
"os/signal"
"syscall"
"time"
+ "github.com/bwmarrin/discordgo"
+ _ "modernc.org/sqlite"
"within.website/ln"
"within.website/ln/opname"
"within.website/x/internal"
@@ -15,9 +19,19 @@ import (
)
var (
+ dbFile = flag.String("db-file", "marabot.db", "Path to the database file")
+ discordToken = flag.String("discord-token", "", "Discord bot token")
revoltToken = flag.String("revolt-token", "", "Revolt bot token")
revoltAPIServer = flag.String("revolt-api-server", "https://api.revolt.chat", "API server for Revolt")
revoltWebsocketServer = flag.String("revolt-ws-server", "wss://ws.revolt.chat", "Websocket server for Revolt")
+
+ //go:embed schema.sql
+ dbSchema string
+)
+
+const (
+ furryholeDiscord = "192289762302754817"
+ furryholeRevolt = "01H2VRKJFPYPEAE438B6JRFSCP"
)
func main() {
@@ -37,6 +51,58 @@ func main() {
client.Connect(ctx, mr)
+ dg, err := discordgo.New("Bot " + *discordToken)
+ if err != nil {
+ ln.FatalErr(ctx, err, ln.Action("creating discord client"))
+ }
+
+ if err := dg.Open(); err != nil {
+ ln.FatalErr(ctx, err, ln.Action("opening discord client"))
+ }
+ defer dg.Close()
+
+ db, err := sql.Open("sqlite", *dbFile)
+ if err != nil {
+ ln.FatalErr(ctx, err, ln.Action("opening sqlite database"))
+ }
+ defer db.Close()
+
+ if _, err := db.ExecContext(ctx, dbSchema); err != nil {
+ ln.FatalErr(ctx, err, ln.Action("running database schema"))
+ }
+
+ // roles, err := dg.GuildRoles(furryholeDiscord)
+ // if err != nil {
+ // ln.FatalErr(ctx, err, ln.Action("getting guild roles"))
+ // }
+
+ // for _, role := range roles {
+ // if role.Name == "@everyone" {
+ // continue
+ // }
+ // ln.Log(ctx, ln.Info("role"), ln.F{"name": role.Name, "id": role.ID, "color": fmt.Sprintf("#%06x", role.Color)})
+
+ // id, err := client.ServerCreateRole(ctx, furryholeRevolt, role.Name)
+ // if err != nil {
+ // ln.Error(ctx, err, ln.Action("creating role"))
+ // continue
+ // }
+
+ // if err := client.ServerEditRole(ctx, furryholeRevolt, id, &revolt.EditRole{
+ // Color: fmt.Sprintf("#%06x", role.Color),
+ // Hoist: role.Hoist,
+ // Rank: 250 - role.Position,
+ // }); err != nil {
+ // ln.Error(ctx, err, ln.Action("editing role"))
+ // continue
+ // }
+
+ // if _, err := db.ExecContext(ctx, "INSERT INTO roles (discord_server, discord_id, revolt_server, revolt_id, name, color, hoist) VALUES (?, ?, ?, ?, ?, ?, ?)", furryholeDiscord, role.ID, furryholeRevolt, id, role.Name, fmt.Sprintf("#%06x", role.Color), role.Hoist); err != nil {
+ // ln.Error(ctx, err, ln.Action("inserting role"))
+ // continue
+ // }
+ // }
+
// Wait for close.
sc := make(chan os.Signal, 1)
@@ -74,7 +140,7 @@ func (m *MaraRevolt) MessageCreate(ctx context.Context, msg *revolt.Message) err
}
sendMsg.SetContent("🏓 Pong!")
- if _, err := msg.Reply(true, sendMsg); err != nil {
+ if _, err := m.cli.MessageReply(ctx, msg.ChannelId, msg.ID, true, sendMsg); err != nil {
return err
}
}
diff --git a/cmd/marabot/schema.sql b/cmd/marabot/schema.sql
new file mode 100644
index 0000000..7d4046f
--- /dev/null
+++ b/cmd/marabot/schema.sql
@@ -0,0 +1,10 @@
+CREATE TABLE IF NOT EXISTS roles (
+ id SERIAL PRIMARY KEY,
+ discord_server TEXT NOT NULL,
+ discord_id TEXT NOT NULL,
+ revolt_server TEXT NOT NULL,
+ revolt_id TEXT NOT NULL,
+ name TEXT NOT NULL,
+ color TEXT NOT NULL,
+ hoist BOOLEAN NOT NULL
+); \ No newline at end of file