Skip to content

Commit 1be8bbe

Browse files
committed
version: allow retreiving plugin versions
1 parent 9550d9d commit 1be8bbe

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

sopel/modules/version.py

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,43 @@ def git_info():
3333

3434

3535
@plugin.command('version')
36+
@plugin.example('.version')
37+
@plugin.example('.version url')
3638
@plugin.output_prefix('[version] ')
3739
def version(bot, trigger):
38-
"""Display the installed version of Sopel.
40+
"""Display the installed version of Sopel or a plugin.
3941
4042
Includes the version of Python Sopel is installed on.
4143
Includes the commit hash if Sopel is installed from source.
4244
"""
43-
parts = [
44-
'Sopel v%s' % release,
45-
'Python: %s' % platform.python_version()
46-
]
47-
sha = git_info()
48-
if sha:
49-
parts.append('Commit: %s' % sha)
50-
51-
bot.say(' | '.join(parts))
45+
plugin = trigger.group(3)
46+
if not plugin or plugin.lower() == "sopel":
47+
# Sopel version
48+
parts = [
49+
'Sopel v%s' % release,
50+
'Python: %s' % platform.python_version()
51+
]
52+
sha = git_info()
53+
if sha:
54+
parts.append('Commit: %s' % sha)
55+
56+
bot.say(' | '.join(parts))
57+
58+
else:
59+
# Plugin version
60+
if not bot.has_plugin(plugin):
61+
bot.say("I don't have a plugin named %r loaded." % plugin)
62+
return
63+
64+
meta = bot.get_plugin_meta(plugin)
65+
if meta["source"].startswith("sopel."):
66+
version = "v" + release + " (built in)"
67+
elif meta["version"] is None:
68+
version = "(version unknown)"
69+
else:
70+
version = "v" + meta["version"]
71+
72+
bot.say("{} {}".format(plugin, version))
5273

5374

5475
@plugin.ctcp('VERSION')

0 commit comments

Comments
 (0)