2019-09-12 15:43:57 +02:00
|
|
|
import datetime
|
|
|
|
|
|
|
|
import discord
|
2017-06-11 20:04:03 +02:00
|
|
|
from discord.ext import commands
|
2019-09-12 15:43:57 +02:00
|
|
|
|
2019-09-11 15:59:37 +02:00
|
|
|
from bot import TuxBot
|
2019-09-12 15:43:57 +02:00
|
|
|
from .utils.lang import Texts
|
2018-12-03 01:26:23 +01:00
|
|
|
|
2019-05-30 00:59:20 +02:00
|
|
|
|
|
|
|
class Admin(commands.Cog):
|
|
|
|
|
2019-09-11 15:59:37 +02:00
|
|
|
def __init__(self, bot: TuxBot):
|
2019-05-30 00:59:20 +02:00
|
|
|
self.bot = bot
|
|
|
|
|
2019-09-11 15:59:37 +02:00
|
|
|
async def cog_check(self, ctx: commands.Context):
|
|
|
|
permissions = ctx.channel.permissions_for(ctx.author)
|
2019-09-12 15:43:57 +02:00
|
|
|
|
|
|
|
has_permission = permissions.administrator
|
|
|
|
is_owner = await self.bot.is_owner(ctx.author)
|
|
|
|
|
|
|
|
return has_permission or is_owner
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
async def kick_ban_message(ctx: commands.Context, **kwargs) -> discord.Embed:
|
|
|
|
member: discord.Member = kwargs.get('member')
|
|
|
|
reason = kwargs.get(
|
|
|
|
'reason',
|
|
|
|
Texts('admin').get("Please enter a reason")
|
|
|
|
)
|
|
|
|
|
|
|
|
if kwargs.get('type') == 'ban':
|
|
|
|
title = '**Ban** ' + str(len(await ctx.guild.bans()))
|
|
|
|
color = discord.Color.dark_red()
|
|
|
|
else:
|
|
|
|
title = '**Kick**'
|
|
|
|
color = discord.Color.red()
|
|
|
|
e = discord.Embed(
|
|
|
|
title=title,
|
|
|
|
description=reason,
|
|
|
|
timestamp=datetime.datetime.utcnow(),
|
|
|
|
color=color
|
|
|
|
)
|
|
|
|
e.set_author(
|
|
|
|
name=f'{member.name}#{member.discriminator} ({member.id})',
|
|
|
|
icon_url=member.avatar_url_as(format='jpg')
|
|
|
|
)
|
|
|
|
e.set_footer(
|
|
|
|
text=f'{ctx.author.name}#{ctx.author.discriminator}',
|
|
|
|
icon_url=ctx.author.avatar_url_as(format='png')
|
|
|
|
)
|
|
|
|
|
|
|
|
return e
|
2019-05-30 00:59:20 +02:00
|
|
|
|
|
|
|
"""---------------------------------------------------------------------"""
|
|
|
|
|
2019-09-12 15:43:57 +02:00
|
|
|
@commands.command(name='say')
|
2019-09-11 15:59:37 +02:00
|
|
|
async def _say(self, ctx: commands.Context, *, to_say: str):
|
2019-09-12 15:43:57 +02:00
|
|
|
try:
|
|
|
|
await ctx.message.delete()
|
|
|
|
await ctx.send(to_say)
|
|
|
|
except discord.errors.Forbidden:
|
|
|
|
await ctx.send(to_say)
|
|
|
|
|
|
|
|
"""---------------------------------------------------------------------"""
|
|
|
|
|
|
|
|
@commands.command(name="ban")
|
|
|
|
async def _ban(self, ctx: commands.Context, user: discord.User, *,
|
|
|
|
reason=""):
|
|
|
|
member: discord.Member = await ctx.guild.fetch_member(user.id)
|
|
|
|
|
|
|
|
if member:
|
|
|
|
try:
|
|
|
|
await member.ban(reason=reason)
|
|
|
|
e: discord.Embed = await self.kick_ban_message(
|
|
|
|
ctx,
|
|
|
|
member=member,
|
|
|
|
type='ban',
|
|
|
|
reason=reason
|
|
|
|
)
|
|
|
|
|
|
|
|
await ctx.send(embed=e)
|
|
|
|
except discord.Forbidden:
|
|
|
|
await ctx.send(Texts('admin').get("Unable to ban this user"))
|
|
|
|
else:
|
|
|
|
await ctx.send(Texts('admin').get("Unable to find the user..."))
|
|
|
|
|
|
|
|
"""---------------------------------------------------------------------"""
|
|
|
|
|
|
|
|
@commands.command(name="kick")
|
|
|
|
async def _kick(self, ctx: commands.Context, user: discord.User, *,
|
|
|
|
reason=""):
|
|
|
|
member: discord.Member = await ctx.guild.fetch_member(user.id)
|
|
|
|
|
|
|
|
if member:
|
|
|
|
try:
|
|
|
|
await member.kick(reason=reason)
|
|
|
|
e: discord.Embed = await self.kick_ban_message(
|
|
|
|
ctx,
|
|
|
|
member=member,
|
|
|
|
type='kick',
|
|
|
|
reason=reason
|
|
|
|
)
|
|
|
|
|
|
|
|
await ctx.send(embed=e)
|
|
|
|
except discord.Forbidden:
|
|
|
|
await ctx.send(Texts('admin').get("Unable to ban this user"))
|
|
|
|
else:
|
|
|
|
await ctx.send(Texts('admin').get("Unable to find the user..."))
|
|
|
|
|
|
|
|
"""---------------------------------------------------------------------"""
|
2019-05-30 00:59:20 +02:00
|
|
|
|
2017-06-11 20:04:03 +02:00
|
|
|
|
2019-09-11 15:59:37 +02:00
|
|
|
def setup(bot: TuxBot):
|
2019-05-30 00:59:20 +02:00
|
|
|
bot.add_cog(Admin(bot))
|