mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
[Core] Co-owners cli flag only, implemented owner cli flag
After giving it further thought, I don't believe co-owners really need to be a command, as it is unlikely that co-owners will need to be changed often enough. Furthermore, this gives a further layer of protection to people who like to gloss over warnings.
This commit is contained in:
parent
2fa5792f69
commit
be5c7f4592
@ -10,13 +10,13 @@ class Red(commands.Bot):
|
|||||||
def __init__(self, cli_flags, **kwargs):
|
def __init__(self, cli_flags, **kwargs):
|
||||||
self._shutdown_mode = ExitCodes.CRITICAL
|
self._shutdown_mode = ExitCodes.CRITICAL
|
||||||
self.db = Config.get_core_conf(force_registration=True)
|
self.db = Config.get_core_conf(force_registration=True)
|
||||||
|
self._co_owners = cli_flags.co_owner
|
||||||
|
|
||||||
self.db.register_global(
|
self.db.register_global(
|
||||||
token=None,
|
token=None,
|
||||||
prefix=[],
|
prefix=[],
|
||||||
packages=[],
|
packages=[],
|
||||||
owner=None,
|
owner=None,
|
||||||
coowners=[],
|
|
||||||
whitelist=[],
|
whitelist=[],
|
||||||
blacklist=[],
|
blacklist=[],
|
||||||
enable_sentry=None
|
enable_sentry=None
|
||||||
@ -43,6 +43,9 @@ class Red(commands.Bot):
|
|||||||
if "command_prefix" not in kwargs:
|
if "command_prefix" not in kwargs:
|
||||||
kwargs["command_prefix"] = prefix_manager
|
kwargs["command_prefix"] = prefix_manager
|
||||||
|
|
||||||
|
if cli_flags.owner and "owner_id" not in kwargs:
|
||||||
|
kwargs["owner_id"] = cli_flags.owner
|
||||||
|
|
||||||
if "owner_id" not in kwargs:
|
if "owner_id" not in kwargs:
|
||||||
kwargs["owner_id"] = self.db.get("owner")
|
kwargs["owner_id"] = self.db.get("owner")
|
||||||
|
|
||||||
@ -51,7 +54,7 @@ class Red(commands.Bot):
|
|||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
async def is_owner(self, user):
|
async def is_owner(self, user):
|
||||||
if user.id in self.db.coowners():
|
if user.id in self._co_owners:
|
||||||
return True
|
return True
|
||||||
return await super().is_owner(user)
|
return await super().is_owner(user)
|
||||||
|
|
||||||
|
|||||||
14
core/cli.py
14
core/cli.py
@ -63,9 +63,17 @@ def ask_sentry(red: Red):
|
|||||||
|
|
||||||
def parse_cli_flags():
|
def parse_cli_flags():
|
||||||
parser = argparse.ArgumentParser(description="Red - Discord Bot")
|
parser = argparse.ArgumentParser(description="Red - Discord Bot")
|
||||||
parser.add_argument("--owner", help="ID of the owner. Only who hosts "
|
parser.add_argument("--owner", type=int,
|
||||||
"Red should be owner, this has "
|
help="ID of the owner. Only who hosts "
|
||||||
"security implications")
|
"Red should be owner, this has "
|
||||||
|
"serious security implications.")
|
||||||
|
parser.add_argument("--co-owner", type=int, action="append", default=[],
|
||||||
|
help="ID of a co-owner. Only people who have access "
|
||||||
|
"to the system that is hosting Red should be "
|
||||||
|
"co-owners, as this gives them complete access "
|
||||||
|
"to the system's data. This has serious "
|
||||||
|
"security implications if misused. Can be "
|
||||||
|
"multiple.")
|
||||||
parser.add_argument("--prefix", "-p", action="append",
|
parser.add_argument("--prefix", "-p", action="append",
|
||||||
help="Global prefix. Can be multiple")
|
help="Global prefix. Can be multiple")
|
||||||
parser.add_argument("--no-prompt",
|
parser.add_argument("--no-prompt",
|
||||||
|
|||||||
@ -11,10 +11,10 @@ import asyncio
|
|||||||
|
|
||||||
log = logging.getLogger("red")
|
log = logging.getLogger("red")
|
||||||
|
|
||||||
OWNER_DISCLAIMER = ("Setting as owner people who do not have access to "
|
OWNER_DISCLAIMER = ("⚠ **Only** the person who is hosting Red should be "
|
||||||
"the system that is hosting Red is **extremely "
|
"owner. **This has SERIOUS security implications. The "
|
||||||
"dangerous**.\n**Owners and co owners are able to access "
|
"owner can access any data that is present on the host "
|
||||||
"any data that is present on the host system.**")
|
"system.** ⚠")
|
||||||
|
|
||||||
|
|
||||||
class Core:
|
class Core:
|
||||||
@ -281,38 +281,3 @@ class Core:
|
|||||||
await ctx.send("You have been set as owner.")
|
await ctx.send("You have been set as owner.")
|
||||||
else:
|
else:
|
||||||
await ctx.send("Invalid token.")
|
await ctx.send("Invalid token.")
|
||||||
|
|
||||||
@_set.command(aliases=["coowners"])
|
|
||||||
@checks.is_owner()
|
|
||||||
@commands.guild_only()
|
|
||||||
async def coowner(self, ctx, *coowners: discord.Member):
|
|
||||||
"""Sets Red's coowner(s)
|
|
||||||
|
|
||||||
Leave empty to reset"""
|
|
||||||
def check(m):
|
|
||||||
return m.author == ctx.author and m.channel == ctx.channel
|
|
||||||
|
|
||||||
coowners = [m.id for m in coowners]
|
|
||||||
|
|
||||||
if not coowners:
|
|
||||||
await ctx.bot.db.set("coowners", [])
|
|
||||||
await ctx.send("Coowners list cleared.")
|
|
||||||
return
|
|
||||||
|
|
||||||
await ctx.send("Remember:\n" + OWNER_DISCLAIMER)
|
|
||||||
await asyncio.sleep(5)
|
|
||||||
|
|
||||||
await ctx.send("Type `I understand` if you have read and understand "
|
|
||||||
"the above message.")
|
|
||||||
|
|
||||||
try:
|
|
||||||
message = await ctx.bot.wait_for("message", check=check,
|
|
||||||
timeout=60)
|
|
||||||
except asyncio.TimeoutError:
|
|
||||||
await ctx.send("The set owner request has timed out.")
|
|
||||||
else:
|
|
||||||
if message.content.lower().strip() == "i understand":
|
|
||||||
await ctx.bot.db.set("coowners", coowners)
|
|
||||||
await ctx.send("{} coowner(s) set.".format(len(coowners)))
|
|
||||||
else:
|
|
||||||
await ctx.send("Set coowner request aborted.")
|
|
||||||
Loading…
x
Reference in New Issue
Block a user