mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-24 03:33:11 +01:00
Plugin: accept author name in 'contributors' command
This commit is contained in:
parent
7854db7135
commit
a4701b258c
@ -139,26 +139,19 @@ class Plugin(callbacks.Plugin):
|
||||
|
||||
@internationalizeDocstring
|
||||
def contributors(self, irc, msg, args, cb, nick):
|
||||
"""<plugin> [<nick>]
|
||||
"""<plugin> [<name>]
|
||||
|
||||
Replies with a list of people who made contributions to a given plugin.
|
||||
If <nick> is specified, that person's specific contributions will
|
||||
be listed. Note: The <nick> is the part inside of the parentheses
|
||||
in the people listing.
|
||||
If <name> is specified, that person's specific contributions will
|
||||
be listed. You can specify a person's name by their full name or their nick,
|
||||
which is shown inside brackets if available.
|
||||
"""
|
||||
def getShortName(authorInfo):
|
||||
"""
|
||||
Take an Authors object, and return only the name and nick values
|
||||
in the format 'First Last (nick)'.
|
||||
"""
|
||||
return '%(name)s (%(nick)s)' % authorInfo.__dict__
|
||||
|
||||
def buildContributorsString(longList):
|
||||
"""
|
||||
Take a list of long names and turn it into :
|
||||
shortname[, shortname and shortname].
|
||||
"""
|
||||
L = [getShortName(n) for n in longList]
|
||||
L = [authorInfo.format(short=True) for authorInfo in longList]
|
||||
return format('%L', L)
|
||||
|
||||
def buildPeopleString(module):
|
||||
@ -187,12 +180,18 @@ class Plugin(callbacks.Plugin):
|
||||
for the requested plugin.
|
||||
"""
|
||||
contributors = getattr(module, '__contributors__', {})
|
||||
# Make a mapping of nicks to author instances
|
||||
contributorNicks = dict((author.nick.lower(), author) for author in contributors.keys())
|
||||
# Make a mapping of nicks and names to author instances
|
||||
contributorNicks = {}
|
||||
for contributor in contributors.keys():
|
||||
if contributor.nick:
|
||||
contributorNicks[contributor.nick.lower()] = contributor
|
||||
if contributor.name:
|
||||
contributorNicks[contributor.name.lower()] = contributor
|
||||
lnick = nick.lower()
|
||||
|
||||
author = getattr(module, '__author__', supybot.authors.unknown)
|
||||
if author != supybot.authors.unknown and lnick == author.nick.lower():
|
||||
if author != supybot.authors.unknown and \
|
||||
(lnick == (author.name or '').lower() or lnick == (author.nick or '').lower()):
|
||||
# Special case for the plugin author. We remove legacy handling of the case where
|
||||
# someone is listed both as author and contributor, which should never really happen?
|
||||
return _('%s wrote the %s plugin.') % (author, cb.name())
|
||||
@ -201,7 +200,7 @@ class Plugin(callbacks.Plugin):
|
||||
|
||||
authorInfo = contributorNicks[lnick]
|
||||
contributions = contributors[authorInfo]
|
||||
fullName = getShortName(authorInfo)
|
||||
fullName = authorInfo.format(short=True)
|
||||
|
||||
if contributions:
|
||||
return format(_('%s contributed the following to %s: %s'),
|
||||
@ -217,7 +216,7 @@ class Plugin(callbacks.Plugin):
|
||||
else:
|
||||
nick = ircutils.toLower(nick)
|
||||
irc.reply(buildPersonString(module))
|
||||
contributors = wrap(contributors, ['plugin', additional('nick')])
|
||||
contributors = wrap(contributors, ['plugin', additional('text')])
|
||||
Plugin = internationalizeDocstring(Plugin)
|
||||
|
||||
Class = Plugin
|
||||
|
@ -54,6 +54,12 @@ class PluginTestCase(PluginTestCase):
|
||||
# Test ability to list contributions
|
||||
# As of 2019-10-19 there is no more distinction between commands and non-commands
|
||||
self.assertRegexp('contributors Plugin skorobeus', 'original contributors command')
|
||||
self.assertRegexp('contributors Plugin Kevin Murphy', 'original contributors command')
|
||||
self.assertRegexp('contributors Plugin James Lu', 'refactored contributors command')
|
||||
|
||||
# Test handling of the plugin author, who is usually not listed in __contributors__
|
||||
self.assertRegexp('contributors Plugin jemfinch', 'wrote the Plugin plugin')
|
||||
self.assertRegexp('contributors Plugin Jeremy Fincher', 'wrote the Plugin plugin')
|
||||
|
||||
# TODO: test handling of a person with multiple contributions to a command
|
||||
|
||||
|
@ -50,7 +50,7 @@ class Author(object):
|
||||
self.nick = nick
|
||||
self.email = email
|
||||
|
||||
def __str__(self):
|
||||
def format(self, short=False):
|
||||
# If only one of these are defined, take the nick as the name
|
||||
name = self.name or self.nick or 'Unknown author'
|
||||
|
||||
@ -58,11 +58,14 @@ class Author(object):
|
||||
if self.nick and name != self.nick:
|
||||
# Format as "Name (nick)" if both are given and different
|
||||
s += ' (%s)' % self.nick
|
||||
if self.email:
|
||||
if self.email and not short:
|
||||
# Add "Name (nick) <email>" or "Name <email>" if provided
|
||||
s += ' <%s>' % self.email
|
||||
return s
|
||||
|
||||
def __str__(self):
|
||||
return self.format()
|
||||
|
||||
class authors(object): # This is basically a bag.
|
||||
jemfinch = Author('Jeremy Fincher', 'jemfinch', 'jemfinch@users.sf.net')
|
||||
jamessan = Author('James McCoy', 'jamessan', 'vega.james@gmail.com')
|
||||
|
@ -54,4 +54,10 @@ class MiscTestCase(SupyTestCase):
|
||||
# Only email?
|
||||
self.assertEqual(str(supybot.Author(email='xyzzy@localhost.localdomain')), 'Unknown author <xyzzy@localhost.localdomain>')
|
||||
|
||||
def testAuthorExpandShort(self):
|
||||
self.assertEqual(supybot.authors.progval.format(short=True),
|
||||
'Valentin Lorentz (ProgVal)')
|
||||
self.assertEqual(supybot.authors.jlu.format(short=True),
|
||||
'James Lu')
|
||||
|
||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||
|
Loading…
Reference in New Issue
Block a user