v0.4.0, implements hybrid slash commands (mostly...), simplifies dev cog, closes #2
This commit is contained in:
parent
17f2d32f60
commit
f61a8fceba
8 changed files with 275 additions and 137 deletions
|
@ -2,13 +2,12 @@ from pathlib import Path
|
||||||
from discord import Intents
|
from discord import Intents
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from discord.utils import find
|
from discord.utils import find
|
||||||
|
from discord_slash import SlashCommand
|
||||||
from psutil import Process
|
from psutil import Process
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
from jarvis.config import get_config
|
from jarvis.config import get_config
|
||||||
from jarvis import utils, logo
|
from jarvis import utils, logo
|
||||||
|
|
||||||
|
|
||||||
if asyncio.get_event_loop().is_closed():
|
if asyncio.get_event_loop().is_closed():
|
||||||
asyncio.set_event_loop(asyncio.new_event_loop())
|
asyncio.set_event_loop(asyncio.new_event_loop())
|
||||||
|
|
||||||
|
@ -18,8 +17,9 @@ restart_ctx = None
|
||||||
|
|
||||||
|
|
||||||
jarvis = commands.Bot(command_prefix=utils.get_prefix, intents=intents)
|
jarvis = commands.Bot(command_prefix=utils.get_prefix, intents=intents)
|
||||||
|
slash = SlashCommand(jarvis, sync_commands=True, sync_on_cog_reload=True)
|
||||||
jarvis_self = Process()
|
jarvis_self = Process()
|
||||||
__version__ = "0.3.0"
|
__version__ = "0.4.0"
|
||||||
|
|
||||||
|
|
||||||
@jarvis.event
|
@jarvis.event
|
||||||
|
@ -70,7 +70,9 @@ def run(ctx=None):
|
||||||
config = get_config()
|
config = get_config()
|
||||||
print(
|
print(
|
||||||
" https://discord.com/api/oauth2/authorize?client_id="
|
" https://discord.com/api/oauth2/authorize?client_id="
|
||||||
+ "{}&permissions=8&scope=bot".format(config.client_id)
|
+ "{}&permissions=8&scope=bot%20applications.commands".format(
|
||||||
|
config.client_id
|
||||||
|
)
|
||||||
)
|
)
|
||||||
jarvis.run(config.token, bot=True, reconnect=True)
|
jarvis.run(config.token, bot=True, reconnect=True)
|
||||||
for cog in jarvis.cogs:
|
for cog in jarvis.cogs:
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import jarvis
|
import jarvis
|
||||||
from discord import User
|
from discord import User
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
from discord_slash import cog_ext, SlashContext
|
||||||
from jarvis.utils.db import DBManager
|
from jarvis.utils.db import DBManager
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,9 +17,7 @@ class AdminCog(commands.Cog):
|
||||||
config = jarvis.config.get_config()
|
config = jarvis.config.get_config()
|
||||||
self.db = DBManager(config.mongo)
|
self.db = DBManager(config.mongo)
|
||||||
|
|
||||||
@commands.command(name="ban")
|
async def _ban(self, ctx: SlashContext, user: User = None, reason=None):
|
||||||
@commands.has_permissions(ban_members=True)
|
|
||||||
async def _ban(self, ctx, user: User = None, reason=None):
|
|
||||||
if not user or user == ctx.message.author:
|
if not user or user == ctx.message.author:
|
||||||
await ctx.send("You cannot ban yourself.")
|
await ctx.send("You cannot ban yourself.")
|
||||||
if not reason:
|
if not reason:
|
||||||
|
@ -35,8 +34,18 @@ class AdminCog(commands.Cog):
|
||||||
+ f"Reason:\n{reason}"
|
+ f"Reason:\n{reason}"
|
||||||
)
|
)
|
||||||
|
|
||||||
@commands.command(name="kick")
|
@cog_ext.cog_slash(
|
||||||
@commands.has_permissions(kick_members=True)
|
name="ban", description="Ban a user", guild_ids=[578757004059738142]
|
||||||
|
)
|
||||||
|
@commands.has_permissions(ban_members=True)
|
||||||
|
async def _ban_slash(self, ctx, user: User = None, reason=None):
|
||||||
|
await self._ban(ctx, user, reason)
|
||||||
|
|
||||||
|
@commands.command(name="ban")
|
||||||
|
@commands.has_permissions(ban_members=True)
|
||||||
|
async def _ban_pref(self, ctx, user: User = None, reason=None):
|
||||||
|
await self._ban(ctx, user, reason)
|
||||||
|
|
||||||
async def _kick(self, ctx, user: User = None, reason=None):
|
async def _kick(self, ctx, user: User = None, reason=None):
|
||||||
if not user or user == ctx.message.author:
|
if not user or user == ctx.message.author:
|
||||||
await ctx.send("You cannot kick yourself.")
|
await ctx.send("You cannot kick yourself.")
|
||||||
|
@ -45,15 +54,30 @@ class AdminCog(commands.Cog):
|
||||||
"Mr. Stark is displeased with your presence. Please leave."
|
"Mr. Stark is displeased with your presence. Please leave."
|
||||||
)
|
)
|
||||||
guild_name = ctx.message.guild.name
|
guild_name = ctx.message.guild.name
|
||||||
|
try:
|
||||||
await user.send(
|
await user.send(
|
||||||
f"You have been kicked from {guild_name}. Reason:\n{reason}"
|
f"You have been kicked from {guild_name}. Reason:\n{reason}"
|
||||||
)
|
)
|
||||||
|
except Exception:
|
||||||
|
await ctx.send("Unable to message user.")
|
||||||
await ctx.guild.kick(user, reason=reason)
|
await ctx.guild.kick(user, reason=reason)
|
||||||
await ctx.send(
|
await ctx.send(
|
||||||
f"{user.name} has been kicked from {guild_name}."
|
f"{user.name} has been kicked from {guild_name}."
|
||||||
+ f"Reason:\n{reason}"
|
+ f"Reason:\n{reason}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@commands.command(name="kick")
|
||||||
|
@commands.has_permissions(kick_members=True)
|
||||||
|
async def _kick_pref(self, ctx, user: User = None, reason=None):
|
||||||
|
await self._kick(ctx, user, reason)
|
||||||
|
|
||||||
|
@cog_ext.cog_slash(
|
||||||
|
name="kick", description="Kick a user", guild_ids=[578757004059738142]
|
||||||
|
)
|
||||||
|
@commands.has_permissions(kick_members=True)
|
||||||
|
async def _kick_slash(self, ctx, user: User = None, reason=None):
|
||||||
|
await self._kick(ctx, user, reason)
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot.add_cog(AdminCog(bot))
|
bot.add_cog(AdminCog(bot))
|
||||||
|
|
|
@ -7,6 +7,7 @@ from jarvis.utils import build_embed
|
||||||
from jarvis.utils.field import Field
|
from jarvis.utils.field import Field
|
||||||
from jarvis.data.dbrand import shipping_lookup
|
from jarvis.data.dbrand import shipping_lookup
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
from discord_slash import cog_ext, SlashContext
|
||||||
|
|
||||||
|
|
||||||
class DbrandCog(commands.Cog):
|
class DbrandCog(commands.Cog):
|
||||||
|
@ -24,32 +25,47 @@ class DbrandCog(commands.Cog):
|
||||||
self.api_url = get_config().urls["dbrand_shipping"]
|
self.api_url = get_config().urls["dbrand_shipping"]
|
||||||
self.cache = {}
|
self.cache = {}
|
||||||
|
|
||||||
@commands.group(name="db", aliases=["dbrand"], pass_context=True)
|
# @cog_ext.cog_slash(name="db", aliases=["dbrand"], pass_context=True)
|
||||||
async def _db(self, ctx):
|
# async def _db(self, ctx):
|
||||||
if ctx.invoked_subcommand is None:
|
# if ctx.invoked_subcommand is None:
|
||||||
await ctx.send(
|
# await ctx.send(
|
||||||
"Available subcommands: `grip`, `support`, "
|
# "Available subcommands: `grip`, `support`, "
|
||||||
+ "`skin`, `prism`, `shipping`, `camo`"
|
# + "`skin`, `prism`, `shipping`, `camo`"
|
||||||
)
|
# )
|
||||||
|
|
||||||
@_db.command(name="skin", aliases=["skins", "tape"])
|
@cog_ext.cog_subcommand(
|
||||||
|
base="db", name="skin", guild_ids=[578757004059738142]
|
||||||
|
)
|
||||||
async def _skin(self, ctx):
|
async def _skin(self, ctx):
|
||||||
await ctx.send(self.base_url + "shop/skins")
|
await ctx.send(self.base_url + "shop/skins")
|
||||||
|
|
||||||
@_db.command(name="robotcamo", aliases=["rc", "robot", "camo"])
|
# @_db.command(name="robotcamo", aliases=["rc", "robot", "camo"])
|
||||||
|
@cog_ext.cog_subcommand(
|
||||||
|
base="db", name="robotcamo", guild_ids=[578757004059738142]
|
||||||
|
)
|
||||||
async def _camo(self, ctx):
|
async def _camo(self, ctx):
|
||||||
await ctx.send(self.base_url + "shop/special-edition/robot-camo")
|
await ctx.send(self.base_url + "shop/special-edition/robot-camo")
|
||||||
|
|
||||||
@_db.command(name="grip", aliases=["g", "case"])
|
# @_db.command(name="grip", aliases=["g", "case"])
|
||||||
|
@cog_ext.cog_subcommand(
|
||||||
|
base="db", name="grip", guild_ids=[578757004059738142]
|
||||||
|
)
|
||||||
async def _grip(self, ctx):
|
async def _grip(self, ctx):
|
||||||
await ctx.send(self.base_url + "shop/grip/#grip-devices")
|
await ctx.send(self.base_url + "shop/grip/#grip-devices")
|
||||||
|
|
||||||
@_db.command(name="support", aliases=["help", "contact"])
|
# @_db.command(name="support", aliases=["help", "contact"])
|
||||||
|
@cog_ext.cog_subcommand(
|
||||||
|
base="db", name="contact", guild_ids=[578757004059738142]
|
||||||
|
)
|
||||||
async def _support(self, ctx):
|
async def _support(self, ctx):
|
||||||
await ctx.send(self.base_url + "contact")
|
await ctx.send(self.base_url + "contact")
|
||||||
|
|
||||||
@_db.command(name="shipping", aliases=["ship", "s"])
|
# @_db.command(name="shipping", aliases=["ship", "s"])
|
||||||
|
@cog_ext.cog_subcommand(
|
||||||
|
base="db", name="ship", guild_ids=[578757004059738142]
|
||||||
|
)
|
||||||
async def _shipping(self, ctx, *, search: str):
|
async def _shipping(self, ctx, *, search: str):
|
||||||
|
await ctx.defer()
|
||||||
if not re.match(r"^[A-Z- ]+$", search, re.IGNORECASE):
|
if not re.match(r"^[A-Z- ]+$", search, re.IGNORECASE):
|
||||||
if re.match(
|
if re.match(
|
||||||
r"^[\U0001f1e6-\U0001f1ff]{2}$",
|
r"^[\U0001f1e6-\U0001f1ff]{2}$",
|
||||||
|
|
|
@ -12,6 +12,7 @@ import traceback
|
||||||
from time import time
|
from time import time
|
||||||
from inspect import getsource
|
from inspect import getsource
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
from discord_slash import cog_ext
|
||||||
from jarvis.utils import build_embed, convert_bytesize
|
from jarvis.utils import build_embed, convert_bytesize
|
||||||
from jarvis.utils.field import Field
|
from jarvis.utils.field import Field
|
||||||
from bson import ObjectId
|
from bson import ObjectId
|
||||||
|
@ -70,7 +71,6 @@ class DevCog(commands.Cog):
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
@commands.command(name="hash")
|
|
||||||
async def _hash(self, ctx, method: str, *, data: str = None):
|
async def _hash(self, ctx, method: str, *, data: str = None):
|
||||||
if method not in supported_hashes:
|
if method not in supported_hashes:
|
||||||
algo_txt = ", ".join(f"`{x}`" for x in supported_hashes)
|
algo_txt = ", ".join(f"`{x}`" for x in supported_hashes)
|
||||||
|
@ -104,7 +104,18 @@ class DevCog(commands.Cog):
|
||||||
)
|
)
|
||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
|
|
||||||
@commands.command(name="uuid")
|
@commands.command(name="hash")
|
||||||
|
async def _hash_pref(self, ctx, method: str, *, data: str = None):
|
||||||
|
await self._hash(ctx, method, data=data)
|
||||||
|
|
||||||
|
@cog_ext.cog_slash(
|
||||||
|
name="hash",
|
||||||
|
description="Hash some data",
|
||||||
|
guild_ids=[578757004059738142],
|
||||||
|
)
|
||||||
|
async def _hash_slash(self, ctx, method: str, *, data: str = None):
|
||||||
|
await self._hash(ctx, method, data=data)
|
||||||
|
|
||||||
async def _uuid(self, ctx, version: str = None, data: str = None):
|
async def _uuid(self, ctx, version: str = None, data: str = None):
|
||||||
if not version:
|
if not version:
|
||||||
await ctx.send("Supported UUID versions: 3, 4, 5")
|
await ctx.send("Supported UUID versions: 3, 4, 5")
|
||||||
|
@ -130,17 +141,50 @@ class DevCog(commands.Cog):
|
||||||
to_send = UUID_GET[version](uuid.NAMESPACE_DNS, data)
|
to_send = UUID_GET[version](uuid.NAMESPACE_DNS, data)
|
||||||
await ctx.send(f"UUID{version}: `{to_send}`")
|
await ctx.send(f"UUID{version}: `{to_send}`")
|
||||||
|
|
||||||
@commands.command(name="objectid")
|
@commands.command(name="uuid")
|
||||||
async def _objectid(self, ctx: commands.Context):
|
async def _uuid_pref(self, ctx, version: str = None, data: str = None):
|
||||||
|
await self._uuid(ctx, version, data)
|
||||||
|
|
||||||
|
@cog_ext.cog_slash(
|
||||||
|
name="uuid",
|
||||||
|
description="Generate a UUID",
|
||||||
|
guild_ids=[578757004059738142],
|
||||||
|
)
|
||||||
|
async def _uuid_slash(self, ctx, version: str = None, data: str = None):
|
||||||
|
await self._uuid(ctx, version, data)
|
||||||
|
|
||||||
|
async def _objectid(self, ctx):
|
||||||
"""Generates new bson.ObjectId"""
|
"""Generates new bson.ObjectId"""
|
||||||
await ctx.send(f"ObjectId: `{str(ObjectId())}`")
|
await ctx.send(f"ObjectId: `{str(ObjectId())}`")
|
||||||
|
|
||||||
@commands.command(name="ulid")
|
@commands.command(name="objectid")
|
||||||
async def _ulid(self, ctx: commands.Context):
|
async def _objectid_pref(self, ctx):
|
||||||
|
await self._objectid(ctx)
|
||||||
|
|
||||||
|
@cog_ext.cog_slash(
|
||||||
|
name="objectid",
|
||||||
|
description="Generate an ObjectID",
|
||||||
|
guild_ids=[578757004059738142],
|
||||||
|
)
|
||||||
|
async def _objectid_slash(self, ctx):
|
||||||
|
await self._objectid(ctx)
|
||||||
|
|
||||||
|
async def _ulid(self, ctx):
|
||||||
"""Generates a new ULID"""
|
"""Generates a new ULID"""
|
||||||
await ctx.send(f"ULID: `{ulid.new().str}`")
|
await ctx.send(f"ULID: `{ulid.new().str}`")
|
||||||
|
|
||||||
@commands.command(name="uuid2ulid")
|
@commands.command(name="ulid")
|
||||||
|
async def _ulid_pref(self, ctx):
|
||||||
|
await self._ulid(ctx)
|
||||||
|
|
||||||
|
@cog_ext.cog_slash(
|
||||||
|
name="ulid",
|
||||||
|
description="Generate a ULID",
|
||||||
|
guild_ids=[578757004059738142],
|
||||||
|
)
|
||||||
|
async def _ulid_slash(self, ctx):
|
||||||
|
await self._ulid(ctx)
|
||||||
|
|
||||||
async def _uuid2ulid(self, ctx: commands.Context, u):
|
async def _uuid2ulid(self, ctx: commands.Context, u):
|
||||||
"""Converts a UUID to a ULID"""
|
"""Converts a UUID to a ULID"""
|
||||||
if UUID_VERIFY.match(u):
|
if UUID_VERIFY.match(u):
|
||||||
|
@ -149,7 +193,18 @@ class DevCog(commands.Cog):
|
||||||
else:
|
else:
|
||||||
await ctx.send("Invalid UUID")
|
await ctx.send("Invalid UUID")
|
||||||
|
|
||||||
@commands.command(name="ulid2uuid")
|
@commands.command(name="uuid2ulid")
|
||||||
|
async def _uuid2ulid_pref(self, ctx, u: str):
|
||||||
|
await self._uuid2ulid(ctx, u)
|
||||||
|
|
||||||
|
@cog_ext.cog_slash(
|
||||||
|
name="uuid2ulid",
|
||||||
|
description="Convert a UUID to a ULID",
|
||||||
|
guild_ids=[578757004059738142],
|
||||||
|
)
|
||||||
|
async def _uuid2ulid_slash(self, ctx, u: str):
|
||||||
|
await self._uuid2ulid(ctx, u)
|
||||||
|
|
||||||
async def _ulid2uuid(self, ctx: commands.Context, u):
|
async def _ulid2uuid(self, ctx: commands.Context, u):
|
||||||
"""Converts a ULID to a UUID"""
|
"""Converts a ULID to a UUID"""
|
||||||
if ULID_VERIFY.match(u):
|
if ULID_VERIFY.match(u):
|
||||||
|
@ -158,91 +213,83 @@ class DevCog(commands.Cog):
|
||||||
else:
|
else:
|
||||||
await ctx.send("Invalid ULID.")
|
await ctx.send("Invalid ULID.")
|
||||||
|
|
||||||
@commands.group(name="encode")
|
@commands.command(name="ulid2uuid")
|
||||||
async def _encode(self, ctx):
|
async def _ulid2uuid_pref(self, ctx, u):
|
||||||
|
await self._ulid2uuid(ctx, u)
|
||||||
|
|
||||||
|
@cog_ext.cog_slash(
|
||||||
|
name="ulid2uuid",
|
||||||
|
description="Convert a ULID to a UUID",
|
||||||
|
guild_ids=[578757004059738142],
|
||||||
|
)
|
||||||
|
async def _ulid2uuid_slash(self, ctx, u):
|
||||||
|
await self._ulid2uuid(ctx, u)
|
||||||
|
|
||||||
|
base64_methods = ["b64", "b16", "b32", "a85", "b85"]
|
||||||
|
|
||||||
|
async def _encode(self, ctx, method: str, data: str):
|
||||||
"""Encodes text with specified encoding method"""
|
"""Encodes text with specified encoding method"""
|
||||||
if ctx.invoked_subcommand is None:
|
if method not in self.base64_methods:
|
||||||
await ctx.send("Usage: encode <method> <data>")
|
methods = ", ".join(f"`{x}`" for x in self.base64_methods)
|
||||||
|
|
||||||
@_encode.command(name="b64")
|
|
||||||
async def _b64e(self, ctx, *, data: str):
|
|
||||||
"""Base64 encoding"""
|
|
||||||
await ctx.send(base64.b64encode(data.encode("UTF-8")).decode("UTF-8"))
|
|
||||||
|
|
||||||
@_encode.command(name="b16")
|
|
||||||
async def _b16e(self, ctx, *, data: str):
|
|
||||||
"""Base16 encoding"""
|
|
||||||
await ctx.send(
|
await ctx.send(
|
||||||
"`" + base64.b16encode(data.encode("UTF-8")).decode("UTF-8") + "`"
|
"Usage: encode <method> <data>\nSupported methods:\n" + methods
|
||||||
)
|
)
|
||||||
|
return
|
||||||
|
method = getattr(base64, method + "encode")
|
||||||
|
await ctx.send(f"`{method(data.encode('UTF-8')).decode('UTF-8')}`")
|
||||||
|
|
||||||
@_encode.command(name="b32")
|
@commands.command(name="encode")
|
||||||
async def _b32e(self, ctx, *, data: str):
|
async def _encode_pref(self, ctx, method: str, *, data: str):
|
||||||
"""Base32 encoding"""
|
await self._encode(ctx, method, data)
|
||||||
await ctx.send(
|
|
||||||
"`" + base64.b32encode(data.encode("UTF-8")).decode("UTF-8") + "`"
|
@cog_ext.cog_slash(
|
||||||
|
name="encode",
|
||||||
|
description="Encode using the base64 module",
|
||||||
|
guild_ids=[578757004059738142],
|
||||||
)
|
)
|
||||||
|
async def _encode_slash(self, ctx, method: str, *, data: str):
|
||||||
|
await self._encode(ctx, method, data)
|
||||||
|
|
||||||
@_encode.command(name="a85")
|
async def _decode(self, ctx, method: str, data: str):
|
||||||
async def _a85e(self, ctx, *, data: str):
|
|
||||||
"""ASCII85 encoding"""
|
|
||||||
await ctx.send(
|
|
||||||
"`" + base64.a85encode(data.encode("UTF-8")).decode("UTF-8") + "`"
|
|
||||||
)
|
|
||||||
|
|
||||||
@_encode.command(name="b85")
|
|
||||||
async def _b85e(self, ctx, *, data: str):
|
|
||||||
"""Base85 encoding"""
|
|
||||||
await ctx.send(
|
|
||||||
"`" + base64.b85encode(data.encode("UTF-8")).decode("UTF-8") + "`"
|
|
||||||
)
|
|
||||||
|
|
||||||
@commands.group(name="decode")
|
|
||||||
async def _decode(self, ctx):
|
|
||||||
"""Decodes text with specified encoding method"""
|
"""Decodes text with specified encoding method"""
|
||||||
if ctx.invoked_subcommand is None:
|
if method not in self.base64_methods:
|
||||||
await ctx.send("Usage: decode <method> <data>")
|
methods = ", ".join(f"`{x}`" for x in self.base64_methods)
|
||||||
|
|
||||||
@_decode.command(name="b64")
|
|
||||||
async def _b64d(self, ctx, *, data: str):
|
|
||||||
"""Base64 decoding"""
|
|
||||||
await ctx.send(
|
await ctx.send(
|
||||||
"`" + base64.b64decode(data.encode("UTF-8")).decode("UTF-8") + "`"
|
"Usage: decode <method> <data>\nSupported methods:\n" + methods
|
||||||
)
|
)
|
||||||
|
return
|
||||||
|
method = getattr(base64, method + "decode")
|
||||||
|
await ctx.send(f"`{method(data.encode('UTF-8')).decode('UTF-8')}`")
|
||||||
|
|
||||||
@_decode.command(name="b16")
|
@commands.command(name="decode")
|
||||||
async def _b16d(self, ctx, *, data: str):
|
async def _decode_pref(self, ctx, method: str, *, data: str):
|
||||||
"""Base16 decoding"""
|
await self._decode(ctx, method, data)
|
||||||
await ctx.send(
|
|
||||||
"`" + base64.b16decode(data.encode("UTF-8")).decode("UTF-8") + "`"
|
@cog_ext.cog_slash(
|
||||||
|
name="decode",
|
||||||
|
description="Decode using the base64 module",
|
||||||
|
guild_ids=[578757004059738142],
|
||||||
)
|
)
|
||||||
|
async def _decode_slash(self, ctx, method: str, *, data: str):
|
||||||
|
await self._decode(ctx, method, data)
|
||||||
|
|
||||||
@_decode.command(name="b32")
|
|
||||||
async def _b32d(self, ctx, *, data: str):
|
|
||||||
"""Base32 decoding"""
|
|
||||||
await ctx.send(
|
|
||||||
"`" + base64.b32decode(data.encode("UTF-8")).decode("UTF-8") + "`"
|
|
||||||
)
|
|
||||||
|
|
||||||
@_decode.command(name="a85")
|
|
||||||
async def _a85d(self, ctx, *, data: str):
|
|
||||||
"""ASCII85 decoding"""
|
|
||||||
await ctx.send(
|
|
||||||
"`" + base64.a85decode(data.encode("UTF-8")).decode("UTF-8") + "`"
|
|
||||||
)
|
|
||||||
|
|
||||||
@_decode.command(name="b85")
|
|
||||||
async def _b85d(self, ctx, *, data: str):
|
|
||||||
"""Base85 decoding"""
|
|
||||||
await ctx.send(
|
|
||||||
"`" + base64.b85decode(data.encode("UTF-8")).decode("UTF-8") + "`"
|
|
||||||
)
|
|
||||||
|
|
||||||
@commands.command(name="cloc", help="Get J.A.R.V.I.S. lines of code")
|
|
||||||
async def _cloc(self, ctx):
|
async def _cloc(self, ctx):
|
||||||
output = subprocess.check_output(["cloc", "."]).decode("UTF-8")
|
output = subprocess.check_output(["cloc", "."]).decode("UTF-8")
|
||||||
await ctx.send(f"```\n{output}\n```")
|
await ctx.send(f"```\n{output}\n```")
|
||||||
|
|
||||||
|
@commands.command(name="cloc", help="Get J.A.R.V.I.S. lines of code")
|
||||||
|
async def _cloc_pref(self, ctx):
|
||||||
|
await self._cloc(ctx)
|
||||||
|
|
||||||
|
@cog_ext.cog_slash(
|
||||||
|
name="cloc",
|
||||||
|
description="Get J.A.R.V.I.S. lines of code",
|
||||||
|
guild_ids=[578757004059738142],
|
||||||
|
)
|
||||||
|
async def _cloc_slash(self, ctx):
|
||||||
|
await ctx.defer()
|
||||||
|
await self._cloc(ctx)
|
||||||
|
|
||||||
def resolve_variable(self, variable):
|
def resolve_variable(self, variable):
|
||||||
if hasattr(variable, "__iter__"):
|
if hasattr(variable, "__iter__"):
|
||||||
var_length = len(list(variable))
|
var_length = len(list(variable))
|
||||||
|
|
|
@ -17,6 +17,17 @@ class ErrorHandlerCog(commands.Cog):
|
||||||
else:
|
else:
|
||||||
await ctx.send(f"Error processing command:\n```{error}```")
|
await ctx.send(f"Error processing command:\n```{error}```")
|
||||||
|
|
||||||
|
@commands.Cog.listener()
|
||||||
|
async def on_slash_command_error(self, ctx, error):
|
||||||
|
if isinstance(error, commands.errors.MissingPermissions):
|
||||||
|
await ctx.send("I'm afraid I can't let you do that.")
|
||||||
|
elif isinstance(error, commands.errors.CommandNotFound):
|
||||||
|
await ctx.send(
|
||||||
|
"Command does not exist. Run `>help` to get a list of commands"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
await ctx.send(f"Error processing command:\n```{error}```")
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot.add_cog(ErrorHandlerCog(bot))
|
bot.add_cog(ErrorHandlerCog(bot))
|
||||||
|
|
|
@ -24,7 +24,6 @@ class ImageCog(commands.Cog):
|
||||||
r"([0-9]*\.?[0-9]*?) ?([KMGTP]?B)", re.IGNORECASE
|
r"([0-9]*\.?[0-9]*?) ?([KMGTP]?B)", re.IGNORECASE
|
||||||
)
|
)
|
||||||
|
|
||||||
@commands.command(name="resize", help="Resize an image")
|
|
||||||
async def _resize(self, ctx, target: str, url: str = None):
|
async def _resize(self, ctx, target: str, url: str = None):
|
||||||
if not target:
|
if not target:
|
||||||
await ctx.send("Missing target size, i.e. 200KB.")
|
await ctx.send("Missing target size, i.e. 200KB.")
|
||||||
|
@ -103,6 +102,10 @@ class ImageCog(commands.Cog):
|
||||||
file=File(bufio, filename="resized.png"),
|
file=File(bufio, filename="resized.png"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@commands.command(name="resize", help="Resize an image")
|
||||||
|
async def _resize_pref(self, ctx, target: str, url: str = None):
|
||||||
|
await self._resize(ctx, target, url)
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot.add_cog(ImageCog(bot))
|
bot.add_cog(ImageCog(bot))
|
||||||
|
|
|
@ -8,6 +8,7 @@ from jarvis.utils import build_embed
|
||||||
from jarvis.utils.db import DBManager
|
from jarvis.utils.db import DBManager
|
||||||
from jarvis.utils.field import Field
|
from jarvis.utils.field import Field
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
from discord_slash import cog_ext
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,7 +25,6 @@ class JokeCog(commands.Cog):
|
||||||
self.db = DBManager(config.mongo)
|
self.db = DBManager(config.mongo)
|
||||||
|
|
||||||
# TODO: Make this a command group with subcommands
|
# TODO: Make this a command group with subcommands
|
||||||
@commands.command(name="joke", help="Hear a joke")
|
|
||||||
async def _joke(self, ctx, id: str = None):
|
async def _joke(self, ctx, id: str = None):
|
||||||
try:
|
try:
|
||||||
if randint(1, 100_000) == 5779 and id is None:
|
if randint(1, 100_000) == 5779 and id is None:
|
||||||
|
@ -108,6 +108,16 @@ class JokeCog(commands.Cog):
|
||||||
)
|
)
|
||||||
# await ctx.send(f"**{result['title']}**\n\n{result['body']}")
|
# await ctx.send(f"**{result['title']}**\n\n{result['body']}")
|
||||||
|
|
||||||
|
@commands.command(name="joke", help="Hear a joke")
|
||||||
|
async def _joke_pref(self, ctx, id: str = None):
|
||||||
|
await self._joke(ctx, id)
|
||||||
|
|
||||||
|
@cog_ext.cog_slash(
|
||||||
|
name="joke", description="Hear a joke", guild_ids=[578757004059738142]
|
||||||
|
)
|
||||||
|
async def _joke_slash(self, ctx, id: str = None):
|
||||||
|
await self._joke(ctx, id)
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot.add_cog(JokeCog(bot))
|
bot.add_cog(JokeCog(bot))
|
||||||
|
|
|
@ -3,6 +3,7 @@ from jarvis import jarvis_self, config, logo
|
||||||
from jarvis.utils import convert_bytesize, build_embed, get_repo_hash
|
from jarvis.utils import convert_bytesize, build_embed, get_repo_hash
|
||||||
from jarvis.utils.field import Field
|
from jarvis.utils.field import Field
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
from discord_slash import cog_ext, SlashContext
|
||||||
|
|
||||||
|
|
||||||
class UtilCog(commands.Cog):
|
class UtilCog(commands.Cog):
|
||||||
|
@ -16,7 +17,6 @@ class UtilCog(commands.Cog):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.config = config.get_config()
|
self.config = config.get_config()
|
||||||
|
|
||||||
@commands.command(name="status", help="Retrieve J.A.R.V.I.S. status")
|
|
||||||
async def _status(self, ctx):
|
async def _status(self, ctx):
|
||||||
title = "J.A.R.V.I.S. Status"
|
title = "J.A.R.V.I.S. Status"
|
||||||
desc = "All systems online"
|
desc = "All systems online"
|
||||||
|
@ -38,11 +38,36 @@ class UtilCog(commands.Cog):
|
||||||
)
|
)
|
||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
|
|
||||||
@commands.command(name="logo", help="Get the current logo")
|
@cog_ext.cog_slash(
|
||||||
|
name="status",
|
||||||
|
description="Retrieve J.A.R.V.I.S. status",
|
||||||
|
guild_ids=[578757004059738142],
|
||||||
|
)
|
||||||
|
async def _status_slash(self, ctx):
|
||||||
|
await self._status(ctx)
|
||||||
|
|
||||||
|
@commands.command(
|
||||||
|
name="status", description="Retrieve J.A.R.V.I.S. status"
|
||||||
|
)
|
||||||
|
async def _status_pre(self, ctx):
|
||||||
|
await self._status(ctx)
|
||||||
|
|
||||||
async def _logo(self, ctx):
|
async def _logo(self, ctx):
|
||||||
lo = logo.get_logo(self.config.logo)
|
lo = logo.get_logo(self.config.logo)
|
||||||
await ctx.send(f"```\n{lo}\n```")
|
await ctx.send(f"```\n{lo}\n```")
|
||||||
|
|
||||||
|
@commands.command(name="logo", help="Get the current logo")
|
||||||
|
async def _logo_pre(self, ctx):
|
||||||
|
await self._logo(ctx)
|
||||||
|
|
||||||
|
@cog_ext.cog_slash(
|
||||||
|
name="logo",
|
||||||
|
description="Retrieve J.A.R.V.I.S. status",
|
||||||
|
guild_ids=[578757004059738142],
|
||||||
|
)
|
||||||
|
async def _logo_slash(self, ctx):
|
||||||
|
await self._logo(ctx)
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot.add_cog(UtilCog(bot))
|
bot.add_cog(UtilCog(bot))
|
||||||
|
|
Loading…
Add table
Reference in a new issue