mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
Disable/enable commands, uptime fix
This commit is contained in:
parent
111ed83d89
commit
399ddeb886
@ -2,6 +2,7 @@ import discord
|
|||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from cogs.utils import checks
|
from cogs.utils import checks
|
||||||
from __main__ import set_cog, send_cmd_help, settings
|
from __main__ import set_cog, send_cmd_help, settings
|
||||||
|
from .utils.dataIO import fileIO
|
||||||
|
|
||||||
import importlib
|
import importlib
|
||||||
import traceback
|
import traceback
|
||||||
@ -43,6 +44,7 @@ class Owner:
|
|||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.setowner_lock = False
|
self.setowner_lock = False
|
||||||
|
self.disabled_commands = fileIO("data/red/disabled_commands.json", "load")
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
@checks.is_owner()
|
@checks.is_owner()
|
||||||
@ -282,6 +284,68 @@ class Owner:
|
|||||||
"""Shuts down Red"""
|
"""Shuts down Red"""
|
||||||
await self.bot.logout()
|
await self.bot.logout()
|
||||||
|
|
||||||
|
@commands.group(name="command", pass_context=True)
|
||||||
|
@checks.is_owner()
|
||||||
|
async def command_disabler(self, ctx):
|
||||||
|
if ctx.invoked_subcommand is None:
|
||||||
|
await send_cmd_help(ctx)
|
||||||
|
if self.disabled_commands:
|
||||||
|
msg = "Disabled commands:\n```xl\n"
|
||||||
|
for cmd in self.disabled_commands:
|
||||||
|
msg += "{}, ".format(cmd)
|
||||||
|
msg = msg.strip(", ")
|
||||||
|
await self.bot.whisper("{}```".format(msg))
|
||||||
|
|
||||||
|
@command_disabler.command()
|
||||||
|
async def disable(self, *, command):
|
||||||
|
comm_obj = await self.get_command(command)
|
||||||
|
if comm_obj is KeyError:
|
||||||
|
await self.bot.say("That command doesn't seem to exist.")
|
||||||
|
elif comm_obj is False:
|
||||||
|
await self.bot.say("You cannot disable the commands of the owner cog.")
|
||||||
|
else:
|
||||||
|
comm_obj.enabled = False
|
||||||
|
comm_obj.hidden = True
|
||||||
|
self.disabled_commands.append(command)
|
||||||
|
fileIO("data/red/disabled_commands.json", "save", self.disabled_commands)
|
||||||
|
await self.bot.say("Command has been disabled.")
|
||||||
|
|
||||||
|
@command_disabler.command()
|
||||||
|
async def enable(self, *, command):
|
||||||
|
if command in self.disabled_commands:
|
||||||
|
self.disabled_commands.remove(command)
|
||||||
|
fileIO("data/red/disabled_commands.json", "save", self.disabled_commands)
|
||||||
|
await self.bot.say("Command enabled.")
|
||||||
|
else:
|
||||||
|
await self.bot.say("That command is not disabled.")
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
comm_obj = await self.get_command(command)
|
||||||
|
comm_obj.enabled = True
|
||||||
|
comm_obj.hidden = False
|
||||||
|
except: # In case it was in the disabled list but not currently loaded
|
||||||
|
pass # No point in even checking what returns
|
||||||
|
|
||||||
|
async def get_command(self, command):
|
||||||
|
command = command.split()
|
||||||
|
try:
|
||||||
|
comm_obj = self.bot.commands[command[0]]
|
||||||
|
if len(command) > 1:
|
||||||
|
command.pop(0)
|
||||||
|
for cmd in command:
|
||||||
|
comm_obj = comm_obj.commands[cmd]
|
||||||
|
except KeyError:
|
||||||
|
return KeyError
|
||||||
|
if comm_obj.cog_name == "Owner":
|
||||||
|
return False
|
||||||
|
return comm_obj
|
||||||
|
|
||||||
|
async def disable_commands(self): # runs at boot
|
||||||
|
for cmd in self.disabled_commands:
|
||||||
|
cmd_obj = await self.get_command(cmd)
|
||||||
|
cmd_obj.enabled = False
|
||||||
|
cmd_obj.hidden = True
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
@checks.is_owner()
|
@checks.is_owner()
|
||||||
async def join(self, invite_url: discord.Invite=None):
|
async def join(self, invite_url: discord.Invite=None):
|
||||||
@ -448,7 +512,12 @@ class Owner:
|
|||||||
return 'Last updated: ``{}``\nCommit: ``{}``\nHash: ``{}``'.format(
|
return 'Last updated: ``{}``\nCommit: ``{}``\nHash: ``{}``'.format(
|
||||||
*version)
|
*version)
|
||||||
|
|
||||||
|
def check_files():
|
||||||
|
if not os.path.isfile("data/red/disabled_commands.json"):
|
||||||
|
print("Creating empty disabled_commands.json...")
|
||||||
|
fileIO("data/red/disabled_commands.json", "save", [])
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
|
check_files()
|
||||||
n = Owner(bot)
|
n = Owner(bot)
|
||||||
bot.add_cog(n)
|
bot.add_cog(n)
|
||||||
6
red.py
6
red.py
@ -38,7 +38,8 @@ async def on_ready():
|
|||||||
users = str(len(set(bot.get_all_members())))
|
users = str(len(set(bot.get_all_members())))
|
||||||
servers = str(len(bot.servers))
|
servers = str(len(bot.servers))
|
||||||
channels = str(len([c for c in bot.get_all_channels()]))
|
channels = str(len([c for c in bot.get_all_channels()]))
|
||||||
bot.uptime = int(time.perf_counter())
|
if not "uptime" in dir(bot): #prevents reset in case of reconnection
|
||||||
|
bot.uptime = int(time.perf_counter())
|
||||||
print('------')
|
print('------')
|
||||||
print(bot.user.name + " is now online.")
|
print(bot.user.name + " is now online.")
|
||||||
print('------')
|
print('------')
|
||||||
@ -55,6 +56,7 @@ async def on_ready():
|
|||||||
bot.oauth_url = url
|
bot.oauth_url = url
|
||||||
print(url)
|
print(url)
|
||||||
print("------")
|
print("------")
|
||||||
|
await bot.get_cog('Owner').disable_commands()
|
||||||
|
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
@ -74,6 +76,8 @@ async def on_command_error(error, ctx):
|
|||||||
await send_cmd_help(ctx)
|
await send_cmd_help(ctx)
|
||||||
elif isinstance(error, commands.BadArgument):
|
elif isinstance(error, commands.BadArgument):
|
||||||
await send_cmd_help(ctx)
|
await send_cmd_help(ctx)
|
||||||
|
elif isinstance(error, commands.DisabledCommand):
|
||||||
|
await bot.send_message(ctx.message.channel, "That command is disabled.")
|
||||||
|
|
||||||
async def send_cmd_help(ctx):
|
async def send_cmd_help(ctx):
|
||||||
if ctx.invoked_subcommand:
|
if ctx.invoked_subcommand:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user