mirror of
https://github.com/brandons209/Red-bot-Cogs.git
synced 2024-05-16 02:13:18 +12:00
add disable cog, fix cost manager errors printing to console
This commit is contained in:
parent
abbb66501d
commit
ca34403f3a
15
README.md
15
README.md
|
@ -18,12 +18,15 @@ Full V2 port with most of the cog rewritten from [calebj](https://github.com/cal
|
|||
|
||||
#### Cost Manager
|
||||
Allows dynamically setting costs for any commands registered to Red. Supports setting costs on a hierarchy that follows user > role > guild. Also can set guild wide roles that can use commands for free, and overriding these for certain commands. It also sends receipts to users and edits that message as they run commands so they can track their spending.
|
||||
**Warning:** from the way its setup, it will print a custom exception message to console every time a user tries running a command but doesn't have enough money. It's the only way I figured out how to get the command to cancel before invoke, raising an exception. I am currently figuring out how to add a permission hook instead to cancel the command without needed to raise an error. Currently the hook won't process removing credits from a user.
|
||||
**Features:**
|
||||
- DM receipts will only notify the user once if it fails to send the message.
|
||||
- Follows hierarchy, checks user cost first, then role cost, then guild wide cost and guild wide free roles.
|
||||
|
||||
|
||||
#### Disable
|
||||
Disable all bot commands except for admins in a guild. Customizable error message.
|
||||
|
||||
|
||||
#### Economy Trickle
|
||||
Currently rewriting parts from [Sinbad](https://github.com/mikeshardmind/SinbadCogs). Nothing changed yet.
|
||||
|
||||
|
@ -67,7 +70,15 @@ Modified from [flapjax](https://github.com/flapjax/FlapJack-Cogs). Uses base of
|
|||
|
||||
|
||||
#### Role Management
|
||||
Modified from [Sinbad](https://github.com/mikeshardmind/SinbadCogs). Adds in subscription based roles which renew every customized interval. Also allows settings messages through DM to users who obtain a specific role (such as role info). Renames srole to selfrole and removes Red's default selfrole, and makes listing roles a bit prettier.
|
||||
Modified from [Sinbad](https://github.com/mikeshardmind/SinbadCogs).
|
||||
**Features:***
|
||||
- Adds in subscription based roles which renew every customized interval.
|
||||
- Allows settings messages through DM to users who obtain a specific role (such as role info).
|
||||
- Renames srole to selfrole and removes Red's default selfrole.
|
||||
**In progress:**
|
||||
- Makes listing roles a bit prettier.
|
||||
- Allow setting roles to automatically add on guild join.
|
||||
- Enhance exclusive roles, allow setting custom role groups where the bot enforces only one role to be on a user at a time, even if it isn't a selfrole. The bot will automatically remove the old role if a new role from the same group is added. Also lists name of role group in list command to make it clearer.
|
||||
|
||||
|
||||
#### Roleplay
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
from redbot.core.utils.chat_formatting import *
|
||||
from redbot.core import Config, checks, commands, bank
|
||||
from redbot.core.bot import Red
|
||||
import discord
|
||||
|
||||
|
||||
class PoorError(commands.CommandError):
|
||||
class PoorError(commands.CheckFailure):
|
||||
pass
|
||||
|
||||
|
||||
|
|
5
disable/__init__.py
Normal file
5
disable/__init__.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from .disable import Disable
|
||||
|
||||
|
||||
def setup(bot):
|
||||
bot.add_cog(Disable(bot))
|
73
disable/disable.py
Normal file
73
disable/disable.py
Normal file
|
@ -0,0 +1,73 @@
|
|||
from redbot.core.utils.chat_formatting import *
|
||||
from redbot.core import Config, checks, commands
|
||||
from redbot.core.utils.mod import is_admin_or_superior
|
||||
import discord
|
||||
from discord.ext.commands import DisabledCommand
|
||||
|
||||
|
||||
class DisabledError(commands.CheckFailure):
|
||||
pass
|
||||
|
||||
|
||||
DEFAULT_MSG = warning("Sorry, `{0}` is disabled! Please contact a server admin for assistance.")
|
||||
|
||||
|
||||
class Disable(commands.Cog):
|
||||
"""
|
||||
Quickly disable all commands in a guild.
|
||||
"""
|
||||
|
||||
def __init__(self, bot):
|
||||
self.config = Config.get_conf(self, identifier=768437593, force_registration=True)
|
||||
self.config.register_guild(disabled_message=DEFAULT_MSG, disabled=False)
|
||||
self.bot = bot
|
||||
self.bot.before_invoke(self.disabler)
|
||||
|
||||
def cog_unload(self):
|
||||
self.bot.remove_before_invoke_hook(self.disabler)
|
||||
|
||||
async def disabler(self, ctx):
|
||||
if await self.config.guild(ctx.guild).disabled() and not await is_admin_or_superior(self.bot, ctx.author):
|
||||
raise DisabledError(f"Command {ctx.command.name} is disabled in {ctx.guild.name}.")
|
||||
|
||||
@commands.group(name="disable")
|
||||
@commands.guild_only()
|
||||
@checks.admin()
|
||||
async def disable(self, ctx):
|
||||
"""
|
||||
Disable all commands for a bot.
|
||||
|
||||
Only admins can use commands when commands are disabled in the server.
|
||||
"""
|
||||
pass
|
||||
|
||||
@disable.command(name="toggle")
|
||||
async def disable_toggle(self, ctx):
|
||||
"""
|
||||
Toggles disabled state of commands.
|
||||
"""
|
||||
current = await self.config.guild(ctx.guild).disabled()
|
||||
current = current != True
|
||||
await self.config.guild(ctx.guild).disabled.set(current)
|
||||
await ctx.tick()
|
||||
|
||||
@disable.command(name="message")
|
||||
async def disable_message(self, ctx, *, msg: str = None):
|
||||
"""
|
||||
Change default error message.
|
||||
Use {0} to get name of command.
|
||||
Pass no message to see current message.
|
||||
"""
|
||||
if not msg:
|
||||
current = await self.config.guild(ctx.guild).disabled_message()
|
||||
await ctx.send(current)
|
||||
return
|
||||
|
||||
await self.config.guild(ctx.guild).disabled_message.set(msg)
|
||||
await ctx.tick()
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_command_error(self, ctx, exception):
|
||||
if isinstance(exception, DisabledError):
|
||||
msg = await self.config.guild(ctx.guild).disabled_message()
|
||||
await ctx.send(msg.format(ctx.command.name))
|
Loading…
Reference in a new issue