I added the option to disable/enable commands in the config.toml

main
supopur 2 years ago
parent 814085c496
commit 6a33d8a6a2

@ -7,21 +7,34 @@ with open("config.toml", "r") as f:
config = toml.load(f) config = toml.load(f)
guild_ids=config["bot"]["guild_ids"] guild_ids=config["bot"]["guild_ids"]
with open("cogs/essentials/config.toml", "r") as f:
esconf = toml.load(f)
class EssentialCommands(commands.Cog): class EssentialCommands(commands.Cog):
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
@commands.slash_command(guild_ids=guild_ids) @commands.slash_command(guild_ids=guild_ids)
async def ping(self, ctx): async def ping(self, ctx):
if not esconf["commands"]["ping"]:
await ctx.respond("This command is disabled.")
return 0
await ctx.respond('Pong!') await ctx.respond('Pong!')
@commands.slash_command(guild_ids=guild_ids) @commands.slash_command(guild_ids=guild_ids)
@option('msg', description="The message to say.") @option('msg', description="The message to say.")
async def say(self, ctx, message): async def say(self, ctx, message):
if not esconf["commands"]["say"]:
await ctx.respond("This command is disabled.")
return 0
await ctx.send(message) await ctx.send(message)
@commands.slash_command(guild_ids=guild_ids) @commands.slash_command(guild_ids=guild_ids)
async def serverinfo(self, ctx): async def serverinfo(self, ctx):
if not esconf["commands"]["serverinfo"]:
await ctx.respond("This command is disabled.")
return 0
await ctx.defer() await ctx.defer()
@ -45,6 +58,9 @@ class EssentialCommands(commands.Cog):
@option('ammount', description="The of messages to clear.", required=True) @option('ammount', description="The of messages to clear.", required=True)
@commands.has_permissions(manage_messages=True) @commands.has_permissions(manage_messages=True)
async def clean(self, ctx, amount: int = 10): async def clean(self, ctx, amount: int = 10):
if not esconf["commands"]["clean"]:
await ctx.respond("This command is disabled.")
return 0
await ctx.defer() await ctx.defer()
try: try:
await ctx.channel.purge(limit=amount + 1) await ctx.channel.purge(limit=amount + 1)
@ -56,6 +72,9 @@ class EssentialCommands(commands.Cog):
@commands.slash_command(guild_ids=guild_ids) @commands.slash_command(guild_ids=guild_ids)
@commands.has_permissions(manage_channels=True) @commands.has_permissions(manage_channels=True)
async def lock(self, ctx, *, reason=None): async def lock(self, ctx, *, reason=None):
if not esconf["commands"]["lock"]:
await ctx.respond("This command is disabled.")
return 0
await ctx.defer() await ctx.defer()
channel = ctx.channel channel = ctx.channel
overwrite = channel.overwrites_for(ctx.guild.default_role) overwrite = channel.overwrites_for(ctx.guild.default_role)
@ -68,6 +87,9 @@ class EssentialCommands(commands.Cog):
@commands.slash_command(guild_ids=guild_ids) @commands.slash_command(guild_ids=guild_ids)
@commands.has_permissions(manage_channels=True) @commands.has_permissions(manage_channels=True)
async def unlock(self, ctx, *, reason=None): async def unlock(self, ctx, *, reason=None):
if not esconf["commands"]["unlock"]:
await ctx.respond("This command is disabled.")
return 0
await ctx.defer() await ctx.defer()
channel = ctx.channel channel = ctx.channel
overwrite = channel.overwrites_for(ctx.guild.default_role) overwrite = channel.overwrites_for(ctx.guild.default_role)
@ -80,6 +102,9 @@ class EssentialCommands(commands.Cog):
@commands.slash_command(guild_ids=guild_ids) @commands.slash_command(guild_ids=guild_ids)
@commands.has_permissions(manage_channels=True) @commands.has_permissions(manage_channels=True)
async def lockdown(self, ctx, *, reason=None): async def lockdown(self, ctx, *, reason=None):
if not esconf["commands"]["lockdown"]:
await ctx.respond("This command is disabled.")
return 0
await ctx.defer() await ctx.defer()
for channel in ctx.guild.channels: for channel in ctx.guild.channels:
if isinstance(channel, discord.TextChannel): if isinstance(channel, discord.TextChannel):
@ -93,6 +118,9 @@ class EssentialCommands(commands.Cog):
@commands.slash_command(guild_ids=guild_ids) @commands.slash_command(guild_ids=guild_ids)
@commands.has_permissions(manage_channels=True) @commands.has_permissions(manage_channels=True)
async def unlockdown(self, ctx): async def unlockdown(self, ctx):
if not esconf["commands"]["unlockdown"]:
await ctx.respond("This command is disabled.")
return 0
await ctx.defer() await ctx.defer()
for channel in ctx.guild.channels: for channel in ctx.guild.channels:
if isinstance(channel, discord.TextChannel): if isinstance(channel, discord.TextChannel):
@ -107,6 +135,9 @@ class EssentialCommands(commands.Cog):
@commands.slash_command(guild_ids=guild_ids) @commands.slash_command(guild_ids=guild_ids)
@option('user', description="The username of the user you want the avatars picture incl 1234 numbers", required=True) @option('user', description="The username of the user you want the avatars picture incl 1234 numbers", required=True)
async def avatar(self, ctx, member: discord.Member): async def avatar(self, ctx, member: discord.Member):
if not esconf["commands"]["avatar"]:
await ctx.respond("This command is disabled.")
return 0
try: try:
avatar_url = member.avatar.url avatar_url = member.avatar.url
except: except:
@ -118,6 +149,9 @@ class EssentialCommands(commands.Cog):
@commands.slash_command(guild_ids=guild_ids) @commands.slash_command(guild_ids=guild_ids)
@option('member', description="The username of the user to run the check on.") @option('member', description="The username of the user to run the check on.")
async def whois(self, ctx, member: discord.Member = None): async def whois(self, ctx, member: discord.Member = None):
if not esconf["commands"]["whois"]:
await ctx.respond("This command is disabled.")
return 0
member = member or ctx.author member = member or ctx.author
roles = [role.mention for role in member.roles[1:]] roles = [role.mention for role in member.roles[1:]]
if not roles: if not roles:
@ -130,6 +164,8 @@ class EssentialCommands(commands.Cog):
embed.add_field(name="ID", value=member.id, inline=False) embed.add_field(name="ID", value=member.id, inline=False)
embed.add_field(name="Account Created", value=member.created_at.strftime("%d/%m/%Y %H:%M:%S"), inline=False) embed.add_field(name="Account Created", value=member.created_at.strftime("%d/%m/%Y %H:%M:%S"), inline=False)
embed.add_field(name="Join Date", value=member.joined_at.strftime("%d/%m/%Y %H:%M:%S"), inline=False) embed.add_field(name="Join Date", value=member.joined_at.strftime("%d/%m/%Y %H:%M:%S"), inline=False)
if not member.activity == None:
embed.add_field(name="Activity", value=member.activity, inline=False)
embed.add_field(name="Roles", value=" ".join(roles), inline=False) embed.add_field(name="Roles", value=" ".join(roles), inline=False)
await ctx.send(embed=embed) await ctx.send(embed=embed)
@ -140,6 +176,9 @@ class EssentialCommands(commands.Cog):
@option('footer', description="The lower text.", required=False) @option('footer', description="The lower text.", required=False)
@option('color', description="The color as a word example: Color: dark_blue", required=False) @option('color', description="The color as a word example: Color: dark_blue", required=False)
async def embed(self, ctx, title: str, content: str, color: str = None, footer: str = None): async def embed(self, ctx, title: str, content: str, color: str = None, footer: str = None):
if not esconf["commands"]["embed"]:
await ctx.respond("This command is disabled.")
return 0
embed = discord.Embed(title=title, description=content) embed = discord.Embed(title=title, description=content)
if color: if color:

@ -0,0 +1,16 @@
[cli]
enabled = true
[commands]
ping = true
say = true
serverinfo = true
avatar = true
whois = true
embed = true
clean = true
lock = true
unlock = true
lockdown = true
unlockdown = true
Loading…
Cancel
Save