67 lines
1.4 KiB
Go
67 lines
1.4 KiB
Go
package output
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"time"
|
|
|
|
"github.com/bluesky-social/indigo/api/atproto"
|
|
"github.com/bluesky-social/indigo/api/bsky"
|
|
lexutil "github.com/bluesky-social/indigo/lex/util"
|
|
"github.com/bluesky-social/indigo/util"
|
|
"github.com/bluesky-social/indigo/xrpc"
|
|
)
|
|
|
|
type blueskyoutput struct {
|
|
identifier string
|
|
password string
|
|
}
|
|
|
|
func BlueskyOutput(identifier string, password string) *blueskyoutput {
|
|
blueskyoutput := &blueskyoutput{
|
|
identifier: identifier,
|
|
password: password,
|
|
}
|
|
|
|
return blueskyoutput
|
|
}
|
|
|
|
func (bo *blueskyoutput) Write(str string) error {
|
|
cli := &xrpc.Client{
|
|
Host: "https://bsky.social",
|
|
}
|
|
|
|
input := &atproto.ServerCreateSession_Input{
|
|
Identifier: bo.identifier,
|
|
Password: bo.password,
|
|
}
|
|
|
|
output, err := atproto.ServerCreateSession(context.TODO(), cli, input)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
cli.Auth = &xrpc.AuthInfo{
|
|
AccessJwt: output.AccessJwt,
|
|
RefreshJwt: output.RefreshJwt,
|
|
Handle: output.Handle,
|
|
Did: output.Did,
|
|
}
|
|
|
|
Recordinput := &atproto.RepoCreateRecord_Input{
|
|
Collection: "app.bsky.feed.post",
|
|
Repo: cli.Auth.Did, // "matope.bsky.social" のDID
|
|
Record: &lexutil.LexiconTypeDecoder{&bsky.FeedPost{
|
|
Text: str,
|
|
CreatedAt: time.Now().Format(util.ISO8601),
|
|
Langs: []string{"ja"},
|
|
}},
|
|
}
|
|
_, recerr := atproto.RepoCreateRecord(context.TODO(), cli, Recordinput)
|
|
|
|
return recerr
|
|
}
|
|
|
|
func (bo *blueskyoutput) GetName() string {
|
|
return "bluesky"
|
|
}
|