checkpoint: we can now add private notes
This commit is contained in:
parent
b12f2328b3
commit
e6fdb621aa
3 changed files with 54 additions and 11 deletions
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
|
@ -14,6 +15,7 @@ type addCommand struct {
|
|||
toResourceType string
|
||||
listID string
|
||||
accountNames accountNames
|
||||
content string
|
||||
}
|
||||
|
||||
func newAddCommand(name, summary string) *addCommand {
|
||||
|
@ -28,6 +30,7 @@ func newAddCommand(name, summary string) *addCommand {
|
|||
command.StringVar(&command.toResourceType, addToFlag, "", "specify the target resource type to add to (e.g. list, account, etc)")
|
||||
command.StringVar(&command.listID, listIDFlag, "", "the ID of the list to add to")
|
||||
command.Var(&command.accountNames, accountNameFlag, "the name of the account to add to the resource")
|
||||
command.StringVar(&command.content, contentFlag, "", "the content of the note")
|
||||
|
||||
command.Usage = commandUsageFunc(name, summary, command.FlagSet)
|
||||
|
||||
|
@ -40,7 +43,8 @@ func (c *addCommand) Execute() error {
|
|||
}
|
||||
|
||||
funcMap := map[string]func(*client.Client) error{
|
||||
listResource: c.addToList,
|
||||
listResource: c.addToList,
|
||||
accountResource: c.addToAccount,
|
||||
}
|
||||
|
||||
doFunc, ok := funcMap[c.toResourceType]
|
||||
|
@ -97,3 +101,39 @@ func (c *addCommand) addAccountsToList(gtsClient *client.Client) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *addCommand) addToAccount(gtsClient *client.Client) error {
|
||||
funcMap := map[string]func(*client.Client) error{
|
||||
noteResource: c.addNoteToAccount,
|
||||
}
|
||||
|
||||
doFunc, ok := funcMap[c.resourceType]
|
||||
if !ok {
|
||||
return unsupportedResourceTypeError{resourceType: c.resourceType}
|
||||
}
|
||||
|
||||
return doFunc(gtsClient)
|
||||
}
|
||||
|
||||
func (c *addCommand) addNoteToAccount(gtsClient *client.Client) error {
|
||||
if len(c.accountNames) != 1 {
|
||||
return fmt.Errorf("unexpected number of accounts specified; want 1, got %d", len(c.accountNames))
|
||||
}
|
||||
|
||||
accountID, err := getAccountID(gtsClient, false, c.accountNames[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("received an error while getting the account ID; %w", err)
|
||||
}
|
||||
|
||||
if c.content == "" {
|
||||
return errors.New("the note content should not be empty")
|
||||
}
|
||||
|
||||
if err := gtsClient.SetPrivateNote(accountID, c.content); err != nil {
|
||||
return fmt.Errorf("unable to add the private note to the account; %w", err)
|
||||
}
|
||||
|
||||
fmt.Println("Successfully added the private note to the account.")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -9,33 +9,35 @@ import (
|
|||
const (
|
||||
accountNameFlag = "account-name"
|
||||
addToFlag = "to"
|
||||
contentFlag = "content"
|
||||
instanceFlag = "instance"
|
||||
limitFlag = "limit"
|
||||
listIDFlag = "list-id"
|
||||
listTitleFlag = "list-title"
|
||||
listRepliesPolicyFlag = "list-replies-policy"
|
||||
myAccountFlag = "my-account"
|
||||
notifyFlag = "notify"
|
||||
removeFromFlag = "from"
|
||||
resourceTypeFlag = "type"
|
||||
showAccountRelationshipFlag = "show-account-relationship"
|
||||
showUserPreferencesFlag = "show-preferences"
|
||||
showRepostsFlag = "show-reposts"
|
||||
statusIDFlag = "status-id"
|
||||
tagFlag = "tag"
|
||||
timelineCategoryFlag = "timeline-category"
|
||||
limitFlag = "limit"
|
||||
toAccountFlag = "to-account"
|
||||
showRepostsFlag = "show-reposts"
|
||||
notifyFlag = "notify"
|
||||
showAccountRelationshipFlag = "show-account-relationship"
|
||||
showUserPreferencesFlag = "show-preferences"
|
||||
)
|
||||
|
||||
const (
|
||||
accountResource = "account"
|
||||
instanceResource = "instance"
|
||||
listResource = "list"
|
||||
statusResource = "status"
|
||||
timelineResource = "timeline"
|
||||
blockedResource = "blocked"
|
||||
followersResource = "followers"
|
||||
followingResource = "following"
|
||||
blockedResource = "blocked"
|
||||
instanceResource = "instance"
|
||||
listResource = "list"
|
||||
noteResource = "note"
|
||||
statusResource = "status"
|
||||
timelineResource = "timeline"
|
||||
)
|
||||
|
||||
type Executor interface {
|
||||
|
|
|
@ -166,6 +166,7 @@ func (a AccountRelationship) String() string {
|
|||
)
|
||||
|
||||
if a.PrivateNote != "" {
|
||||
output += "\n"
|
||||
output += fmt.Sprintf(
|
||||
privateNoteFormat,
|
||||
utilities.HeaderFormat("YOUR PRIVATE NOTE ABOUT THIS ACCOUNT:"),
|
||||
|
|
Loading…
Reference in a new issue