Resolve more issues

This commit is contained in:
TheBluekr 2020-03-09 01:07:27 +01:00
parent 43740dc9fc
commit bb5f4c4cbe
No known key found for this signature in database
GPG key ID: 839D51A91C353D5A

View file

@ -8,7 +8,6 @@ import time
from redbot.core import checks, commands, Config, modlog from redbot.core import checks, commands, Config, modlog
from redbot.core.bot import Red from redbot.core.bot import Red
from redbot.core.config import Group from redbot.core.config import Group
from redbot.core.commands import Context, Cog
from redbot.core.utils.chat_formatting import pagify from redbot.core.utils.chat_formatting import pagify
from redbot.core.utils.predicates import MessagePredicate from redbot.core.utils.predicates import MessagePredicate
@ -39,10 +38,10 @@ class RoleTracker(commands.Cog):
async def register_casetypes(): async def register_casetypes():
# register mod case # register mod case
role_case = { role_case = {
"name": "Role List Update", "name": "roleupdate",
"default_setting": True, "default_setting": True,
"image": "\N{PAGE FACING UP}", "image": "\N{PAGE FACING UP}",
"case_str": "roleupdate", "case_str": "Role Update",
} }
try: try:
await modlog.register_casetype(**role_case) await modlog.register_casetype(**role_case)
@ -50,7 +49,7 @@ class RoleTracker(commands.Cog):
pass pass
# Commands # Commands
@commands.group() @commands.group(aliases=["rtrack", "roletrack"])
@commands.guild_only() @commands.guild_only()
@checks.mod_or_permissions(manage_roles=True) @checks.mod_or_permissions(manage_roles=True)
async def roletracker(self, ctx: GuildContext): async def roletracker(self, ctx: GuildContext):
@ -65,13 +64,13 @@ class RoleTracker(commands.Cog):
if not enabled: if not enabled:
if await self.config.role(role).USERS(): if await self.config.role(role).USERS():
pred = MessagePredicate.yes_or_no(ctx) pred = MessagePredicate.yes_or_no(ctx)
await ctx.send(f"Found logs for role {role}, do you want to erase them?") await ctx.maybe_send_embed(f"Found logs for role {role}, do you want to erase them?")
try: try:
await self.bot.wait_for("message", check=pred, timeout=30) await self.bot.wait_for("message", check=pred, timeout=30)
except asyncio.TimeoutError: except asyncio.TimeoutError:
return await ctx.send("Timed out.") return await ctx.send("Timed out.")
if pred.result: if pred.result:
await self.config.role(role).USERS.set({}) await self.config.role(role).USERS.set({})
await self.config.role(role).addable.set(False) await self.config.role(role).addable.set(False)
await ctx.tick() await ctx.tick()
else: else:
@ -109,16 +108,16 @@ class RoleTracker(commands.Cog):
data = await self.config.role(role).USERS() data = await self.config.role(role).USERS()
if len(ctx.message.attachments): if len(ctx.message.attachments):
attachment = ctx.message.attachments[0] attachment = ctx.message.attachments[0]
reason_message = f"{reason}. {attachment.url}" reason_message = f"{reason}\nRole: {role.mention}\n{attachment.url}"
else: else:
pred = MessagePredicate.yes_or_no(ctx)
await ctx.send(f"Couldn't find attachment, do you want to continue without adding attachment?") await ctx.send(f"Couldn't find attachment, do you want to continue without adding attachment?")
pred = MessagePredicate.yes_or_no(ctx)
try: try:
await self.bot.wait_for("message", check=pred, timeout=30) await self.bot.wait_for("message", check=pred, timeout=30)
except asyncio.TimeoutError: except asyncio.TimeoutError:
return await ctx.send("Timed out.") return await ctx.send("Timed out.")
if pred.result: if pred.result:
reason_message = f"{reason}. Missing attachment." reason_message = f"{reason}\nRole: {role.mention}\nMissing attachment"
else: else:
return await ctx.maybe_send_embed("Cancelling command.") return await ctx.maybe_send_embed("Cancelling command.")
case = await modlog.create_case( case = await modlog.create_case(
@ -170,7 +169,7 @@ class RoleTracker(commands.Cog):
case = None case = None
if case: if case:
edits = {"reason": reason} edits = {"reason": f'{case["reason"]}\nUpdate: {reason}'}
if ctx.message.author.id != case.moderator.id: if ctx.message.author.id != case.moderator.id:
edits["amended_by"] = ctx.message.author edits["amended_by"] = ctx.message.author
@ -179,7 +178,7 @@ class RoleTracker(commands.Cog):
await case.edit(edits) await case.edit(edits)
await member.remove_role(role) await member.remove_roles(role)
await self.config.role(role).USERS.set(data) await self.config.role(role).USERS.set(data)
await ctx.tick() await ctx.tick()
except discord.Forbidden: except discord.Forbidden:
@ -210,8 +209,9 @@ class RoleTracker(commands.Cog):
now_date = datetime.utcnow() now_date = datetime.utcnow()
for role in added: for role in added:
if await self.config.role(role).addable(): role_dict = await self.config.role(role).all()
data = await self.config.role(role).USERS() if role_dict["addable"] and before.id not in role_dict["USERS"].keys():
data = role_dict["USERS"]
case = await modlog.create_case( case = await modlog.create_case(
self.bot, self.bot,
@ -228,8 +228,9 @@ class RoleTracker(commands.Cog):
await self.config.role(role).USERS.set(data) await self.config.role(role).USERS.set(data)
for role in removed: for role in removed:
if await self.config.role(role).addable(): role_dict = await self.config.role(role).all()
data = await self.config.role(role).USERS() if role_dict["addable"]:
data = role_dict["USERS"]
caseno = data.pop(before.id, None) caseno = data.pop(before.id, None)
@ -241,7 +242,7 @@ class RoleTracker(commands.Cog):
case = None case = None
if case: if case:
edits = {"reason": "Role manually removed"} edits = {"reason": f'{case["reason"]}\nUpdate: Role manually removed'}
if user.id != case.moderator.id: if user.id != case.moderator.id:
edits["amended_by"] = user edits["amended_by"] = user