You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

202 lines
8.4 KiB
Python

2 years ago
import discord, toml
from discord.ext import commands
from discord.commands import option
with open("config.toml", "r") as f:
config = toml.load(f)
guild_ids=config["bot"]["guild_ids"]
with open("cogs/essentials/config.toml", "r") as f:
esconf = toml.load(f)
2 years ago
class EssentialCommands(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.slash_command(guild_ids=guild_ids)
async def ping(self, ctx):
if not esconf["commands"]["ping"]:
await ctx.respond("This command is disabled.")
return 0
2 years ago
await ctx.respond('Pong!')
@commands.slash_command(guild_ids=guild_ids)
@option('msg', description="The message to say.")
async def say(self, ctx, message):
if not esconf["commands"]["say"]:
await ctx.respond("This command is disabled.")
return 0
2 years ago
await ctx.send(message)
@commands.slash_command(guild_ids=guild_ids)
async def serverinfo(self, ctx):
if not esconf["commands"]["serverinfo"]:
await ctx.respond("This command is disabled.")
return 0
2 years ago
await ctx.defer()
embed = discord.Embed(title=f"{ctx.guild.name} Info", colour=discord.Colour.blurple())
embed.add_field(name="Roles", value=len(ctx.guild.roles), inline=False)
embed.add_field(name="Members", value=ctx.guild.member_count, inline=False)
embed.add_field(name="Owner", value=ctx.guild.owner.mention, inline=False)
embed.add_field(name="Text Channels", value=len(ctx.guild.text_channels), inline=False)
embed.add_field(name="Voice Channels", value=len(ctx.guild.voice_channels), inline=False)
embed.add_field(name="Boost Level", value=ctx.guild.premium_tier, inline=False)
embed.add_field(name="Created", value=ctx.guild.created_at, inline=False)
embed.add_field(name="ID", value=ctx.guild.id, inline=False)
embed.add_field(name="Max File Size", value=f"{str(int(ctx.guild.filesize_limit / (1024 * 1024)))} MB", inline=False)
icon = ctx.guild.icon
embed.set_thumbnail(url=icon)
await ctx.followup.send(embed=embed)
@commands.slash_command(guild_ids=guild_ids)
@option('ammount', description="The of messages to clear.", required=True)
@commands.has_permissions(manage_messages=True)
async def clean(self, ctx, amount: int = 10):
if not esconf["commands"]["clean"]:
await ctx.respond("This command is disabled.")
return 0
2 years ago
await ctx.defer()
try:
await ctx.channel.purge(limit=amount + 1)
except:
await ctx.followup.send(f"Could not purge all of the messages.")
else:
await ctx.followup.send(f"Purged {amount} messages.")
@commands.slash_command(guild_ids=guild_ids)
@commands.has_permissions(manage_channels=True)
async def lock(self, ctx, *, reason=None):
if not esconf["commands"]["lock"]:
await ctx.respond("This command is disabled.")
return 0
2 years ago
await ctx.defer()
channel = ctx.channel
overwrite = channel.overwrites_for(ctx.guild.default_role)
overwrite.send_messages = False
await channel.set_permissions(ctx.guild.default_role, overwrite=overwrite)
embed = discord.Embed(title="Locked", description=f"Reason: {reason}")
await ctx.followup.send(embed=embed)
@commands.slash_command(guild_ids=guild_ids)
@commands.has_permissions(manage_channels=True)
async def unlock(self, ctx, *, reason=None):
if not esconf["commands"]["unlock"]:
await ctx.respond("This command is disabled.")
return 0
2 years ago
await ctx.defer()
channel = ctx.channel
overwrite = channel.overwrites_for(ctx.guild.default_role)
overwrite.send_messages = True
await channel.set_permissions(ctx.guild.default_role, overwrite=overwrite)
embed = discord.Embed(title="Unlocked", description=f"Reason: {reason}")
await ctx.followup.send(embed=embed)
@commands.slash_command(guild_ids=guild_ids)
@commands.has_permissions(manage_channels=True)
async def lockdown(self, ctx, *, reason=None):
if not esconf["commands"]["lockdown"]:
await ctx.respond("This command is disabled.")
return 0
2 years ago
await ctx.defer()
for channel in ctx.guild.channels:
if isinstance(channel, discord.TextChannel):
overwrite = channel.overwrites_for(ctx.guild.default_role)
overwrite.send_messages = False
await channel.set_permissions(ctx.guild.default_role, overwrite=overwrite)
embed = discord.Embed(title="Server Locked Down", description=f"Reason: {reason}")
await ctx.followup.send(embed=embed)
@commands.slash_command(guild_ids=guild_ids)
@commands.has_permissions(manage_channels=True)
async def unlockdown(self, ctx):
if not esconf["commands"]["unlockdown"]:
await ctx.respond("This command is disabled.")
return 0
2 years ago
await ctx.defer()
for channel in ctx.guild.channels:
if isinstance(channel, discord.TextChannel):
overwrite = channel.overwrites_for(ctx.guild.default_role)
overwrite.send_messages = None
await channel.set_permissions(ctx.guild.default_role, overwrite=overwrite)
embed = discord.Embed(title="Server Unlocked", description="All channels have been unlocked.")
await ctx.followup.send(embed=embed)
@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)
async def avatar(self, ctx, member: discord.Member):
if not esconf["commands"]["avatar"]:
await ctx.respond("This command is disabled.")
return 0
try:
avatar_url = member.avatar.url
except:
await ctx.respond(f"Unable to get {member.name}'s avatar as he probably has a default avatar.")
else:
await ctx.respond(f"{member.name}'s avatar: {avatar_url}")
@commands.slash_command(guild_ids=guild_ids)
@option('member', description="The username of the user to run the check on.")
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
roles = [role.mention for role in member.roles[1:]]
if not roles:
roles = ["None"]
embed = discord.Embed(title=f"{member.display_name}'s Info", color=member.color)
try:
embed.set_thumbnail(url=member.avatar.url)
except: pass
embed.add_field(name="Name", value=str(member), 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="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)
await ctx.send(embed=embed)
2 years ago
@commands.slash_command(guild_ids=guild_ids)
@option('title', description="The biggest text.", required=True)
@option('content', description="The actuall text to put in the embed.", required=True)
@option('footer', description="The lower text.", 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):
if not esconf["commands"]["embed"]:
await ctx.respond("This command is disabled.")
return 0
2 years ago
embed = discord.Embed(title=title, description=content)
if color:
try:
atr = getattr(discord.Color, color)
embed.color = atr()
except Exception as e:
bot.api.logger("inf", f"Command ivoked a error wrong color: {e}")
ctx.send("ERR: Invalid color.")
return 1
if footer:
embed.set_footer(text=footer)
await ctx.send(embed=embed)
2 years ago
def setup(bot):
bot.add_cog(EssentialCommands(bot))