Skip to content

Commit

Permalink
Finish auditlog cache impl
Browse files Browse the repository at this point in the history
  • Loading branch information
hypergonial committed Feb 7, 2023
1 parent b7a4a87 commit 2826684
Show file tree
Hide file tree
Showing 21 changed files with 53 additions and 104 deletions.
2 changes: 0 additions & 2 deletions extensions/automod.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ async def punish(
offender: t.Optional[hikari.Member] = None,
original_action: t.Optional[AutomodActionType] = None,
) -> None:

required_perms = (
hikari.Permissions.BAN_MEMBERS
| hikari.Permissions.MODERATE_MEMBERS
Expand Down Expand Up @@ -235,7 +234,6 @@ async def punish(
)

elif state == AutoModState.TIMEOUT.value:

embed = await automod.app.mod.timeout(
offender,
me,
Expand Down
1 change: 0 additions & 1 deletion extensions/command_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ async def application_error_handler(ctx: SnedContext, error: BaseException) -> N
return

if isinstance(error, lightbulb.CommandInvocationError):

if isinstance(error.original, asyncio.TimeoutError):
await ctx.respond(
embed=hikari.Embed(
Expand Down
2 changes: 0 additions & 2 deletions extensions/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ async def unload_cmd(ctx: SnedPrefixContext, extension_name: str) -> None:
@lightbulb.command("py", "Run code.", pass_options=True)
@lightbulb.implements(lightbulb.PrefixCommand)
async def eval_py(ctx: SnedPrefixContext, code: str) -> None:

globals_dict = {
"_author": ctx.author,
"_bot": ctx.bot,
Expand Down Expand Up @@ -241,7 +240,6 @@ def unload(bot: SnedBot) -> None:
@lightbulb.command("sh", "Run code.", pass_options=True)
@lightbulb.implements(lightbulb.PrefixCommand)
async def eval_sh(ctx: SnedPrefixContext, code: str) -> None:

await run_shell(ctx, code)


Expand Down
2 changes: 0 additions & 2 deletions extensions/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ async def callback(self, ctx: miru.Context) -> None:
winner = view.check_winner()

if winner is not None:

if winner == WinState.PLAYER_X:
embed = hikari.Embed(
title="Tic Tac Toe!",
Expand Down Expand Up @@ -742,7 +741,6 @@ async def on_dice_reroll(event: miru.ComponentInteractionCreateEvent) -> None:
@lightbulb.command("animal", "Shows a random picture of the selected animal.", pass_options=True)
@lightbulb.implements(lightbulb.SlashCommand)
async def animal(ctx: SnedSlashContext, animal: str) -> None:

await animal_ratelimiter.acquire(ctx)
if animal_ratelimiter.is_rate_limited(ctx):
await ctx.respond(
Expand Down
2 changes: 0 additions & 2 deletions extensions/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ async def about(ctx: SnedSlashContext) -> None:
@lightbulb.command("invite", "Invite the bot to your server!")
@lightbulb.implements(lightbulb.SlashCommand)
async def invite(ctx: SnedSlashContext) -> None:

if not ctx.app.dev_mode:
invite_url = f"https://discord.com/oauth2/authorize?client_id={ctx.app.user_id}&permissions=1494984682710&scope=applications.commands%20bot"
await ctx.respond(
Expand Down Expand Up @@ -346,7 +345,6 @@ async def echo(ctx: SnedSlashContext, text: str) -> None:
@lightbulb.command("edit", "Edit a message that was sent by the bot.", pass_options=True)
@lightbulb.implements(lightbulb.SlashCommand)
async def edit(ctx: SnedSlashContext, message_link: str) -> None:

message = await helpers.parse_message_link(ctx, message_link)
if not message:
return
Expand Down
12 changes: 1 addition & 11 deletions extensions/moderation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@
from etc import const
from models import errors
from models.bot import SnedBot
from models.checks import (
bot_has_permissions,
has_permissions,
is_above_target,
is_invoker_above_target,
)
from models.checks import bot_has_permissions, is_above_target, is_invoker_above_target
from models.context import SnedSlashContext, SnedUserContext
from models.db_user import DatabaseUser
from models.events import MassBanEvent
Expand Down Expand Up @@ -187,7 +182,6 @@ async def role_del(ctx: SnedSlashContext, user: hikari.Member, role: hikari.Role
@lightbulb.command("purge", "Purge multiple messages in this channel.")
@lightbulb.implements(lightbulb.SlashCommand)
async def purge(ctx: SnedSlashContext) -> None:

channel = ctx.get_channel() or await ctx.app.rest.fetch_channel(ctx.channel_id)
assert isinstance(channel, hikari.TextableGuildChannel)

Expand Down Expand Up @@ -620,7 +614,6 @@ async def ban_cmd(
duration: t.Optional[str] = None,
days_to_delete: t.Optional[str] = None,
) -> None:

assert ctx.member is not None

if duration:
Expand Down Expand Up @@ -730,7 +723,6 @@ async def softban_cmd(
@lightbulb.command("unban", "Unban a user who was previously banned.", pass_options=True)
@lightbulb.implements(lightbulb.SlashCommand)
async def unban_cmd(ctx: SnedSlashContext, user: hikari.User, reason: t.Optional[str] = None) -> None:

assert ctx.member is not None

await ctx.mod_respond(hikari.ResponseType.DEFERRED_MESSAGE_CREATE)
Expand All @@ -757,7 +749,6 @@ async def unban_cmd(ctx: SnedSlashContext, user: hikari.User, reason: t.Optional
@lightbulb.command("kick", "Kick a user from this server.", pass_options=True)
@lightbulb.implements(lightbulb.SlashCommand)
async def kick_cmd(ctx: SnedSlashContext, user: hikari.Member, reason: t.Optional[str] = None) -> None:

helpers.is_member(user)
assert ctx.member is not None

Expand Down Expand Up @@ -827,7 +818,6 @@ async def slowmode_mcd(ctx: SnedSlashContext, interval: int) -> None:
@lightbulb.command("massban", "Ban a large number of users based on a set of criteria. Useful for handling raids")
@lightbulb.implements(lightbulb.SlashCommand)
async def massban(ctx: SnedSlashContext) -> None:

if ctx.options["joined-before"]:
helpers.is_member(ctx.options["joined-before"])
if ctx.options["joined-after"]:
Expand Down
4 changes: 0 additions & 4 deletions extensions/reminders.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ async def on_timeout(self) -> None:

@reminders.listener(miru.ComponentInteractionCreateEvent, bind=True)
async def reminder_component_handler(plugin: SnedPlugin, event: miru.ComponentInteractionCreateEvent) -> None:

if not event.context.custom_id.startswith(("RMSS:", "RMAR:")):
return

Expand Down Expand Up @@ -170,7 +169,6 @@ async def reminder_component_handler(plugin: SnedPlugin, event: miru.ComponentIn
notes: t.Dict[str, t.Any] = json.loads(timer.notes)

if event.context.user.id not in notes["additional_recipients"]:

if len(notes["additional_recipients"]) > 50:
await event.context.respond(
embed=hikari.Embed(
Expand Down Expand Up @@ -224,7 +222,6 @@ async def reminder(ctx: SnedSlashContext) -> None:
@lightbulb.command("create", "Create a new reminder.", pass_options=True)
@lightbulb.implements(lightbulb.SlashSubCommand)
async def reminder_create(ctx: SnedSlashContext, when: str, message: t.Optional[str] = None) -> None:

assert ctx.guild_id is not None

if message and len(message) >= 1000:
Expand Down Expand Up @@ -308,7 +305,6 @@ async def reminder_create(ctx: SnedSlashContext, when: str, message: t.Optional[
@lightbulb.command("delete", "Delete a currently pending reminder.", pass_options=True)
@lightbulb.implements(lightbulb.SlashSubCommand)
async def reminder_del(ctx: SnedSlashContext, id: int) -> None:

assert ctx.guild_id is not None

try:
Expand Down
1 change: 0 additions & 1 deletion extensions/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ async def report_perms_error(ctx: SnedApplicationContext) -> None:
async def report(
ctx: SnedApplicationContext, member: hikari.Member, message: t.Optional[hikari.Message] = None
) -> None:

assert ctx.member is not None and ctx.guild_id is not None

if member.id == ctx.member.id or member.is_bot:
Expand Down
5 changes: 0 additions & 5 deletions extensions/role_buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ async def rolebutton_listener(plugin: SnedPlugin, event: miru.ComponentInteracti
return

if role.id in event.context.member.role_ids:

if role_button.mode in [RoleButtonMode.TOGGLE, RoleButtonMode.REMOVE_ONLY]:
await event.context.member.remove_role(role, reason=f"Removed by role-button (ID: {entry_id})")
embed = hikari.Embed(
Expand All @@ -175,7 +174,6 @@ async def rolebutton_listener(plugin: SnedPlugin, event: miru.ComponentInteracti
).set_footer("This button is set to only add roles, not remove them.")

else:

if role_button.mode in [RoleButtonMode.TOGGLE, RoleButtonMode.ADD_ONLY]:
await event.context.member.add_role(role, reason=f"Granted by role-button (ID: {entry_id})")
embed = hikari.Embed(
Expand Down Expand Up @@ -217,7 +215,6 @@ async def rolebutton(ctx: SnedSlashContext) -> None:
@lightbulb.command("list", "List all registered rolebuttons on this server.")
@lightbulb.implements(lightbulb.SlashSubCommand)
async def rolebutton_list(ctx: SnedSlashContext) -> None:

assert ctx.guild_id is not None

buttons = await RoleButton.fetch_all(ctx.guild_id)
Expand Down Expand Up @@ -449,7 +446,6 @@ async def rolebutton_add(
label: t.Optional[str] = None,
mode: t.Optional[str] = None,
) -> None:

assert ctx.guild_id is not None and ctx.member is not None

style = style or "Grey"
Expand Down Expand Up @@ -560,7 +556,6 @@ async def rolebutton_add(
)
@lightbulb.implements(lightbulb.SlashSubCommand)
async def rolebutton_setprompt(ctx: SnedSlashContext, button_id: int, prompt_type: str) -> None:

button = await RoleButton.fetch(button_id)
if not button or button.guild_id != ctx.guild_id:
await ctx.respond(
Expand Down
7 changes: 0 additions & 7 deletions extensions/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ async def settings_report(self) -> None:
assert self.last_item and self.last_item.custom_id

if self.last_item.custom_id == "add_r":

embed = hikari.Embed(
title="Reports Settings",
description="Select a role to add to the list of roles that will be mentioned when a new report is made.",
Expand Down Expand Up @@ -334,7 +333,6 @@ async def settings_report(self) -> None:
return await self.error_screen(embed, parent="Reports")

elif self.last_item.custom_id == "del_r":

embed = hikari.Embed(
title="Reports Settings",
description="Remove a role from the list of roles that is mentioned when a new report is made.",
Expand Down Expand Up @@ -433,7 +431,6 @@ async def settings_mod(self) -> None:
await self.settings_mod()

async def settings_starboard(self) -> None:

assert isinstance(self.app, SnedBot) and self.last_ctx is not None and self.last_ctx.guild_id is not None

records = await self.app.db_cache.get(table="starboard", guild_id=self.last_ctx.guild_id, limit=1)
Expand Down Expand Up @@ -602,7 +599,6 @@ async def settings_starboard(self) -> None:

assert self.last_item is not None
if self.last_item.custom_id == "add_excluded":

embed = hikari.Embed(
title="Starboard Settings",
description="Select a new channel to be added to the list of excluded channels. Users will not be able to star messages from these channels.",
Expand Down Expand Up @@ -636,7 +632,6 @@ async def settings_starboard(self) -> None:
return await self.error_screen(embed, parent="Starboard")

elif self.last_item.custom_id == "del_excluded":

embed = hikari.Embed(
title="Starboard Settings",
description="Remove a channel from the list of excluded channels.",
Expand Down Expand Up @@ -1044,7 +1039,6 @@ async def settings_automod_policy(self, policy: t.Optional[str] = None) -> None:
action = [key for key in actions if opt in actions[key]][0]

if opt == "state": # State changing is a special case, ignore action

options = [
miru.SelectOption(
value=state,
Expand Down Expand Up @@ -1141,7 +1135,6 @@ async def settings_automod_policy(self, policy: t.Optional[str] = None) -> None:
policies[policy][opt] = value

elif action == "ask":

if opt in ["add_channel", "add_role", "del_channel", "del_role"]:
match opt:
case "add_channel":
Expand Down
2 changes: 0 additions & 2 deletions extensions/starboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ async def on_reaction(
return

if channel := plugin.app.cache.get_guild_channel(settings["channel_id"]):

perms = lightbulb.utils.permissions_in(channel, me)
if not helpers.includes_permissions(
perms,
Expand Down Expand Up @@ -256,7 +255,6 @@ async def star(ctx: SnedSlashContext) -> None:
@lightbulb.command("show", "Show a starboard entry.", pass_options=True)
@lightbulb.implements(lightbulb.SlashSubCommand)
async def star_show(ctx: SnedSlashContext, id: str) -> None:

assert ctx.guild_id is not None

try:
Expand Down
8 changes: 0 additions & 8 deletions extensions/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ async def tag_group(ctx: SnedSlashContext) -> None:
@lightbulb.command("create", "Create a new tag. Opens a modal to specify the details.")
@lightbulb.implements(lightbulb.SlashSubCommand)
async def tag_create(ctx: SnedSlashContext) -> None:

assert ctx.guild_id is not None and ctx.member is not None

modal = TagEditorModal()
Expand Down Expand Up @@ -277,7 +276,6 @@ async def tag_delalias(ctx: SnedSlashContext, name: str, alias: str) -> None:

tag = await Tag.fetch(name.casefold(), ctx.guild_id)
if tag and tag.owner_id == ctx.author.id:

if tag.aliases and alias.casefold() in tag.aliases:
tag.aliases.remove(alias.casefold())

Expand Down Expand Up @@ -339,7 +337,6 @@ async def tag_transfer(ctx: SnedSlashContext, name: str, receiver: hikari.Member
tag = await Tag.fetch(name.casefold(), ctx.guild_id)

if tag and tag.owner_id == ctx.author.id:

tag.owner_id = receiver.id
await tag.update()

Expand Down Expand Up @@ -381,7 +378,6 @@ async def tag_transfer_name_ac(
)
@lightbulb.implements(lightbulb.SlashSubCommand)
async def tag_claim(ctx: SnedSlashContext, name: str) -> None:

assert ctx.guild_id is not None and ctx.member is not None

tag = await Tag.fetch(name.casefold(), ctx.guild_id)
Expand Down Expand Up @@ -442,7 +438,6 @@ async def tag_claim_name_ac(
@lightbulb.command("edit", "Edit the content of a tag you own.", pass_options=True)
@lightbulb.implements(lightbulb.SlashSubCommand)
async def tag_edit(ctx: SnedSlashContext, name: str) -> None:

assert ctx.member is not None and ctx.guild_id is not None

tag = await Tag.fetch(name.casefold(), ctx.guild_id)
Expand Down Expand Up @@ -493,7 +488,6 @@ async def tag_edit_name_ac(
@lightbulb.command("delete", "Delete a tag you own.", pass_options=True)
@lightbulb.implements(lightbulb.SlashSubCommand)
async def tag_delete(ctx: SnedSlashContext, name: str) -> None:

assert ctx.member is not None and ctx.guild_id is not None

tag = await Tag.fetch(name.casefold(), ctx.guild_id)
Expand All @@ -502,7 +496,6 @@ async def tag_delete(ctx: SnedSlashContext, name: str) -> None:
(tag.owner_id == ctx.author.id)
or helpers.includes_permissions(lightbulb.utils.permissions_for(ctx.member), hikari.Permissions.MANAGE_MESSAGES)
):

await tag.delete()

await ctx.respond(
Expand Down Expand Up @@ -575,7 +568,6 @@ async def tag_list(ctx: SnedSlashContext, owner: t.Optional[hikari.User] = None)
@lightbulb.command("search", "Search for a tag name or alias.", pass_options=True)
@lightbulb.implements(lightbulb.SlashSubCommand)
async def tag_search(ctx: SnedSlashContext, query: str) -> None:

assert ctx.member is not None and ctx.guild_id is not None

tags = await Tag.fetch_all(ctx.guild_id)
Expand Down
2 changes: 0 additions & 2 deletions extensions/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ async def bar_button(self, button: miru.Button, ctx: miru.ViewContext) -> None:


class BasicView(miru.View):

# Define a new Select menu with two options
@miru.select(
placeholder="Select me!",
Expand Down Expand Up @@ -112,7 +111,6 @@ async def modaltest(ctx: SnedSlashContext) -> None:
@lightbulb.command("navtest", "Test miru nav")
@lightbulb.implements(lightbulb.SlashCommand)
async def navtest(ctx: SnedSlashContext) -> None:

buttons = [nav.FirstButton(), nav.PrevButton(), nav.StopButton(), nav.NextButton(), nav.LastButton()]

navigator = nav.NavigatorView(pages=["1", "2", "3"], buttons=buttons)
Expand Down
Loading

0 comments on commit 2826684

Please sign in to comment.