Add commands: (un)mute, (un)block - toot - Unnamed repository; edit this file '… | |
Log | |
Files | |
Refs | |
LICENSE | |
--- | |
commit 7563641f54d19f0654243454502c7d65f3f15e63 | |
parent 3a1d7e17aaaa2d0f2e3c7b99692f9c5ceef63ed5 | |
Author: Ivan Habunek <[email protected]> | |
Date: Wed, 26 Apr 2017 11:49:21 +0200 | |
Add commands: (un)mute, (un)block | |
Diffstat: | |
toot/api.py | 28 +++++++++++++++++++++++----- | |
toot/commands.py | 34 +++++++++++++++++++++---------- | |
toot/console.py | 46 +++++++++++++++++++++++++++---- | |
3 files changed, 86 insertions(+), 22 deletions(-) | |
--- | |
diff --git a/toot/api.py b/toot/api.py | |
@@ -92,6 +92,12 @@ def _post(app, user, url, data=None, files=None): | |
return _process_response(response) | |
+def _account_action(app, user, account, action): | |
+ url = '/api/v1/accounts/%d/%s' % (account, action) | |
+ | |
+ return _post(app, user, url).json() | |
+ | |
+ | |
def create_app(instance): | |
base_url = 'https://' + instance | |
url = base_url + '/api/v1/apps' | |
@@ -174,15 +180,27 @@ def search_accounts(app, user, query): | |
def follow(app, user, account): | |
- url = '/api/v1/accounts/%d/follow' % account | |
- | |
- return _post(app, user, url).json() | |
+ return _account_action(app, user, account, 'follow') | |
def unfollow(app, user, account): | |
- url = '/api/v1/accounts/%d/unfollow' % account | |
+ return _account_action(app, user, account, 'unfollow') | |
- return _post(app, user, url).json() | |
+ | |
+def mute(app, user, account): | |
+ return _account_action(app, user, account, 'mute') | |
+ | |
+ | |
+def unmute(app, user, account): | |
+ return _account_action(app, user, account, 'unmute') | |
+ | |
+ | |
+def block(app, user, account): | |
+ return _account_action(app, user, account, 'block') | |
+ | |
+ | |
+def unblock(app, user, account): | |
+ return _account_action(app, user, account, 'unblock') | |
def verify_credentials(app, user): | |
diff --git a/toot/commands.py b/toot/commands.py | |
@@ -297,26 +297,38 @@ def _print_account(account): | |
def follow(app, user, args): | |
account = _find_account(app, user, args.account) | |
- | |
- if not account: | |
- print_error("Account not found") | |
- return | |
- | |
api.follow(app, user, account['id']) | |
- | |
print(green("✓ You are now following %s" % args.account)) | |
def unfollow(app, user, args): | |
account = _find_account(app, user, args.account) | |
+ api.unfollow(app, user, account['id']) | |
+ print(green("✓ You are no longer following %s" % args.account)) | |
- if not account: | |
- print_error("Account not found") | |
- return | |
- api.unfollow(app, user, account['id']) | |
+def mute(app, user, args): | |
+ account = _find_account(app, user, args.account) | |
+ api.mute(app, user, account['id']) | |
+ print(green("✓ You have muted %s" % args.account)) | |
- print(green("✓ You are no longer following %s" % args.account)) | |
+ | |
+def unmute(app, user, args): | |
+ account = _find_account(app, user, args.account) | |
+ api.unmute(app, user, account['id']) | |
+ print(green("✓ %s is no longer muted" % args.account)) | |
+ | |
+ | |
+def block(app, user, args): | |
+ account = _find_account(app, user, args.account) | |
+ api.block(app, user, account['id']) | |
+ print(green("✓ You are now blocking %s" % args.account)) | |
+ | |
+ | |
+def unblock(app, user, args): | |
+ account = _find_account(app, user, args.account) | |
+ api.unblock(app, user, account['id']) | |
+ print(green("✓ %s is no longer blocked" % args.account)) | |
def whoami(app, user, args): | |
diff --git a/toot/console.py b/toot/console.py | |
@@ -26,6 +26,12 @@ def visibility(value): | |
Command = namedtuple("Command", ["name", "description", "require_auth", "argum… | |
+# Some common arguments: | |
+account_arg = (["account"], { | |
+ "help": "account name, e.g. 'Gargron' or '[email protected]'", | |
+}) | |
+ | |
+ | |
COMMANDS = [ | |
Command( | |
name="login", | |
@@ -116,9 +122,7 @@ COMMANDS = [ | |
name="follow", | |
description="Follow an account", | |
arguments=[ | |
- (["account"], { | |
- "help": "account name, e.g. 'Gargron' or '[email protected]… | |
- }), | |
+ account_arg, | |
], | |
require_auth=True, | |
), | |
@@ -126,9 +130,39 @@ COMMANDS = [ | |
name="unfollow", | |
description="Unfollow an account", | |
arguments=[ | |
- (["account"], { | |
- "help": "account name, e.g. 'Gargron' or '[email protected]… | |
- }), | |
+ account_arg, | |
+ ], | |
+ require_auth=True, | |
+ ), | |
+ Command( | |
+ name="mute", | |
+ description="Mute an account", | |
+ arguments=[ | |
+ account_arg, | |
+ ], | |
+ require_auth=True, | |
+ ), | |
+ Command( | |
+ name="unmute", | |
+ description="Unmute an account", | |
+ arguments=[ | |
+ account_arg, | |
+ ], | |
+ require_auth=True, | |
+ ), | |
+ Command( | |
+ name="block", | |
+ description="Block an account", | |
+ arguments=[ | |
+ account_arg, | |
+ ], | |
+ require_auth=True, | |
+ ), | |
+ Command( | |
+ name="unblock", | |
+ description="Unblock an account", | |
+ arguments=[ | |
+ account_arg, | |
], | |
require_auth=True, | |
), |