More admin functions, implement bot admins
This commit is contained in:
parent
e797671ad8
commit
7f297185c0
6 changed files with 50 additions and 10 deletions
|
@ -1,11 +1,6 @@
|
||||||
---
|
---
|
||||||
token: api key here
|
token: api key here
|
||||||
client_id: 123456789012345678
|
client_id: 123456789012345678
|
||||||
admins:
|
|
||||||
- list
|
|
||||||
- of
|
|
||||||
- user
|
|
||||||
- ids
|
|
||||||
logo: alligator2
|
logo: alligator2
|
||||||
mongo:
|
mongo:
|
||||||
username: user
|
username: user
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
from discord import User
|
from discord import User
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
from jarvis.utils.db import DBManager
|
||||||
|
from jarvis.utils import user_is_bot_admin
|
||||||
|
|
||||||
|
|
||||||
class AdminCog(commands.Cog):
|
class AdminCog(commands.Cog):
|
||||||
|
@ -11,6 +13,7 @@ class AdminCog(commands.Cog):
|
||||||
|
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
self.db = DBManager()
|
||||||
|
|
||||||
@commands.command(name="ban")
|
@commands.command(name="ban")
|
||||||
@commands.has_permissions(administrator=True)
|
@commands.has_permissions(administrator=True)
|
||||||
|
@ -21,12 +24,32 @@ class AdminCog(commands.Cog):
|
||||||
reason = (
|
reason = (
|
||||||
"Mr. Stark is displeased with your presence. Please leave."
|
"Mr. Stark is displeased with your presence. Please leave."
|
||||||
)
|
)
|
||||||
|
guild_name = ctx.message.guild.name
|
||||||
await user.send(
|
await user.send(
|
||||||
f"You have been banned from Stark Industries. Reason:\n{reason}"
|
f"You have been banned from {guild_name}. Reason:\n{reason}"
|
||||||
)
|
)
|
||||||
await ctx.guild.ban(user, reason=reason)
|
await ctx.guild.ban(user, reason=reason)
|
||||||
await ctx.send(
|
await ctx.send(
|
||||||
f"{user.name} has been banned from Stark Industries."
|
f"{user.name} has been banned from {guild_name}."
|
||||||
|
+ f"Reason:\n{reason}"
|
||||||
|
)
|
||||||
|
|
||||||
|
@commands.command(name="kick")
|
||||||
|
@commands.has_permissions(administrator=True)
|
||||||
|
async def _kick(self, ctx, user: User = None, reason=None):
|
||||||
|
if not user or user == ctx.message.author:
|
||||||
|
await ctx.send("You cannot kick yourself.")
|
||||||
|
if not reason:
|
||||||
|
reason = (
|
||||||
|
"Mr. Stark is displeased with your presence. Please leave."
|
||||||
|
)
|
||||||
|
guild_name = ctx.message.guild.name
|
||||||
|
await user.send(
|
||||||
|
f"You have been kicked from {guild_name}. Reason:\n{reason}"
|
||||||
|
)
|
||||||
|
await ctx.guild.kick(user, reason=reason)
|
||||||
|
await ctx.send(
|
||||||
|
f"{user.name} has been banned from {guild_name}."
|
||||||
+ f"Reason:\n{reason}"
|
+ f"Reason:\n{reason}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ from discord.ext import commands
|
||||||
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
|
||||||
|
from jarvis.utils import user_is_bot_admin
|
||||||
|
|
||||||
|
|
||||||
supported_hashes = {
|
supported_hashes = {
|
||||||
|
@ -270,7 +271,7 @@ class DevCog(commands.Cog):
|
||||||
return "".join(f"\n\t{i}" for i in arr)
|
return "".join(f"\n\t{i}" for i in arr)
|
||||||
|
|
||||||
@commands.command(pass_context=True, aliases=["eval", "exec", "evaluate"])
|
@commands.command(pass_context=True, aliases=["eval", "exec", "evaluate"])
|
||||||
@commands.is_owner()
|
@commands.check(user_is_bot_admin)
|
||||||
async def _eval(self, ctx, *, code: str):
|
async def _eval(self, ctx, *, code: str):
|
||||||
code = self.prepare(code)
|
code = self.prepare(code)
|
||||||
args = {
|
args = {
|
||||||
|
@ -294,7 +295,7 @@ class DevCog(commands.Cog):
|
||||||
await ctx.send(
|
await ctx.send(
|
||||||
f"```py\n{self.resolve_variable(response)}````{type(response).__name__} | {(time() - a) / 1000} ms`"
|
f"```py\n{self.resolve_variable(response)}````{type(response).__name__} | {(time() - a) / 1000} ms`"
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
await ctx.send(f"Error occurred:```\n{traceback.format_exc()}```")
|
await ctx.send(f"Error occurred:```\n{traceback.format_exc()}```")
|
||||||
|
|
||||||
del args, code
|
del args, code
|
||||||
|
|
|
@ -2,7 +2,7 @@ import jarvis
|
||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from jarvis.config import get_config
|
from jarvis.config import get_config
|
||||||
from jarvis.utils import update
|
from jarvis.utils import update, user_is_bot_admin
|
||||||
|
|
||||||
|
|
||||||
class OwnerCog(commands.Cog):
|
class OwnerCog(commands.Cog):
|
||||||
|
@ -17,6 +17,7 @@ class OwnerCog(commands.Cog):
|
||||||
self.admins = get_config().admins
|
self.admins = get_config().admins
|
||||||
|
|
||||||
@commands.command(name="load", hidden=True)
|
@commands.command(name="load", hidden=True)
|
||||||
|
@commands.check(user_is_bot_admin)
|
||||||
async def _load_cog(self, ctx, *, cog: str):
|
async def _load_cog(self, ctx, *, cog: str):
|
||||||
info = await self.bot.application_info()
|
info = await self.bot.application_info()
|
||||||
if (
|
if (
|
||||||
|
@ -35,6 +36,7 @@ class OwnerCog(commands.Cog):
|
||||||
await ctx.send("I'm afraid I can't let you do that")
|
await ctx.send("I'm afraid I can't let you do that")
|
||||||
|
|
||||||
@commands.command(name="unload", hidden=True)
|
@commands.command(name="unload", hidden=True)
|
||||||
|
@commands.check(user_is_bot_admin)
|
||||||
async def _unload_cog(self, ctx, *, cog: str):
|
async def _unload_cog(self, ctx, *, cog: str):
|
||||||
if cog == "jarvis.cogs.owner":
|
if cog == "jarvis.cogs.owner":
|
||||||
await ctx.send("Cannot unload `owner` cog")
|
await ctx.send("Cannot unload `owner` cog")
|
||||||
|
@ -56,6 +58,7 @@ class OwnerCog(commands.Cog):
|
||||||
await ctx.send("I'm afraid I can't let you do that")
|
await ctx.send("I'm afraid I can't let you do that")
|
||||||
|
|
||||||
@commands.command(name="reload", hidden=True)
|
@commands.command(name="reload", hidden=True)
|
||||||
|
@commands.check(user_is_bot_admin)
|
||||||
async def _cog_reload(self, ctx, *, cog: str):
|
async def _cog_reload(self, ctx, *, cog: str):
|
||||||
if cog == "jarvis.cogs.owner":
|
if cog == "jarvis.cogs.owner":
|
||||||
await ctx.send("Cannot reload `owner` cog")
|
await ctx.send("Cannot reload `owner` cog")
|
||||||
|
@ -78,6 +81,7 @@ class OwnerCog(commands.Cog):
|
||||||
await ctx.send("I'm afraid I can't let you do that")
|
await ctx.send("I'm afraid I can't let you do that")
|
||||||
|
|
||||||
@commands.group(name="system", hidden=True, pass_context=True)
|
@commands.group(name="system", hidden=True, pass_context=True)
|
||||||
|
@commands.check(user_is_bot_admin)
|
||||||
async def _system(self, ctx):
|
async def _system(self, ctx):
|
||||||
if ctx.invoked_subcommand is None:
|
if ctx.invoked_subcommand is None:
|
||||||
await ctx.send(
|
await ctx.send(
|
||||||
|
@ -86,6 +90,7 @@ class OwnerCog(commands.Cog):
|
||||||
)
|
)
|
||||||
|
|
||||||
@_system.command(name="restart", hidden=True)
|
@_system.command(name="restart", hidden=True)
|
||||||
|
@commands.check(user_is_bot_admin)
|
||||||
async def _restart(self, ctx):
|
async def _restart(self, ctx):
|
||||||
info = await self.bot.application_info()
|
info = await self.bot.application_info()
|
||||||
if (
|
if (
|
||||||
|
@ -108,6 +113,7 @@ class OwnerCog(commands.Cog):
|
||||||
await ctx.send("I'm afraid I can't let you do that")
|
await ctx.send("I'm afraid I can't let you do that")
|
||||||
|
|
||||||
@_system.command(name="update", hidden=True)
|
@_system.command(name="update", hidden=True)
|
||||||
|
@commands.check(user_is_bot_admin)
|
||||||
async def _update(self, ctx):
|
async def _update(self, ctx):
|
||||||
info = await self.bot.application_info()
|
info = await self.bot.application_info()
|
||||||
if (
|
if (
|
||||||
|
@ -138,6 +144,11 @@ class OwnerCog(commands.Cog):
|
||||||
else:
|
else:
|
||||||
await ctx.send("I'm afraid I can't let you do that")
|
await ctx.send("I'm afraid I can't let you do that")
|
||||||
|
|
||||||
|
@commands.Cog.listener()
|
||||||
|
async def on_command_error(self, ctx, error):
|
||||||
|
if isinstance(error, commands.errors.MissingPermissions):
|
||||||
|
await ctx.send("I'm afraid I can't let you do that.")
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot.add_cog(OwnerCog(bot))
|
bot.add_cog(OwnerCog(bot))
|
||||||
|
|
|
@ -42,3 +42,8 @@ def get_config(path: str = "config.yaml") -> Config:
|
||||||
raw = f.read()
|
raw = f.read()
|
||||||
y = load(raw, Loader=Loader)
|
y = load(raw, Loader=Loader)
|
||||||
return Config.from_yaml(y)
|
return Config.from_yaml(y)
|
||||||
|
|
||||||
|
|
||||||
|
def reload_config():
|
||||||
|
if "it" in Config.__dict__:
|
||||||
|
Config.__dict__.pop("it")
|
||||||
|
|
|
@ -4,6 +4,7 @@ from pkgutil import iter_modules
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import jarvis.cogs
|
import jarvis.cogs
|
||||||
import jarvis.utils.db
|
import jarvis.utils.db
|
||||||
|
import jarvis.config
|
||||||
import git
|
import git
|
||||||
|
|
||||||
__all__ = ["field", "db"]
|
__all__ = ["field", "db"]
|
||||||
|
@ -85,3 +86,7 @@ def update():
|
||||||
def get_repo_hash():
|
def get_repo_hash():
|
||||||
repo = git.Repo(".")
|
repo = git.Repo(".")
|
||||||
return repo.head.object.hexsha
|
return repo.head.object.hexsha
|
||||||
|
|
||||||
|
|
||||||
|
def user_is_bot_admin(ctx):
|
||||||
|
return ctx.author.id in jarvis.config.get_config().admins
|
||||||
|
|
Loading…
Add table
Reference in a new issue