Skip to content

Commit

Permalink
Add support for specified spoiler text
Browse files Browse the repository at this point in the history
  • Loading branch information
waybackarchiver committed Jun 15, 2024
1 parent 33f2909 commit 5105387
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 0 deletions.
54 changes: 54 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,60 @@ func TestMastodon(t *testing.T) {
},
want: "foo",
},
{
name: "default mastodon cw",
envs: map[string]string{
"WAYBACK_MASTODON_CW": "true",
},
call: func(t *testing.T, opts *Options, want string) {
called := strconv.FormatBool(opts.MastodonCW())
if called != want {
t.Errorf(`Unexpected get the mastodon cw status, got %v instead of %s`, called, want)
}
},
want: "true",
},
{
name: "specified mastodon cw",
envs: map[string]string{
"WAYBACK_MASTODON_CW": "false",
},
call: func(t *testing.T, opts *Options, want string) {
called := strconv.FormatBool(opts.MastodonCW())
if called != want {
t.Errorf(`Unexpected get the mastodon cw status, got %v instead of %s`, called, want)
}
},
want: "false",
},
{
name: "default mastodon cw text",
envs: map[string]string{
"WAYBACK_MASTODON_CWTEXT": "",
},
call: func(t *testing.T, opts *Options, want string) {
opts.mastodon.cw = true
called := opts.MastodonCWText()
if called != want {
t.Errorf(`Unexpected get the mastodon cw text, got %v instead of %s`, called, want)
}
},
want: defMastodonCWText,
},
{
name: "specified mastodon cw text",
envs: map[string]string{
"WAYBACK_MASTODON_CWTEXT": "foo",
},
call: func(t *testing.T, opts *Options, want string) {
opts.mastodon.cw = true
called := opts.MastodonCWText()
if called != want {
t.Errorf(`Unexpected get the mastodon cw text, got %v instead of %s`, called, want)
}
},
want: "foo",
},
{
name: "publish to mastodon enabled",
envs: map[string]string{
Expand Down
19 changes: 19 additions & 0 deletions config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ const (
defMastodonClientKey = ""
defMastodonClientSecret = ""
defMastodonAccessToken = ""
defMastodonCW = false
defMastodonCWText = "Wayback archive links"
defTwitterConsumerKey = ""
defTwitterConsumerSecret = ""
defTwitterAccessToken = ""
Expand Down Expand Up @@ -177,6 +179,8 @@ type mastodon struct {
clientKey string
clientSecret string
accessToken string
cw bool
cwText string
}

type discord struct {
Expand Down Expand Up @@ -293,6 +297,8 @@ func NewOptions() *Options {
clientKey: defMastodonClientKey,
clientSecret: defMastodonClientSecret,
accessToken: defMastodonAccessToken,
cw: defMastodonCW,
cwText: defMastodonCWText,
},
discord: &discord{
appID: defDiscordBotToken,
Expand Down Expand Up @@ -529,6 +535,19 @@ func (o *Options) MastodonAccessToken() string {
return o.mastodon.accessToken
}

// MastodonCW returns whether to enable content warning for publish to Mastodon.
func (o *Options) MastodonCW() bool {
return o.mastodon.cw
}

// MastodonCWText returns the CW text for publish to Mastodon.
func (o *Options) MastodonCWText() string {
if o.MastodonCW() {
return o.mastodon.cwText
}
return ""
}

// PublishToMastodon returns whether to publish result to Mastodon.
func (o *Options) PublishToMastodon() bool {
return o.MastodonServer() != "" &&
Expand Down
4 changes: 4 additions & 0 deletions config/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ func (p *Parser) parseLines(lines []string) (err error) {
p.opts.mastodon.clientSecret = parseString(val, defMastodonClientSecret)
case "WAYBACK_MASTODON_TOKEN":
p.opts.mastodon.accessToken = parseString(val, defMastodonAccessToken)
case "WAYBACK_MASTODON_CW":
p.opts.mastodon.cw = parseBool(val, defMastodonCW)
case "WAYBACK_MASTODON_CWTEXT":
p.opts.mastodon.cwText = parseString(val, defMastodonCWText)
case "WAYBACK_TWITTER_CONSUMER_KEY":
p.opts.twitter.consumerKey = parseString(val, defTwitterConsumerKey)
case "WAYBACK_TWITTER_CONSUMER_SECRET":
Expand Down
2 changes: 2 additions & 0 deletions docs/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ Use the `-c` / `--config` option to specify the build definition file to use.
| - | `WAYBACK_MASTODON_KEY` | - | The client key of your Mastodon application |
| - | `WAYBACK_MASTODON_SECRET` | - | The client secret of your Mastodon application |
| - | `WAYBACK_MASTODON_TOKEN` | - | The access token of your Mastodon application |
| - | `WAYBACK_MASTODON_CW` | `false` | Whether specified content warning |
| - | `WAYBACK_MASTODON_CWTEXT` | `Wayback archive links` | The text of content warning |
| - | `WAYBACK_TWITTER_CONSUMER_KEY` | - | The customer key of your Twitter application |
| - | `WAYBACK_TWITTER_CONSUMER_SECRET` | - | The customer secret of your Twitter application |
| - | `WAYBACK_TWITTER_ACCESS_TOKEN` | - | The access token of your Twitter application |
Expand Down
1 change: 1 addition & 0 deletions publish/mastodon/mastodon.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (m *Mastodon) toMastodon(ctx context.Context, text, id string) bool {

toot := &mastodon.Toot{
Status: text,

Check failure on line 87 in publish/mastodon/mastodon.go

View workflow job for this annotation

GitHub Actions / golangci-lint / golangci (macos-latest)

File is not `gofmt`-ed with `-s` (gofmt)

Check failure on line 87 in publish/mastodon/mastodon.go

View workflow job for this annotation

GitHub Actions / golangci-lint / golangci (ubuntu-latest)

File is not `gofmt`-ed with `-s` (gofmt)

Check failure on line 87 in publish/mastodon/mastodon.go

View workflow job for this annotation

GitHub Actions / golangci-lint / golangci (windows-latest)

File is not `gofmt`-ed with `-s` (gofmt)
SpoilerText: m.opts.MastodonCWText(),
Visibility: mastodon.VisibilityPublic,
}
if id != "" {
Expand Down
6 changes: 6 additions & 0 deletions wayback.1
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ The client secret of your Mastodon application\&.
.B WAYBACK_MASTODON_TOKEN
The access token of your Mastodon application\&.
.TP
.B WAYBACK_MASTODON_CW
Whether specified content warning\&.
.TP
.B WAYBACK_MASTODON_CWTEXT
The text of content warning\&.
.TP
.B WAYBACK_TWITTER_CONSUMER_KEY
The customer key of your Twitter application\&.
.TP
Expand Down
2 changes: 2 additions & 0 deletions wayback.conf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ WAYBACK_MASTODON_SERVER=
WAYBACK_MASTODON_KEY=
WAYBACK_MASTODON_SECRET=
WAYBACK_MASTODON_TOKEN=
WAYBACK_MASTODON_CW=false
WAYBACK_MASTODON_CWTEXT=Wayback archive links
WAYBACK_TWITTER_CONSUMER_KEY=
WAYBACK_TWITTER_CONSUMER_SECRE=
WAYBACK_TWITTER_ACCESS_TOKEN=
Expand Down

0 comments on commit 5105387

Please sign in to comment.