Allow nicknames when looking for mentions

This commit is contained in:
Lucidiot 2019-09-02 23:26:50 +02:00
parent 70e932f2d7
commit 0247de2875
Signed by: lucidiot
GPG Key ID: 3358C1CA6906FB8D
2 changed files with 17 additions and 5 deletions

View File

@ -10,8 +10,6 @@ To-do
-----
* Error handling
* Read user info from twtxt following list to guess the URL in mentions :
``twtxt-registry registry.twtxt.org mentions johndoe``
* Command-line help
* Sphinx documentation
@ -20,3 +18,4 @@ To-do
* Parsing, enhanced outputs and porcelain mode, just like with `twtxt`_
* Verbose output and logging
* Set user-agent depending on twtxt's ``disclose_identity``

View File

@ -62,10 +62,22 @@ def tweets(ctx, query):
@cli.command()
@click.argument('url', required=False)
@click.argument('name_or_url', required=False)
@click.pass_context
def mentions(ctx, url):
if not url:
def mentions(ctx, name_or_url):
if name_or_url:
scheme = urlsplit(name_or_url).scheme
if not scheme: # it could be a nick
try:
config = Config.discover()
except ValueError:
pass
else:
source = config.get_source_by_nick(name_or_url)
if source:
url = source.url
url = url or name_or_url # Fallback
else:
try:
config = Config.discover()
except ValueError as e:
@ -75,6 +87,7 @@ def mentions(ctx, url):
ctx=ctx,
)
url = config.twturl
click.echo(ctx.obj.list_mentions(url).text)