Plugin: refactor the first half of 'contributors [nick]'

This commit is contained in:
James Lu 2019-10-19 11:09:55 -07:00
parent 65e3e18fe2
commit 672652d780
1 changed files with 22 additions and 29 deletions

View File

@ -1,5 +1,6 @@
### ###
# Copyright (c) 2005, Jeremiah Fincher # Copyright (c) 2005, Jeremiah Fincher
# Copyright (c) 2019, James Lu <james@overdrivenetworks.com>
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@ -183,28 +184,24 @@ class Plugin(callbacks.Plugin):
def buildPersonString(module): def buildPersonString(module):
""" """
Build the list of contributions (if any) for the requested person Build the list of contributions (if any) for the requested person
for the requested plugin for the requested plugin.
""" """
isAuthor = False contributors = getattr(module, '__contributors__', {})
authorInfo = None # Make a mapping of nicks to author instances
moduleContribs = module.__contributors__.keys() contributorNicks = dict((author.nick.lower(), author) for author in contributors.keys())
lnick = nick.lower() lnick = nick.lower()
for contrib in moduleContribs:
if contrib.nick.lower() == lnick: author = getattr(module, '__author__', None)
authorInfo = contrib if author and lnick == author.nick.lower():
break # Special case for the plugin author. We remove legacy handling of the case where
authorInfo = authorInfo or getattr(supybot.authors, nick, None) # someone is listed both as author and contributor, which should never really happen?
if not authorInfo: return _('%s wrote the %s plugin.') % (author, cb.name())
return _('The nick specified (%s) is not a registered ' elif lnick not in contributorNicks:
'contributor.') % nick return _('%s is not listed as a contributor to %s.') % (nick, cb.name())
fullName = str(authorInfo)
contributions = [] authorInfo = contributorNicks[lnick]
if hasattr(module, '__contributors__'): contributions = contributors[authorInfo]
if authorInfo not in module.__contributors__:
return _('The %s plugin does not have \'%s\' listed as a '
'contributor.') % (cb.name(), nick)
contributions = module.__contributors__[authorInfo]
isAuthor = getattr(module, '__author__', False) == authorInfo
(nonCommands, commands) = utils.iter.partition(lambda s: ' ' in s, (nonCommands, commands) = utils.iter.partition(lambda s: ' ' in s,
contributions) contributions)
results = [] results = []
@ -215,19 +212,15 @@ class Plugin(callbacks.Plugin):
results.append(format(_('the %L %s'), commands, s)) results.append(format(_('the %L %s'), commands, s))
if nonCommands: if nonCommands:
results.append(format(_('the %L'), nonCommands)) results.append(format(_('the %L'), nonCommands))
if results and isAuthor:
return format( fullName = getShortName(authorInfo)
_('%s wrote the %s plugin and also contributed %L.'), if results:
(fullName, cb.name(), results))
elif results and not isAuthor:
return format(_('%s contributed %L to the %s plugin.'), return format(_('%s contributed %L to the %s plugin.'),
fullName, results, cb.name()) fullName, results, cb.name())
elif isAuthor and not results:
return _('%s wrote the %s plugin') % (fullName, cb.name())
# XXX Does this ever actually get reached?
else: else:
return _('%s has no listed contributions for the %s ' return _('%s has no specific listed contributions to the %s '
'plugin.') % (fullName, cb.name()) 'plugin.') % (fullName, cb.name())
# First we need to check and see if the requested plugin is loaded # First we need to check and see if the requested plugin is loaded
module = cb.classModule module = cb.classModule
if not nick: if not nick: