Compare commits
2 commits
8ecc2ec301
...
7b9ef14d92
Author | SHA1 | Date | |
---|---|---|---|
7b9ef14d92 | |||
64ecc90499 |
9 changed files with 81 additions and 34 deletions
|
@ -153,3 +153,29 @@ func (g *Client) GetLikedStatuses(limit int, resourceName string) (model.StatusL
|
|||
|
||||
return liked, nil
|
||||
}
|
||||
|
||||
func (g *Client) ReblogStatus(statusID string) error {
|
||||
url := g.Authentication.Instance + "/api/v1/statuses/" + statusID + "/reblog"
|
||||
|
||||
if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil {
|
||||
return fmt.Errorf(
|
||||
"received an error after sending the request to reblog the status; %w",
|
||||
err,
|
||||
)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *Client) UnreblogStatus(statusID string) error {
|
||||
url := g.Authentication.Instance + "/api/v1/statuses/" + statusID + "/unreblog"
|
||||
|
||||
if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil {
|
||||
return fmt.Errorf(
|
||||
"received an error after sending the request to un-reblog the status; %w",
|
||||
err,
|
||||
)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -187,9 +187,14 @@ func (a *AddExecutor) addStatusToBookmarks(gtsClient *client.Client) error {
|
|||
}
|
||||
|
||||
func (a *AddExecutor) addToStatus(gtsClient *client.Client) error {
|
||||
if a.statusID == "" {
|
||||
return FlagNotSetError{flagText: flagStatusID}
|
||||
}
|
||||
|
||||
funcMap := map[string]func(*client.Client) error{
|
||||
resourceStar: a.addStarToStatus,
|
||||
resourceLike: a.addStarToStatus,
|
||||
resourceStar: a.addStarToStatus,
|
||||
resourceLike: a.addStarToStatus,
|
||||
resourceBoost: a.addBoostToStatus,
|
||||
}
|
||||
|
||||
doFunc, ok := funcMap[a.resourceType]
|
||||
|
@ -204,10 +209,6 @@ func (a *AddExecutor) addToStatus(gtsClient *client.Client) error {
|
|||
}
|
||||
|
||||
func (a *AddExecutor) addStarToStatus(gtsClient *client.Client) error {
|
||||
if a.statusID == "" {
|
||||
return FlagNotSetError{flagText: flagStatusID}
|
||||
}
|
||||
|
||||
if err := gtsClient.LikeStatus(a.statusID); err != nil {
|
||||
return fmt.Errorf("unable to add the %s to the status: %w", a.resourceType, err)
|
||||
}
|
||||
|
@ -216,3 +217,13 @@ func (a *AddExecutor) addStarToStatus(gtsClient *client.Client) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *AddExecutor) addBoostToStatus(gtsClient *client.Client) error {
|
||||
if err := gtsClient.ReblogStatus(a.statusID); err != nil {
|
||||
return fmt.Errorf("unable to add the boost to the status: %w", err)
|
||||
}
|
||||
|
||||
fmt.Println("Successfully added the boost to the status.")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ const (
|
|||
resourceAccount = "account"
|
||||
resourceBlocked = "blocked"
|
||||
resourceBookmarks = "bookmarks"
|
||||
resourceBoost = "boost"
|
||||
resourceFollowers = "followers"
|
||||
resourceFollowing = "following"
|
||||
resourceInstance = "instance"
|
||||
|
|
|
@ -178,9 +178,14 @@ func (r *RemoveExecutor) removeStatusFromBookmarks(gtsClient *client.Client) err
|
|||
}
|
||||
|
||||
func (r *RemoveExecutor) removeFromStatus(gtsClient *client.Client) error {
|
||||
if r.statusID == "" {
|
||||
return FlagNotSetError{flagText: flagStatusID}
|
||||
}
|
||||
|
||||
funcMap := map[string]func(*client.Client) error{
|
||||
resourceStar: r.removeStarFromStatus,
|
||||
resourceLike: r.removeStarFromStatus,
|
||||
resourceStar: r.removeStarFromStatus,
|
||||
resourceLike: r.removeStarFromStatus,
|
||||
resourceBoost: r.removeBoostFromStatus,
|
||||
}
|
||||
|
||||
doFunc, ok := funcMap[r.resourceType]
|
||||
|
@ -195,10 +200,6 @@ func (r *RemoveExecutor) removeFromStatus(gtsClient *client.Client) error {
|
|||
}
|
||||
|
||||
func (r *RemoveExecutor) removeStarFromStatus(gtsClient *client.Client) error {
|
||||
if r.statusID == "" {
|
||||
return FlagNotSetError{flagText: flagStatusID}
|
||||
}
|
||||
|
||||
if err := gtsClient.UnlikeStatus(r.statusID); err != nil {
|
||||
return fmt.Errorf("unable to remove the %s from the status: %w", r.resourceType, err)
|
||||
}
|
||||
|
@ -207,3 +208,13 @@ func (r *RemoveExecutor) removeStarFromStatus(gtsClient *client.Client) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *RemoveExecutor) removeBoostFromStatus(gtsClient *client.Client) error {
|
||||
if err := gtsClient.UnreblogStatus(r.statusID); err != nil {
|
||||
return fmt.Errorf("unable to remove the boost from the status: %w", err)
|
||||
}
|
||||
|
||||
fmt.Println("Successfully removed the boost from the status.")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ type Field struct {
|
|||
|
||||
func (a Account) Display(noColor bool) string {
|
||||
format := `
|
||||
%s (@%s)
|
||||
%s
|
||||
|
||||
%s
|
||||
%s
|
||||
|
@ -98,8 +98,7 @@ func (a Account) Display(noColor bool) string {
|
|||
|
||||
return fmt.Sprintf(
|
||||
format,
|
||||
utilities.DisplayNameFormat(noColor, a.DisplayName),
|
||||
a.Username,
|
||||
utilities.FullDisplayNameFormat(noColor, a.DisplayName, a.Acct),
|
||||
utilities.HeaderFormat(noColor, "ACCOUNT ID:"),
|
||||
a.ID,
|
||||
utilities.HeaderFormat(noColor, "JOINED ON:"),
|
||||
|
@ -218,11 +217,7 @@ func (a AccountList) Display(noColor bool) string {
|
|||
}
|
||||
} else {
|
||||
for i := range a.Accounts {
|
||||
output += fmt.Sprintf(
|
||||
"\n • %s (%s)",
|
||||
utilities.DisplayNameFormat(noColor, a.Accounts[i].DisplayName),
|
||||
a.Accounts[i].Acct,
|
||||
)
|
||||
output += "\n • " + utilities.FullDisplayNameFormat(noColor, a.Accounts[i].DisplayName, a.Accounts[i].Acct)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -154,9 +154,9 @@ func (i InstanceV2) Display(noColor bool) string {
|
|||
i.Version,
|
||||
utilities.HeaderFormat(noColor, "CONTACT:"),
|
||||
utilities.FieldFormat(noColor, "Name:"),
|
||||
utilities.DisplayNameFormat(noColor, i.Contact.Account.DisplayName),
|
||||
i.Contact.Account.DisplayName,
|
||||
utilities.FieldFormat(noColor, "Username:"),
|
||||
i.Contact.Account.Username,
|
||||
i.Contact.Account.Acct,
|
||||
utilities.FieldFormat(noColor, "Email:"),
|
||||
i.Contact.Email,
|
||||
)
|
||||
|
|
|
@ -131,11 +131,7 @@ func (l List) Display(noColor bool) string {
|
|||
|
||||
if len(l.Accounts) > 0 {
|
||||
for acct, name := range l.Accounts {
|
||||
output += fmt.Sprintf(
|
||||
"\n • %s (%s)",
|
||||
utilities.DisplayNameFormat(noColor, name),
|
||||
acct,
|
||||
)
|
||||
output += "\n • " + utilities.FullDisplayNameFormat(noColor, name, acct)
|
||||
}
|
||||
} else {
|
||||
output += "\n None"
|
||||
|
|
|
@ -159,7 +159,7 @@ type MediaDimensions struct {
|
|||
|
||||
func (s Status) Display(noColor bool) string {
|
||||
format := `
|
||||
%s (@%s)
|
||||
%s
|
||||
|
||||
%s
|
||||
%s
|
||||
|
@ -183,7 +183,7 @@ func (s Status) Display(noColor bool) string {
|
|||
|
||||
return fmt.Sprintf(
|
||||
format,
|
||||
utilities.DisplayNameFormat(noColor, s.Account.DisplayName), s.Account.Username,
|
||||
utilities.FullDisplayNameFormat(noColor, s.Account.DisplayName, s.Account.Acct),
|
||||
utilities.HeaderFormat(noColor, "CONTENT:"),
|
||||
utilities.WrapLines(utilities.ConvertHTMLToText(s.Content), "\n ", 80),
|
||||
utilities.HeaderFormat(noColor, "STATUS ID:"),
|
||||
|
@ -214,13 +214,13 @@ func (s StatusList) Display(noColor bool) string {
|
|||
builder.WriteString(utilities.HeaderFormat(noColor, s.Name) + "\n")
|
||||
|
||||
for _, status := range s.Statuses {
|
||||
builder.WriteString("\n" + utilities.DisplayNameFormat(noColor, status.Account.DisplayName) + " (@" + status.Account.Acct + ")\n")
|
||||
builder.WriteString("\n" + utilities.FullDisplayNameFormat(noColor, status.Account.DisplayName, status.Account.Acct) + "\n")
|
||||
|
||||
statusID := status.ID
|
||||
createdAt := status.CreatedAt
|
||||
|
||||
if status.Reblog != nil {
|
||||
builder.WriteString("reposted this status from " + utilities.DisplayNameFormat(noColor, status.Reblog.Account.DisplayName) + " (@" + status.Reblog.Account.Acct + ")\n")
|
||||
builder.WriteString("reposted this status from " + utilities.FullDisplayNameFormat(noColor, status.Reblog.Account.DisplayName, status.Reblog.Account.Acct) + "\n")
|
||||
statusID = status.Reblog.ID
|
||||
createdAt = status.Reblog.CreatedAt
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ package utilities
|
|||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -32,15 +33,21 @@ func FieldFormat(noColor bool, text string) string {
|
|||
return green + text + reset
|
||||
}
|
||||
|
||||
func DisplayNameFormat(noColor bool, text string) string {
|
||||
func FullDisplayNameFormat(noColor bool, displayName, acct string) string {
|
||||
// use this pattern to remove all emoji strings
|
||||
pattern := regexp.MustCompile(`\s:[A-Za-z0-9]*:`)
|
||||
|
||||
var builder strings.Builder
|
||||
|
||||
if noColor {
|
||||
return pattern.ReplaceAllString(text, "")
|
||||
builder.WriteString(pattern.ReplaceAllString(displayName, ""))
|
||||
} else {
|
||||
builder.WriteString(boldmagenta + pattern.ReplaceAllString(displayName, "") + reset)
|
||||
}
|
||||
|
||||
return boldmagenta + pattern.ReplaceAllString(text, "") + reset
|
||||
builder.WriteString(" (@" + acct + ")")
|
||||
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
func FormatDate(date time.Time) string {
|
||||
|
|
Loading…
Reference in a new issue