Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 613576f438 | |||
| a2a93adfb6 | |||
| 3b06d6b773 |
2
Makefile
2
Makefile
@@ -5,6 +5,6 @@ VERSION ?= `git describe --tags`
|
||||
REVISION ?= `git rev-list --all | wc -l`
|
||||
|
||||
build:
|
||||
@${GO} build ${GOFLAGS} -o mikuru ./cmd
|
||||
@${GO} build ${GOFLAGS}
|
||||
clean:
|
||||
@rm -f mikuru
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
A [yarn.social](https://yarn.social) client from the future
|
||||
|
||||
## Current status
|
||||
* [ ] Follow/Unfollow
|
||||
* [X] Follow/Unfollow
|
||||
* [X] Login
|
||||
* [X] Posting
|
||||
* [ ] Timeline
|
||||
|
||||
@@ -6,8 +6,7 @@ env:
|
||||
GO: go
|
||||
|
||||
vars:
|
||||
IMPORT: git.laidback.moe/shinyoukai/mikuru
|
||||
DIR: ./cmd
|
||||
IMPORT: git.laidback.moe/shinyoukai/mikuru/mirai
|
||||
tasks:
|
||||
default:
|
||||
cmds:
|
||||
@@ -15,7 +14,7 @@ tasks:
|
||||
build:
|
||||
desc: Build the client
|
||||
cmds:
|
||||
- $GO build -ldflags='-s -w -X "{{.IMPORT}}.Version={{.VERSION}}" -X "{{.IMPORT}}.Revision={{.REVISION}}"' -v -o mikuru {{.DIR}}
|
||||
- $GO build -ldflags='-s -w -X "{{.IMPORT}}.Version={{.VERSION}}" -X "{{.IMPORT}}.Revision={{.REVISION}}"' -v
|
||||
vars:
|
||||
REVISION:
|
||||
sh: git rev-list --all | wc -l | tr -d ' '
|
||||
|
||||
45
follow.go
Normal file
45
follow.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"git.laidback.moe/shinyoukai/mikuru/mirai"
|
||||
"go.yarn.social/client"
|
||||
)
|
||||
|
||||
var followCmd = &cobra.Command{
|
||||
Use: "follow <NICK> <URL>",
|
||||
Short: "Track a twtxt.txt feed, located in a Yarn pod or otherwise",
|
||||
Run: func(_ *cobra.Command, args []string) {
|
||||
cli, err := client.NewClient(
|
||||
client.WithURI(mirai.Config.Host),
|
||||
client.WithToken(mirai.Config.Token),
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if len(args) != 2 {
|
||||
log.Fatal("Not enough arguments")
|
||||
}
|
||||
nick := args[0]
|
||||
url := args[1]
|
||||
|
||||
observe(cli, nick, url)
|
||||
if err != nil {
|
||||
log.Fatalf("Could not follow %s at %s\n", nick, url)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
mirai.ConfInit()
|
||||
rootCmd.AddCommand(followCmd)
|
||||
}
|
||||
|
||||
func observe(cli *client.Client, nick, url string) error {
|
||||
err := cli.Follow(nick, url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
"golang.org/x/term"
|
||||
"go.yarn.social/client"
|
||||
"git.laidback.moe/shinyoukai/mikuru"
|
||||
"git.laidback.moe/shinyoukai/mikuru/mirai"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -20,20 +20,20 @@ var (
|
||||
|
||||
var loginCmd = &cobra.Command{
|
||||
Use: "login",
|
||||
Short: "Authenticate against a Yarn.social pod",
|
||||
Short: "Authenticate against a Yarn pod",
|
||||
Aliases: []string{"auth", "signin"},
|
||||
Args: cobra.MaximumNArgs(0),
|
||||
Run: func(_ *cobra.Command, _ []string) {
|
||||
cli, err := client.NewClient(client.WithURI(mikuru.Config.Host))
|
||||
cli, err := client.NewClient(client.WithURI(mirai.Config.Host))
|
||||
if err != nil {
|
||||
log.Fatal("Unable to create client", err)
|
||||
log.Fatalf("Unable to create client\n%s\n", err)
|
||||
}
|
||||
signin(cli)
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
mikuru.ConfInit()
|
||||
mirai.ConfInit()
|
||||
rootCmd.AddCommand(loginCmd)
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ func signin(cli *client.Client) {
|
||||
fmt.Printf("Password: ")
|
||||
data, err := term.ReadPassword(int(syscall.Stdin))
|
||||
if err != nil {
|
||||
log.Fatal("Unable to obtain password", err)
|
||||
log.Fatalf("Unable to obtain password\n%s\n", err)
|
||||
}
|
||||
|
||||
password := string(data)
|
||||
@@ -57,7 +57,7 @@ func signin(cli *client.Client) {
|
||||
res, err := cli.Login(username, password)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal("Unable to login", err)
|
||||
log.Fatalf("Unable to login\n%s\n", err)
|
||||
}
|
||||
|
||||
token := strings.Trim(fmt.Sprintf(res.Token), "{}")
|
||||
@@ -1,4 +1,4 @@
|
||||
package mikuru
|
||||
package mirai
|
||||
|
||||
import (
|
||||
"log"
|
||||
17
mirai/version.go
Normal file
17
mirai/version.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package mirai
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var (
|
||||
Revision = "0"
|
||||
Version = "0"
|
||||
)
|
||||
|
||||
func FullVersion() string {
|
||||
return fmt.Sprintf("%s (r%s)", Version, Revision)
|
||||
}
|
||||
func PrintVersion() string {
|
||||
return fmt.Sprintf("%s", Version)
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"git.laidback.moe/shinyoukai/mikuru"
|
||||
"git.laidback.moe/shinyoukai/mikuru/mirai"
|
||||
"go.yarn.social/client"
|
||||
"github.com/tj/go-editor"
|
||||
log "github.com/sirupsen/logrus"
|
||||
@@ -14,11 +14,11 @@ var postCmd = &cobra.Command{
|
||||
Short: "Publish a new post to a Yarn pod",
|
||||
Run: func(_ *cobra.Command, args []string) {
|
||||
cli, err := client.NewClient(
|
||||
client.WithURI(mikuru.Config.Host),
|
||||
client.WithToken(mikuru.Config.Token),
|
||||
client.WithURI(mirai.Config.Host),
|
||||
client.WithToken(mirai.Config.Token),
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatal("Unable to create client", err)
|
||||
log.Fatalf("Unable to create client\n%s\n", err)
|
||||
}
|
||||
write(cli)
|
||||
},
|
||||
@@ -26,7 +26,7 @@ var postCmd = &cobra.Command{
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(postCmd)
|
||||
mikuru.ConfInit()
|
||||
mirai.ConfInit()
|
||||
}
|
||||
|
||||
func write(cli *client.Client) {
|
||||
@@ -35,7 +35,7 @@ func write(cli *client.Client) {
|
||||
data, err := editor.Read()
|
||||
|
||||
if err != nil {
|
||||
log.Fatal("Unable to read content from editor", err)
|
||||
log.Fatalf("Unable to read content from editor\n%s\n", err)
|
||||
}
|
||||
|
||||
post = string(data)
|
||||
@@ -43,6 +43,6 @@ func write(cli *client.Client) {
|
||||
_, err = cli.Post(post, "")
|
||||
|
||||
if err != nil {
|
||||
log.Fatal("Unable to publish tweet", err)
|
||||
log.Fatalf("Unable to publish tweet\n%s\n", err)
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,13 @@ package main
|
||||
import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"git.laidback.moe/shinyoukai/mikuru"
|
||||
"git.laidback.moe/shinyoukai/mikuru/mirai"
|
||||
)
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "mikuru",
|
||||
Short: "A client for Yarn.social from the future",
|
||||
Version: mikuru.Version,
|
||||
Version: mirai.FullVersion(),
|
||||
}
|
||||
|
||||
func Execute() {
|
||||
44
unfollow.go
Normal file
44
unfollow.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"git.laidback.moe/shinyoukai/mikuru/mirai"
|
||||
"go.yarn.social/client"
|
||||
)
|
||||
|
||||
var unfollowCmd = &cobra.Command{
|
||||
Use: "unfollow <NICK>",
|
||||
Short: "Cease to track a feed",
|
||||
Run: func(_ *cobra.Command, args []string) {
|
||||
cli, err := client.NewClient(
|
||||
client.WithURI(mirai.Config.Host),
|
||||
client.WithToken(mirai.Config.Token),
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if len(args) != 1 {
|
||||
log.Fatal("Not enough arguments")
|
||||
}
|
||||
nick := args[0]
|
||||
|
||||
leave_alone(cli, nick)
|
||||
if err != nil {
|
||||
log.Fatalf("Could not unfollow %s\n", nick)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
mirai.ConfInit()
|
||||
rootCmd.AddCommand(unfollowCmd)
|
||||
}
|
||||
|
||||
func leave_alone(cli *client.Client, nick string) error {
|
||||
err := cli.Unfollow(nick)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
13
version.go
13
version.go
@@ -1,13 +0,0 @@
|
||||
package mikuru
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var (
|
||||
Version = "0"
|
||||
)
|
||||
|
||||
func PrintVersion() string {
|
||||
return fmt.Sprintf("%s", Version)
|
||||
}
|
||||
Reference in New Issue
Block a user