nonsensebot/app/modules/version.py

31 lines
1 KiB
Python
Raw Normal View History

2024-09-12 20:18:57 +01:00
"""
Displays versions for the bot and its dependencies
"""
2024-09-15 23:03:24 +01:00
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(
2024-09-15 23:03:24 +01:00
"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(
2024-09-15 23:03:24 +01:00
"* {0}: [{1}](https://pypi.org/p/{0})".format(dependency, dep_version)
)
return await ctx.respond("\n".join(lines))