Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e8b76d07e2 | ||
|
|
63ef1f206b | ||
|
|
373e9ff3c3 | ||
|
|
d3fff1519b | ||
|
|
2b6acc51fb | ||
|
|
fade4467d6 | ||
|
|
c8800c010e |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@ todo-server-yaml
|
|||||||
cmd/cmd
|
cmd/cmd
|
||||||
cmd/cli
|
cmd/cli
|
||||||
cmd/pttodo/pttodo
|
cmd/pttodo/pttodo
|
||||||
|
/truckstop
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
"RefreshURI": "https://api.imgur.com/oauth2/token",
|
"RefreshURI": "https://api.imgur.com/oauth2/token",
|
||||||
"RefreshFormat": "refresh_token=%s\u0026client_id=%s\u0026client_secret=%s\u0026grant_type=refresh_token",
|
"RefreshFormat": "refresh_token=%s\u0026client_id=%s\u0026client_secret=%s\u0026grant_type=refresh_token",
|
||||||
"RefreshMethod": "POST",
|
"RefreshMethod": "POST",
|
||||||
"UploadURI": "https://api.imgur.com/3/image",
|
"UploadURI": "https://api.imgur.com/3/image?name=something.jpeg",
|
||||||
"UploadMethod": "POST"
|
"UploadMethod": "POST"
|
||||||
},
|
},
|
||||||
"Maps": {
|
"Maps": {
|
||||||
@@ -74,7 +74,7 @@
|
|||||||
"Room": "!WbawbZxHqnxxfhvcSj:synapse.home.blapointe.com"
|
"Room": "!WbawbZxHqnxxfhvcSj:synapse.home.blapointe.com"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Once": false,
|
"Once": true,
|
||||||
"Brokers": {
|
"Brokers": {
|
||||||
"NTG": {
|
"NTG": {
|
||||||
"Mock": true,
|
"Mock": true,
|
||||||
|
|||||||
4
main.go
4
main.go
@@ -259,14 +259,17 @@ func once() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
log.Printf("once: all jobs: %+v", alljobs)
|
||||||
newjobs, err := dropStaleJobs(alljobs)
|
newjobs, err := dropStaleJobs(alljobs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
log.Printf("once: new jobs: %+v", newjobs)
|
||||||
jobs, err := dropBanlistJobs(newjobs)
|
jobs, err := dropBanlistJobs(newjobs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
log.Printf("once: sending jobs: %+v", jobs)
|
||||||
for i := range jobs {
|
for i := range jobs {
|
||||||
if err := sendJob(jobs[i]); err != nil {
|
if err := sendJob(jobs[i]); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -318,6 +321,7 @@ func dropBanlistJobs(jobs []broker.Job) ([]broker.Job, error) {
|
|||||||
func sendJob(job broker.Job) error {
|
func sendJob(job broker.Job) error {
|
||||||
sender := message.NewMatrix()
|
sender := message.NewMatrix()
|
||||||
payload := job.FormatMultilineText()
|
payload := job.FormatMultilineText()
|
||||||
|
log.Printf("once: send job %s if nonzero: %s", job.String(), payload)
|
||||||
if len(payload) == 0 {
|
if len(payload) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"local/truckstop/config"
|
"local/truckstop/config"
|
||||||
|
"log"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -30,9 +32,17 @@ func refreshToken() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func uploadImage(b []byte) (string, error) {
|
func uploadImage(b []byte) (string, error) {
|
||||||
|
images := config.Get().Images
|
||||||
buff := bytes.NewBuffer(nil)
|
buff := bytes.NewBuffer(nil)
|
||||||
writer := multipart.NewWriter(buff)
|
writer := multipart.NewWriter(buff)
|
||||||
part, err := writer.CreateFormFile("image", "name")
|
name := "name"
|
||||||
|
if u, err := url.Parse(images.UploadURI); err != nil {
|
||||||
|
} else if s, ok := u.Query()["name"]; !ok {
|
||||||
|
} else {
|
||||||
|
name = s[0]
|
||||||
|
log.Printf("found name in upload uri: %s", name)
|
||||||
|
}
|
||||||
|
part, err := writer.CreateFormFile("image", name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@@ -43,7 +53,6 @@ func uploadImage(b []byte) (string, error) {
|
|||||||
}
|
}
|
||||||
writer.Close()
|
writer.Close()
|
||||||
|
|
||||||
images := config.Get().Images
|
|
||||||
request, err := http.NewRequest(
|
request, err := http.NewRequest(
|
||||||
images.UploadMethod,
|
images.UploadMethod,
|
||||||
images.UploadURI,
|
images.UploadURI,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package message
|
package message
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"local/truckstop/config"
|
"local/truckstop/config"
|
||||||
@@ -129,14 +130,15 @@ func (m Matrix) SendImage(uri string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
publicURI, err := UploadImage(b)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
c, err := m.getclient()
|
c, err := m.getclient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
mediaUpload, err := c.UploadToContentRepo(bytes.NewReader(b), "image/jpeg", int64(len(b)))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
publicURI := mediaUpload.ContentURI
|
||||||
resp, err := c.SendImage(m.room, "img", publicURI)
|
resp, err := c.SendImage(m.room, "img", publicURI)
|
||||||
log.Printf("sent image %s => %s: %+v", uri, publicURI, resp)
|
log.Printf("sent image %s => %s: %+v", uri, publicURI, resp)
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
todo:
|
todo:
|
||||||
|
- no hard code jpeg or have it in multiple places
|
||||||
|
- todo: switch house to selfhosted for rate limit
|
||||||
|
tags: now
|
||||||
|
- mark consumed;; save scroll id for matrix
|
||||||
|
- TEST its falling apart
|
||||||
- test each !command callbacks to matrix
|
- test each !command callbacks to matrix
|
||||||
- change matrix so I test my custom logic even if I dont fetch remote
|
- change matrix so I test my custom logic even if I dont fetch remote
|
||||||
- warn/err/etc. on clobbering ids.matrix since clients can mess with one another
|
- warn/err/etc. on clobbering ids.matrix since clients can mess with one another
|
||||||
|
|||||||
Reference in New Issue
Block a user