bot connects to server

This commit is contained in:
lyx0 2024-01-09 05:09:01 +01:00
parent a9b9c12fca
commit fcef2c479f
7 changed files with 56 additions and 15 deletions

1
.gitignore vendored
View file

@ -23,3 +23,4 @@ bin/
go.work
.env
nourybot-matrix

23
Dockerfile Normal file
View file

@ -0,0 +1,23 @@
# Start from golang base image
FROM golang:alpine3.19
RUN apk add --no-cache git ca-certificates build-base su-exec olm-dev sqlite
# Setup folders
RUN mkdir /app
WORKDIR /app
# Copy the source from the current directory to the working Directory inside the container
COPY . .
# Download all the dependencies
RUN go get -d -v ./...
RUN go get -u maunium.net/go/mautrix
# Build the Go app
RUN go build .
# Run the executable
CMD [ "./nourybot-matrix" ]

View file

@ -0,0 +1,3 @@
rebuild:
docker compose down
docker-compose up --force-recreate --no-deps --build nourybot-matrix

8
docker-compose.yml Normal file
View file

@ -0,0 +1,8 @@
version: "3.7"
services:
nourybot-matrix:
build:
context: .
dockerfile: Dockerfile
env_file: .env

3
go.mod
View file

@ -4,7 +4,8 @@ go 1.20
require (
github.com/chzyer/readline v1.5.1
github.com/mattn/go-sqlite3 v1.14.18
github.com/joho/godotenv v1.5.1
github.com/mattn/go-sqlite3 v1.14.19
github.com/rs/zerolog v1.31.0
maunium.net/go/mautrix v0.16.3-0.20231215142331-753cdb2e1cb0
)

6
go.sum
View file

@ -8,13 +8,15 @@ github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-sqlite3 v1.14.18 h1:JL0eqdCOq6DJVNPSvArO/bIV9/P7fbGrV00LZHc+5aI=
github.com/mattn/go-sqlite3 v1.14.18/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/mattn/go-sqlite3 v1.14.19 h1:fhGleo2h1p8tVChob4I9HpmVFIAkKGpiukdrgQbWfGI=
github.com/mattn/go-sqlite3 v1.14.19/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=

27
main.go
View file

@ -18,6 +18,7 @@ import (
"time"
"github.com/chzyer/readline"
"github.com/joho/godotenv"
_ "github.com/mattn/go-sqlite3"
"github.com/rs/zerolog"
@ -27,21 +28,23 @@ import (
"maunium.net/go/mautrix/id"
)
var homeserver = flag.String("homeserver", "", "Matrix homeserver")
var username = flag.String("username", "", "Matrix username localpart")
var password = flag.String("password", "", "Matrix password")
var database = flag.String("database", "mautrix-example.db", "SQLite database path")
var debug = flag.Bool("debug", false, "Enable debug logs")
//var database = flag.String("database", "test.db", "SQLite database path")
func main() {
flag.Parse()
if *username == "" || *password == "" || *homeserver == "" {
_, _ = fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
flag.PrintDefaults()
os.Exit(1)
err := godotenv.Load()
if err != nil {
panic(err)
}
client, err := mautrix.NewClient(*homeserver, "", "")
homeserver := os.Getenv("MATRIX_HOMESERVER")
username := os.Getenv("MATRIX_USERNAME")
password := os.Getenv("MATRIX_PASSWORD")
database := os.Getenv("SQLITE_DATABASE")
client, err := mautrix.NewClient(homeserver, "", "")
if err != nil {
panic(err)
}
@ -91,7 +94,7 @@ func main() {
}
})
cryptoHelper, err := cryptohelper.NewCryptoHelper(client, []byte("meow"), *database)
cryptoHelper, err := cryptohelper.NewCryptoHelper(client, []byte("meow"), database)
if err != nil {
panic(err)
}
@ -103,8 +106,8 @@ func main() {
// You don't need to set a device ID in LoginAs because the crypto helper will set it for you if necessary.
cryptoHelper.LoginAs = &mautrix.ReqLogin{
Type: mautrix.AuthTypePassword,
Identifier: mautrix.UserIdentifier{Type: mautrix.IdentifierTypeUser, User: *username},
Password: *password,
Identifier: mautrix.UserIdentifier{Type: mautrix.IdentifierTypeUser, User: username},
Password: password,
}
// If you want to use multiple clients with the same DB, you should set a distinct database account ID for each one.
//cryptoHelper.DBAccountID = ""