initial commit
This commit is contained in:
commit
cfc1a0b08c
6 changed files with 561 additions and 0 deletions
54
ext/system.py
Normal file
54
ext/system.py
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import subprocess
|
||||
import asyncio
|
||||
|
||||
import lightbulb
|
||||
import hikari
|
||||
|
||||
plugin = lightbulb.Plugin("SystemPlugin")
|
||||
|
||||
async def get_git_status() -> dict:
|
||||
output = {}
|
||||
try:
|
||||
id_proc = await asyncio.create_subprocess_exec("git", "rev-parse", "--short", "HEAD",
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
br_proc = await asyncio.create_subprocess_exec("git", "rev-parse", "--abbrev-ref", "HEAD",
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
|
||||
stdout, _ = await id_proc.communicate()
|
||||
output["commit_id"] = stdout.decode("utf-8")
|
||||
|
||||
stdout, _ = await br_proc.communicate()
|
||||
output["branch"] = stdout.decode("utf-8")
|
||||
except subprocess.SubprocessError as err:
|
||||
print(err)
|
||||
return output
|
||||
|
||||
@plugin.command
|
||||
@lightbulb.command("ping", "ping the bot.", ephemeral=True)
|
||||
@lightbulb.implements(lightbulb.SlashCommand)
|
||||
async def ping(ctx: lightbulb.Context) -> None:
|
||||
embed = hikari.Embed(title="Ping!",
|
||||
description=f"latency: {round(ctx.bot.heartbeat_latency * 1000, ndigits=2)}ms"
|
||||
)
|
||||
await ctx.respond(embed)
|
||||
|
||||
@plugin.command
|
||||
@lightbulb.command("info", "get bot info", ephemeral=True)
|
||||
@lightbulb.implements(lightbulb.SlashCommand)
|
||||
async def info(ctx: lightbulb.Context) -> None:
|
||||
git_status = await get_git_status()
|
||||
embed = hikari.Embed(title="About Me!")
|
||||
embed.add_field("GitHub", "https://gitdab.com/InValidFire/radical-bot")
|
||||
embed.add_field("Version", git_status['commit_id'])
|
||||
embed.add_field("Branch", git_status['branch'])
|
||||
await ctx.respond(embed)
|
||||
|
||||
def load(bot: lightbulb.BotApp):
|
||||
bot.add_plugin(plugin)
|
||||
|
||||
def unload(bot: lightbulb.BotApp):
|
||||
bot.remove_plugin(plugin)
|
||||
Loading…
Add table
Add a link
Reference in a new issue