fixes for deployment
This commit is contained in:
parent
e432b6c4d2
commit
4c8532fc7d
|
@ -3,7 +3,13 @@
|
|||
## Usage
|
||||
|
||||
```
|
||||
INSECURE_TLS=no BASE_URL=https://matrix.server.com LISTEN_ADDR=0.0.0.0:8888 ACCESS_TOKEN=hackme go run .
|
||||
INSECURE_TLS=no \
|
||||
BASE_URL=https://matrix.server.com \
|
||||
LISTEN_ADDR=0.0.0.0:8888 \
|
||||
ACCESS_TOKEN=hackme \
|
||||
VERBS_FILE=verbs.csv \
|
||||
MATRIX_USER=@esbot:server.com \
|
||||
go run .
|
||||
```
|
||||
|
||||
## Licence
|
||||
|
|
|
@ -35,12 +35,12 @@ func (h *handler) handleTransactions(w http.ResponseWriter, r *http.Request) {
|
|||
w.Write([]byte("{}"))
|
||||
}
|
||||
|
||||
func ListenAndServe(listenAddr, baseURL, accessToken string, insecureTLS bool, logger zerolog.Logger) error {
|
||||
func ListenAndServe(listenAddr, baseURL, user, accessToken string, insecureTLS bool, logger zerolog.Logger) error {
|
||||
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: insecureTLS}
|
||||
|
||||
h := handler{
|
||||
logger: logger,
|
||||
ep: matrix.NewProcessor(baseURL, accessToken, logger),
|
||||
ep: matrix.NewProcessor(baseURL, user, accessToken, logger),
|
||||
}
|
||||
|
||||
mux := http.NewServeMux()
|
||||
|
|
|
@ -46,11 +46,11 @@ func GetVerb(q string) *Verb {
|
|||
return verbs[q]
|
||||
}
|
||||
|
||||
func Load() (int, error) {
|
||||
func Load(verbsFile string) (int, error) {
|
||||
var err error
|
||||
f, err := os.Open("./internal/lang/resources/jehle_verb_database.csv")
|
||||
f, err := os.Open(verbsFile)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("could not open verb database: %v", err)
|
||||
return 0, fmt.Errorf("could not open verbs file: %v", err)
|
||||
}
|
||||
|
||||
csv := csv.NewReader(f)
|
||||
|
|
|
@ -20,16 +20,16 @@ type EventProcessor interface {
|
|||
}
|
||||
|
||||
type processor struct {
|
||||
baseURL string
|
||||
accessToken string
|
||||
httpclient *http.Client
|
||||
processed map[string]bool
|
||||
logger zerolog.Logger
|
||||
baseURL, user, accessToken string
|
||||
httpclient *http.Client
|
||||
processed map[string]bool
|
||||
logger zerolog.Logger
|
||||
}
|
||||
|
||||
func NewProcessor(baseURL, accessToken string, logger zerolog.Logger) EventProcessor {
|
||||
func NewProcessor(baseURL, user, accessToken string, logger zerolog.Logger) EventProcessor {
|
||||
return &processor{
|
||||
baseURL: baseURL,
|
||||
user: user,
|
||||
accessToken: accessToken,
|
||||
httpclient: &http.Client{},
|
||||
processed: make(map[string]bool),
|
||||
|
@ -45,7 +45,7 @@ func (p *processor) ProcessEvents(events []*RawEvent) error {
|
|||
}
|
||||
|
||||
if e.StateKey != "" {
|
||||
if e.Content.Membership == "invite" {
|
||||
if e.Type == "m.room.member" && e.Content.Membership == "invite" && e.StateKey == p.user {
|
||||
if err := p.acceptInvite(e); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
14
main.go
14
main.go
|
@ -27,15 +27,25 @@ func main() {
|
|||
logger.Fatal().Msg("missing BASE_URL")
|
||||
}
|
||||
|
||||
user := os.Getenv("MATRIX_USER")
|
||||
if user == "" {
|
||||
logger.Fatal().Msg("missing MATRIX_USER")
|
||||
}
|
||||
|
||||
verbsFile := os.Getenv("VERBS_FILE")
|
||||
if verbsFile == "" {
|
||||
logger.Fatal().Msg("missing VERBS_FILE")
|
||||
}
|
||||
|
||||
insecureTLS := os.Getenv("INSECURE_TLS") == "yes"
|
||||
|
||||
if n, err := lang.Load(); err == nil {
|
||||
if n, err := lang.Load(verbsFile); err == nil {
|
||||
logger.Info().Msgf("Loaded %d verbs", n)
|
||||
} else {
|
||||
logger.Fatal().Msgf("could not initialize languages: %v", err)
|
||||
}
|
||||
|
||||
if err := http.ListenAndServe(listenAddr, baseURL, accessToken, insecureTLS, logger); err != nil {
|
||||
if err := http.ListenAndServe(listenAddr, baseURL, user, accessToken, insecureTLS, logger); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue