add a raw sendactivity API action
This commit is contained in:
parent
f76a5d6113
commit
3014826f6f
26
activity.go
26
activity.go
|
@ -1186,24 +1186,34 @@ func gimmejonk(xid string) ([]byte, bool) {
|
||||||
return j, ok
|
return j, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
func honkworldwide(user *WhatAbout, honk *Honk) {
|
func boxuprcpts(user *WhatAbout, addresses []string, useshared bool) map[string]bool {
|
||||||
jonk, _ := jonkjonk(user, honk)
|
|
||||||
jonk["@context"] = itiswhatitis
|
|
||||||
msg := jonk.ToBytes()
|
|
||||||
|
|
||||||
rcpts := make(map[string]bool)
|
rcpts := make(map[string]bool)
|
||||||
for _, a := range honk.Audience {
|
for _, a := range addresses {
|
||||||
if a == thewholeworld || a == user.URL || strings.HasSuffix(a, "/followers") {
|
if a == "" || a == thewholeworld || a == user.URL || strings.HasSuffix(a, "/followers") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if a[0] == '%' {
|
||||||
|
rcpts[a] = true
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
var box *Box
|
var box *Box
|
||||||
ok := boxofboxes.Get(a, &box)
|
ok := boxofboxes.Get(a, &box)
|
||||||
if ok && honk.Public && box.Shared != "" {
|
if ok && useshared && box.Shared != "" {
|
||||||
rcpts["%"+box.Shared] = true
|
rcpts["%"+box.Shared] = true
|
||||||
} else {
|
} else {
|
||||||
rcpts[a] = true
|
rcpts[a] = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return rcpts
|
||||||
|
}
|
||||||
|
|
||||||
|
func honkworldwide(user *WhatAbout, honk *Honk) {
|
||||||
|
jonk, _ := jonkjonk(user, honk)
|
||||||
|
jonk["@context"] = itiswhatitis
|
||||||
|
msg := jonk.ToBytes()
|
||||||
|
|
||||||
|
rcpts := boxuprcpts(user, honk.Audience, honk.Public)
|
||||||
|
|
||||||
if honk.Public {
|
if honk.Public {
|
||||||
for _, h := range getdubs(user.ID) {
|
for _, h := range getdubs(user.ID) {
|
||||||
if h.XID == user.URL {
|
if h.XID == user.URL {
|
||||||
|
|
|
@ -2,6 +2,8 @@ changelog
|
||||||
|
|
||||||
-- next
|
-- next
|
||||||
|
|
||||||
|
+ A raw sendactivity API action for the bold.
|
||||||
|
|
||||||
+ More flexible meme names.
|
+ More flexible meme names.
|
||||||
|
|
||||||
-- 0.8.5 Turnkey Blaster
|
-- 0.8.5 Turnkey Blaster
|
||||||
|
|
14
docs/honk.3
14
docs/honk.3
|
@ -109,6 +109,20 @@ If there are no results, wait this many seconds for something to appear.
|
||||||
.El
|
.El
|
||||||
.Pp
|
.Pp
|
||||||
The result will be returned as json.
|
The result will be returned as json.
|
||||||
|
.Ss sendactivity
|
||||||
|
Send anything.
|
||||||
|
No limits, no error checking.
|
||||||
|
.Bl -tag -width public
|
||||||
|
.It Fa rcpt
|
||||||
|
An actor to deliver the message to to.
|
||||||
|
May be specified more than once.
|
||||||
|
An inbox may be specified directly by prefixing with %.
|
||||||
|
.It Fa msg
|
||||||
|
The message.
|
||||||
|
It should be a valid json activity, but yolo.
|
||||||
|
.It Fa public
|
||||||
|
Set to 1 to use shared inboxes for delivery.
|
||||||
|
.El
|
||||||
.Sh EXAMPLES
|
.Sh EXAMPLES
|
||||||
Refer to the sample code in the
|
Refer to the sample code in the
|
||||||
.Pa toys
|
.Pa toys
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
all: gettoken saytheday youvegothonks
|
all: gettoken saytheday sprayandpray youvegothonks
|
||||||
|
|
||||||
gettoken: gettoken.go
|
gettoken: gettoken.go
|
||||||
go build gettoken.go
|
go build gettoken.go
|
||||||
|
@ -7,5 +7,8 @@ gettoken: gettoken.go
|
||||||
saytheday: saytheday.go
|
saytheday: saytheday.go
|
||||||
go build saytheday.go
|
go build saytheday.go
|
||||||
|
|
||||||
|
sprayandpray: sprayandpray.go
|
||||||
|
go build sprayandpray.go
|
||||||
|
|
||||||
youvegothonks: youvegothonks.go
|
youvegothonks: youvegothonks.go
|
||||||
go build youvegothonks.go
|
go build youvegothonks.go
|
||||||
|
|
|
@ -4,6 +4,8 @@ A little of this, a little of that.
|
||||||
|
|
||||||
gettoken.go - obtains an authorization token
|
gettoken.go - obtains an authorization token
|
||||||
|
|
||||||
saytheday.go - posts a new honk
|
saytheday.go - posts a new honk that's a date based look and say sequence
|
||||||
|
|
||||||
|
sprayandpray.go - send an activity with no error checking and hope it works
|
||||||
|
|
||||||
youvegothonks.go - polls for new mesages
|
youvegothonks.go - polls for new mesages
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
func sendmsg(server, token, msg, rcpt string) {
|
||||||
|
form := make(url.Values)
|
||||||
|
form.Add("token", token)
|
||||||
|
form.Add("action", "sendactivity")
|
||||||
|
form.Add("msg", msg)
|
||||||
|
form.Add("rcpt", rcpt)
|
||||||
|
apiurl := fmt.Sprintf("https://%s/api", server)
|
||||||
|
req, err := http.NewRequest("POST", apiurl, strings.NewReader(form.Encode()))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||||
|
resp, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
answer, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
if resp.StatusCode != 200 {
|
||||||
|
log.Fatalf("status: %d: %s", resp.StatusCode, answer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var server, token, msgfile, rcpt string
|
||||||
|
flag.StringVar(&server, "server", server, "server to connnect")
|
||||||
|
flag.StringVar(&token, "token", token, "auth token to use")
|
||||||
|
flag.StringVar(&msgfile, "msgfile", token, "file with message to send")
|
||||||
|
flag.StringVar(&rcpt, "rcpt", rcpt, "rcpt to send it to")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
if server == "" || token == "" || msgfile == "" || rcpt == "" {
|
||||||
|
flag.Usage()
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
msg, err := ioutil.ReadFile(msgfile)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
sendmsg(server, token, string(msg), rcpt)
|
||||||
|
}
|
8
web.go
8
web.go
|
@ -2138,6 +2138,7 @@ func honkhonkline() {
|
||||||
func apihandler(w http.ResponseWriter, r *http.Request) {
|
func apihandler(w http.ResponseWriter, r *http.Request) {
|
||||||
u := login.GetUserInfo(r)
|
u := login.GetUserInfo(r)
|
||||||
userid := u.UserID
|
userid := u.UserID
|
||||||
|
user, _ := butwhatabout(u.Username)
|
||||||
action := r.FormValue("action")
|
action := r.FormValue("action")
|
||||||
wait, _ := strconv.ParseInt(r.FormValue("wait"), 10, 0)
|
wait, _ := strconv.ParseInt(r.FormValue("wait"), 10, 0)
|
||||||
log.Printf("api request '%s' on behalf of %s", action, u.Username)
|
log.Printf("api request '%s' on behalf of %s", action, u.Username)
|
||||||
|
@ -2175,6 +2176,13 @@ func apihandler(w http.ResponseWriter, r *http.Request) {
|
||||||
j := junk.New()
|
j := junk.New()
|
||||||
j["honks"] = honks
|
j["honks"] = honks
|
||||||
j.Write(w)
|
j.Write(w)
|
||||||
|
case "sendactivity":
|
||||||
|
public := r.FormValue("public") == "1"
|
||||||
|
rcpts := boxuprcpts(user, r.Form["rcpt"], public)
|
||||||
|
msg := []byte(r.FormValue("msg"))
|
||||||
|
for rcpt := range rcpts {
|
||||||
|
go deliverate(0, userid, rcpt, msg)
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
http.Error(w, "unknown action", http.StatusNotFound)
|
http.Error(w, "unknown action", http.StatusNotFound)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue