import re from discord.ext import commands from discord_slash import SlashContext, cog_ext from discord_slash.utils.manage_commands import create_option import jarvis from jarvis import config, jarvis_self, logo from jarvis.utils import build_embed, convert_bytesize, get_repo_hash from jarvis.utils.field import Field class UtilCog(commands.Cog): """ Utility functions for J.A.R.V.I.S. Mostly system utility functions, but may change over time """ def __init__(self, bot): self.bot = bot self.config = config.get_config() @cog_ext.cog_slash( name="status", description="Retrieve J.A.R.V.I.S. status", guild_ids=[578757004059738142], ) async def _status(self, ctx): title = "J.A.R.V.I.S. Status" desc = "All systems online" color = "#98CCDA" fields = [] with jarvis_self.oneshot(): fields.append(Field("CPU Usage", jarvis_self.cpu_percent())) fields.append( Field( "RAM Usage", convert_bytesize(jarvis_self.memory_info().rss), ) ) fields.append(Field("PID", jarvis_self.pid)) fields.append(Field("Version", jarvis.__version__, False)) fields.append(Field("Git Hash", get_repo_hash(), False)) embed = build_embed( title=title, description=desc, fields=fields, color=color ) await ctx.send(embed=embed) @cog_ext.cog_slash( name="logo", description="Get the current logo", guild_ids=[578757004059738142], ) async def _logo(self, ctx): lo = logo.get_logo(self.config.logo) await ctx.send(f"```\n{lo}\n```") @cog_ext.cog_slash( name="rcauto", description="Automates robot camo letters", guild_ids=[578757004059738142], options=[ create_option( name="text", description="Text to camo-ify", option_type=3, required=True, ) ], ) async def _rcauto(self, ctx: SlashContext, text: str): lookup = { "-": ":rcDash:", "(": ":rcPL:", ")": ":rc:", "$": ":rcDS:", "@": ":rcAt:", "!": ":rcEx:", "?": ":rcQm:", "^": ":rcThis:", "'": ":rcApost:", "#": ":rcHash:", ".": ":rcDot:", } to_send = "" for letter in text.upper(): if letter == " ": to_send += " " elif re.match(r"^[A-Z0-9]$", letter): to_send += f":rc{letter}:" elif re.match(r"^[-()$@!?^'#.]$", letter): to_send += lookup[letter] await ctx.send(to_send) def setup(bot): bot.add_cog(UtilCog(bot))