enbas/internal/executor/reject.go
Dan Anglin b06fdc2960
checkpoint: add more commands to the schema
- Added accept and reject
- Added follow and unfollow
- Add ability to use a define a different field name for each flag
  reference.
2024-08-10 08:51:53 +01:00

40 lines
1 KiB
Go

package executor
import (
"fmt"
"codeflow.dananglin.me.uk/apollo/enbas/internal/client"
)
func (r *RejectExecutor) Execute() error {
funcMap := map[string]func(*client.Client) error{
resourceFollowRequest: r.rejectFollowRequest,
}
doFunc, ok := funcMap[r.resourceType]
if !ok {
return UnsupportedTypeError{resourceType: r.resourceType}
}
gtsClient, err := client.NewClientFromFile(r.config.CredentialsFile)
if err != nil {
return fmt.Errorf("unable to create the GoToSocial client: %w", err)
}
return doFunc(gtsClient)
}
func (r *RejectExecutor) rejectFollowRequest(gtsClient *client.Client) error {
accountID, err := getAccountID(gtsClient, false, r.accountName, r.config.CredentialsFile)
if err != nil {
return fmt.Errorf("received an error while getting the account ID: %w", err)
}
if err := gtsClient.RejectFollowRequest(accountID); err != nil {
return fmt.Errorf("unable to reject the follow request: %w", err)
}
r.printer.PrintSuccess("Successfully rejected the follow request.")
return nil
}