""" Displays versions for the bot and its dependencies """ import niobot import asyncio import tomllib from importlib.metadata import version class VersionModule(niobot.Module): @niobot.command() async def version(self, ctx: niobot.Context): """Gets the nio-bot version""" with open("Pipfile", "rb") as pipfile_fd: pipfile = tomllib.load(pipfile_fd) process = await asyncio.create_subprocess_exec( "git", "rev-parse", "--short", "HEAD", stdout=asyncio.subprocess.PIPE ) stdout, _ = await process.communicate() git_version = stdout.decode().strip() git_url = "https://git.i-am.nexus/nex/nonsensebot/src/commit/" + git_version lines = ["* Nonsensebot: [g+%s](%s)" % (git_version, git_url), ""] for dependency in pipfile["packages"].keys(): dep_version = version(dependency) lines.append( "* {0}: [{1}](https://pypi.org/p/{0})".format(dependency, dep_version) ) return await ctx.respond("\n".join(lines))