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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
@ -14,6 +15,7 @@ type addCommand struct {
|
||||||
toResourceType string
|
toResourceType string
|
||||||
listID string
|
listID string
|
||||||
accountNames accountNames
|
accountNames accountNames
|
||||||
|
content string
|
||||||
}
|
}
|
||||||
|
|
||||||
func newAddCommand(name, summary string) *addCommand {
|
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.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.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.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)
|
command.Usage = commandUsageFunc(name, summary, command.FlagSet)
|
||||||
|
|
||||||
|
@ -41,6 +44,7 @@ func (c *addCommand) Execute() error {
|
||||||
|
|
||||||
funcMap := map[string]func(*client.Client) error{
|
funcMap := map[string]func(*client.Client) error{
|
||||||
listResource: c.addToList,
|
listResource: c.addToList,
|
||||||
|
accountResource: c.addToAccount,
|
||||||
}
|
}
|
||||||
|
|
||||||
doFunc, ok := funcMap[c.toResourceType]
|
doFunc, ok := funcMap[c.toResourceType]
|
||||||
|
@ -97,3 +101,39 @@ func (c *addCommand) addAccountsToList(gtsClient *client.Client) error {
|
||||||
|
|
||||||
return nil
|
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 (
|
const (
|
||||||
accountNameFlag = "account-name"
|
accountNameFlag = "account-name"
|
||||||
addToFlag = "to"
|
addToFlag = "to"
|
||||||
|
contentFlag = "content"
|
||||||
instanceFlag = "instance"
|
instanceFlag = "instance"
|
||||||
|
limitFlag = "limit"
|
||||||
listIDFlag = "list-id"
|
listIDFlag = "list-id"
|
||||||
listTitleFlag = "list-title"
|
listTitleFlag = "list-title"
|
||||||
listRepliesPolicyFlag = "list-replies-policy"
|
listRepliesPolicyFlag = "list-replies-policy"
|
||||||
myAccountFlag = "my-account"
|
myAccountFlag = "my-account"
|
||||||
|
notifyFlag = "notify"
|
||||||
removeFromFlag = "from"
|
removeFromFlag = "from"
|
||||||
resourceTypeFlag = "type"
|
resourceTypeFlag = "type"
|
||||||
|
showAccountRelationshipFlag = "show-account-relationship"
|
||||||
|
showUserPreferencesFlag = "show-preferences"
|
||||||
|
showRepostsFlag = "show-reposts"
|
||||||
statusIDFlag = "status-id"
|
statusIDFlag = "status-id"
|
||||||
tagFlag = "tag"
|
tagFlag = "tag"
|
||||||
timelineCategoryFlag = "timeline-category"
|
timelineCategoryFlag = "timeline-category"
|
||||||
limitFlag = "limit"
|
|
||||||
toAccountFlag = "to-account"
|
toAccountFlag = "to-account"
|
||||||
showRepostsFlag = "show-reposts"
|
|
||||||
notifyFlag = "notify"
|
|
||||||
showAccountRelationshipFlag = "show-account-relationship"
|
|
||||||
showUserPreferencesFlag = "show-preferences"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
accountResource = "account"
|
accountResource = "account"
|
||||||
instanceResource = "instance"
|
blockedResource = "blocked"
|
||||||
listResource = "list"
|
|
||||||
statusResource = "status"
|
|
||||||
timelineResource = "timeline"
|
|
||||||
followersResource = "followers"
|
followersResource = "followers"
|
||||||
followingResource = "following"
|
followingResource = "following"
|
||||||
blockedResource = "blocked"
|
instanceResource = "instance"
|
||||||
|
listResource = "list"
|
||||||
|
noteResource = "note"
|
||||||
|
statusResource = "status"
|
||||||
|
timelineResource = "timeline"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Executor interface {
|
type Executor interface {
|
||||||
|
|
|
@ -166,6 +166,7 @@ func (a AccountRelationship) String() string {
|
||||||
)
|
)
|
||||||
|
|
||||||
if a.PrivateNote != "" {
|
if a.PrivateNote != "" {
|
||||||
|
output += "\n"
|
||||||
output += fmt.Sprintf(
|
output += fmt.Sprintf(
|
||||||
privateNoteFormat,
|
privateNoteFormat,
|
||||||
utilities.HeaderFormat("YOUR PRIVATE NOTE ABOUT THIS ACCOUNT:"),
|
utilities.HeaderFormat("YOUR PRIVATE NOTE ABOUT THIS ACCOUNT:"),
|
||||||
|
|
Loading…
Reference in a new issue