mirror of
https://github.com/ihabunek/toot.git
synced 2024-11-03 04:17:21 -05:00
Add commands: (un)mute, (un)block
This commit is contained in:
parent
3a1d7e17aa
commit
7563641f54
28
toot/api.py
28
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):
|
||||
|
@ -297,28 +297,40 @@ 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)
|
||||
|
||||
if not account:
|
||||
print_error("Account not found")
|
||||
return
|
||||
|
||||
api.unfollow(app, user, account['id'])
|
||||
|
||||
print(green("✓ You are no longer following %s" % args.account))
|
||||
|
||||
|
||||
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))
|
||||
|
||||
|
||||
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):
|
||||
account = api.verify_credentials(app, user)
|
||||
_print_account(account)
|
||||
|
@ -26,6 +26,12 @@ def visibility(value):
|
||||
Command = namedtuple("Command", ["name", "description", "require_auth", "arguments"])
|
||||
|
||||
|
||||
# Some common arguments:
|
||||
account_arg = (["account"], {
|
||||
"help": "account name, e.g. 'Gargron' or 'polymerwitch@toot.cat'",
|
||||
})
|
||||
|
||||
|
||||
COMMANDS = [
|
||||
Command(
|
||||
name="login",
|
||||
@ -116,9 +122,7 @@ COMMANDS = [
|
||||
name="follow",
|
||||
description="Follow an account",
|
||||
arguments=[
|
||||
(["account"], {
|
||||
"help": "account name, e.g. 'Gargron' or 'polymerwitch@toot.cat'",
|
||||
}),
|
||||
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 'polymerwitch@toot.cat'",
|
||||
}),
|
||||
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,
|
||||
),
|
||||
|
Loading…
Reference in New Issue
Block a user