|
|
|
|
|
|
|
|
"""Group of commands handling warnings""" |
|
|
"""Group of commands handling warnings""" |
|
|
if ctx.invoked_subcommand is None: |
|
|
if ctx.invoked_subcommand is None: |
|
|
return await ctx.send('Missing Argument') |
|
|
return await ctx.send('Missing Argument') |
|
|
self.settings = gs.get(ctx.guild) |
|
|
|
|
|
|
|
|
|
|
|
@warn.command() |
|
|
@warn.command() |
|
|
async def add(self, ctx, user: discord.User = None, *, warning = ""): |
|
|
async def add(self, ctx, user: discord.User = None, *, warning = ""): |
|
|
"""Adds a warning to a user.""" |
|
|
"""Adds a warning to a user.""" |
|
|
# Warning in the settings is a dictionary of user ids. The user ids are equal to a list of dictionaries. |
|
|
# Warning in the settings is a dictionary of user ids. The user ids are equal to a list of dictionaries. |
|
|
|
|
|
settings = gs.get(ctx.guild) |
|
|
warning_limit = 2 |
|
|
warning_limit = 2 |
|
|
warning_dict = { |
|
|
warning_dict = { |
|
|
"warned-by": ctx.author.id, |
|
|
"warned-by": ctx.author.id, |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
user_id = str(user.id) |
|
|
user_id = str(user.id) |
|
|
|
|
|
|
|
|
if not user_id in self.settings.warnings: |
|
|
|
|
|
self.settings.warnings[user_id] = [] |
|
|
|
|
|
|
|
|
if not user_id in settings.warnings: |
|
|
|
|
|
settings.warnings[user_id] = [] |
|
|
|
|
|
|
|
|
self.settings.warnings[user_id].append(warning_dict) |
|
|
|
|
|
self.settings.update(self.settings.warnings, "warnings") |
|
|
|
|
|
|
|
|
settings.warnings[user_id].append(warning_dict) |
|
|
|
|
|
settings.update(settings.warnings, "warnings") |
|
|
|
|
|
|
|
|
amount_warnings = len(self.settings.warnings[user_id]) |
|
|
|
|
|
|
|
|
amount_warnings = len(settings.warnings[user_id]) |
|
|
if amount_warnings > warning_limit: |
|
|
if amount_warnings > warning_limit: |
|
|
await ctx.author.send("{} has been reported {} time(s). This is a reminder that this is over the set limit of {}.".format( |
|
|
await ctx.author.send("{} has been reported {} time(s). This is a reminder that this is over the set limit of {}.".format( |
|
|
str(user), amount_warnings, warning_limit)) |
|
|
str(user), amount_warnings, warning_limit)) |
|
|
|
|
|
|
|
|
@warn.command() |
|
|
@warn.command() |
|
|
async def list(self, ctx, *, user: discord.User = None): |
|
|
async def list(self, ctx, *, user: discord.User = None): |
|
|
"""Lists all or just the warnings for one user.""" |
|
|
"""Lists all or just the warnings for one user.""" |
|
|
|
|
|
settings = gs.get(ctx.guild) |
|
|
|
|
|
|
|
|
if user == None: |
|
|
if user == None: |
|
|
output = "" |
|
|
output = "" |
|
|
for member in self.settings.warnings: |
|
|
|
|
|
|
|
|
for member in settings.warnings: |
|
|
# Remove users with no warning here instead of remove cause im lazy |
|
|
# Remove users with no warning here instead of remove cause im lazy |
|
|
if not self.settings.warnings[member]: |
|
|
|
|
|
self.settings.warnings.pop(member) |
|
|
|
|
|
|
|
|
if not settings.warnings[member]: |
|
|
|
|
|
settings.warnings.pop(member) |
|
|
else: |
|
|
else: |
|
|
member_obj = discord.utils.get(ctx.guild.members, id=int(member)) |
|
|
member_obj = discord.utils.get(ctx.guild.members, id=int(member)) |
|
|
if member_obj: |
|
|
if member_obj: |
|
|
output += "{}: {} Warning(s)\n".format(str(member_obj), len( |
|
|
output += "{}: {} Warning(s)\n".format(str(member_obj), len( |
|
|
self.settings.warnings[member])) |
|
|
|
|
|
|
|
|
settings.warnings[member])) |
|
|
else: |
|
|
else: |
|
|
output += "{}: {} Warning(s)\n".format(member, len( |
|
|
output += "{}: {} Warning(s)\n".format(member, len( |
|
|
self.settings.warnings[member])) |
|
|
|
|
|
|
|
|
settings.warnings[member])) |
|
|
return await ctx.send(output) |
|
|
return await ctx.send(output) |
|
|
|
|
|
|
|
|
user_id = str(user.id) |
|
|
user_id = str(user.id) |
|
|
|
|
|
|
|
|
if not self.settings.warnings[user_id]: |
|
|
|
|
|
self.settings.warnings.pop(user_id) |
|
|
|
|
|
self.settings.update(self.settings.warnings, "warnings") |
|
|
|
|
|
if not user_id in self.settings.warnings: |
|
|
|
|
|
|
|
|
if not settings.warnings[user_id]: |
|
|
|
|
|
settings.warnings.pop(user_id) |
|
|
|
|
|
settings.update(settings.warnings, "warnings") |
|
|
|
|
|
if not user_id in settings.warnings: |
|
|
return await ctx.send("This user doesn't have any warning on record.") |
|
|
return await ctx.send("This user doesn't have any warning on record.") |
|
|
|
|
|
|
|
|
em = discord.Embed(title="Warnings for {}".format(str(user)), colour=0XDEADBF) |
|
|
em = discord.Embed(title="Warnings for {}".format(str(user)), colour=0XDEADBF) |
|
|
em.set_thumbnail(url=user.avatar_url) |
|
|
em.set_thumbnail(url=user.avatar_url) |
|
|
x = 1 |
|
|
x = 1 |
|
|
userlist = self.settings.warnings[user.id] |
|
|
|
|
|
|
|
|
userlist = settings.warnings[user_id] |
|
|
for warning in userlist: |
|
|
for warning in userlist: |
|
|
try: |
|
|
try: |
|
|
warned_by = str(await self.bot.get_user_info(warning["warned-by"])) |
|
|
warned_by = str(await self.bot.get_user_info(warning["warned-by"])) |
|
|
except discord.ClientException: |
|
|
|
|
|
|
|
|
except discord.ext.commands.CommandInvokeError: |
|
|
warned_by = warning["warned-by"] |
|
|
warned_by = warning["warned-by"] |
|
|
date = datetime.datetime.fromtimestamp(warning["date"]).strftime('%c') |
|
|
date = datetime.datetime.fromtimestamp(warning["date"]).strftime('%c') |
|
|
warn_reason = warning["warning"] |
|
|
warn_reason = warning["warning"] |
|
|
|
|
|
|
|
|
async def remove(self, ctx, user: discord.User = None, index = None): |
|
|
async def remove(self, ctx, user: discord.User = None, index = None): |
|
|
"""Removes one or all of the warnings for a user.""" |
|
|
"""Removes one or all of the warnings for a user.""" |
|
|
user_id = str(user.id) |
|
|
user_id = str(user.id) |
|
|
|
|
|
settings = gs.get(ctx.guild) |
|
|
|
|
|
|
|
|
if index: |
|
|
if index: |
|
|
try: |
|
|
try: |
|
|
index = int(index) |
|
|
index = int(index) |
|
|
index -= 1 |
|
|
index -= 1 |
|
|
self.settings.warnings[user_id].pop(index) |
|
|
|
|
|
if not self.settings.warnings[user_id]: |
|
|
|
|
|
self.settings.warnings.pop(user_id) |
|
|
|
|
|
|
|
|
settings.warnings[user_id].pop(index) |
|
|
|
|
|
if not settings.warnings[user_id]: |
|
|
|
|
|
settings.warnings.pop(user_id) |
|
|
|
|
|
|
|
|
self.settings.update(self.settings.warnings, "warnings") |
|
|
|
|
|
|
|
|
settings.update(settings.warnings, "warnings") |
|
|
return await ctx.send("Removed Warning {} from {}".format(index+1, str(user))) |
|
|
return await ctx.send("Removed Warning {} from {}".format(index+1, str(user))) |
|
|
|
|
|
|
|
|
except Exception as e: |
|
|
except Exception as e: |
|
|
|
|
|
|
|
|
raise e |
|
|
raise e |
|
|
else: |
|
|
else: |
|
|
try: |
|
|
try: |
|
|
self.settings.warnings.pop(user.id) |
|
|
|
|
|
self.settings.update(self.settings.warnings, "warnings") |
|
|
|
|
|
|
|
|
settings.warnings.pop(user_id) |
|
|
|
|
|
settings.update(settings.warnings, "warnings") |
|
|
return await ctx.send("Removed all warnings for {}".format(str(user))) |
|
|
return await ctx.send("Removed all warnings for {}".format(str(user))) |
|
|
except KeyError: |
|
|
except KeyError: |
|
|
return await ctx.send("Could not find user in warning list.") |
|
|
return await ctx.send("Could not find user in warning list.") |