Skip to content

Commit

Permalink
Modlog commands done
Browse files Browse the repository at this point in the history
  • Loading branch information
ajax146 committed Jul 23, 2024
1 parent 0f50256 commit fda054c
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 7 deletions.
4 changes: 3 additions & 1 deletion techsupport_bot/commands/moderator.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ async def handle_unban_user(
await interaction.response.send_message(embed=embed)
return

await modlog.log_unban(target, interaction.user, interaction.guild, reason)
await modlog.log_unban(
self.bot, target, interaction.user, interaction.guild, reason
)

await moderation.send_command_usage_alert(
bot=self.bot,
Expand Down
121 changes: 117 additions & 4 deletions techsupport_bot/commands/modlog.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from __future__ import annotations

Check notice on line 1 in techsupport_bot/commands/modlog.py

View check run for this annotation

codefactor.io / CodeFactor

techsupport_bot/commands/modlog.py#L1

Missing module docstring (missing-module-docstring)

import datetime
from collections import Counter
from typing import TYPE_CHECKING, Self

import discord
from core import cogs
import munch
import ui
from core import auxiliary, cogs
from discord import app_commands
from discord.ext import commands

if TYPE_CHECKING:
Expand All @@ -21,15 +25,123 @@ async def setup(bot: bot.TechSupportBot) -> None:


Check notice on line 26 in techsupport_bot/commands/modlog.py

View check run for this annotation

codefactor.io / CodeFactor

techsupport_bot/commands/modlog.py#L26

Missing function or method docstring (missing-function-docstring)
class BanLogger(cogs.BaseCog):
async def high_score_command(self: Self, interaction: discord.Interaction): ...

modlog_group = app_commands.Group(
name="modlog", description="...", extras={"module": "modlog"}

Check notice on line 30 in techsupport_bot/commands/modlog.py

View check run for this annotation

codefactor.io / CodeFactor

techsupport_bot/commands/modlog.py#L30

Missing function or method docstring (missing-function-docstring)
)

@modlog_group.command(
name="highscores",
description="Unban someone and allow them to apply",

Check notice on line 35 in techsupport_bot/commands/modlog.py

View check run for this annotation

codefactor.io / CodeFactor

techsupport_bot/commands/modlog.py#L35

Missing function or method docstring (missing-function-docstring)
extras={"module": "modlog"},
)
async def high_score_command(self: Self, interaction: discord.Interaction):

Check notice on line 38 in techsupport_bot/commands/modlog.py

View check run for this annotation

codefactor.io / CodeFactor

techsupport_bot/commands/modlog.py#L38

Missing function or method docstring (missing-function-docstring)
all_bans = await self.bot.models.BanLog.query.where(
self.bot.models.BanLog.guild_id == str(interaction.guild.id)
).gino.all()
ban_frequency_counter = Counter(ban.banning_moderator for ban in all_bans)

sorted_ban_frequency = sorted(
ban_frequency_counter.items(), key=lambda x: x[1], reverse=True
)
embed = discord.Embed(title="Most active moderators")

final_string = ""
for index, (moderator_id, count) in enumerate(sorted_ban_frequency):

Check notice on line 50 in techsupport_bot/commands/modlog.py

View check run for this annotation

codefactor.io / CodeFactor

techsupport_bot/commands/modlog.py#L50

Using possibly undefined loop variable 'entry' (undefined-loop-variable)
moderator = await interaction.guild.fetch_member(int(moderator_id))
final_string += (
f"{index+1}. {moderator.display_name} "

Check notice on line 53 in techsupport_bot/commands/modlog.py

View check run for this annotation

codefactor.io / CodeFactor

techsupport_bot/commands/modlog.py#L53

Missing function or method docstring (missing-function-docstring)
f"{moderator.mention} ({moderator.id}) - ({count})\n"
)
embed.description = final_string
embed.color = discord.Color.blue()
await interaction.response.send_message(embed=embed)

@modlog_group.command(
name="lookup-user",
description="Unban someone and allow them to apply",
extras={"module": "modlog"},
)
async def lookup_user_command(
self: Self, interaction: discord.Interaction, user: discord.User
): ...
):
recent_bans_by_user = (
await self.bot.models.BanLog.query.where(
self.bot.models.BanLog.guild_id == str(interaction.guild.id)
)

Check notice on line 71 in techsupport_bot/commands/modlog.py

View check run for this annotation

codefactor.io / CodeFactor

techsupport_bot/commands/modlog.py#L71

Using possibly undefined loop variable 'entry' (undefined-loop-variable)
.where(self.bot.models.BanLog.banned_member == str(user.id))
.order_by(self.bot.models.BanLog.ban_time.desc())
.limit(10)
.gino.all()

Check notice on line 75 in techsupport_bot/commands/modlog.py

View check run for this annotation

codefactor.io / CodeFactor

techsupport_bot/commands/modlog.py#L75

Missing function or method docstring (missing-function-docstring)
)

embeds = []
for ban in recent_bans_by_user:
embeds.append(
await self.convert_ban_to_pretty_string(ban, f"{user.name} bans")
)

if len(embeds) == 0:
embed = auxiliary.prepare_deny_embed(
f"No bans for the user {user.name} could be found"
)
await interaction.response.send_message(embed=embed)
return

await interaction.response.defer(ephemeral=False)
view = ui.PaginateView()
await view.send(interaction.channel, interaction.user, embeds, interaction)

@modlog_group.command(
name="lookup-moderator",
description="Unban someone and allow them to apply",
extras={"module": "modlog"},
)
async def lookup_moderator_command(
self: Self, interaction: discord.Interaction, moderator: discord.Member
): ...
):
recent_bans_by_user = (
await self.bot.models.BanLog.query.where(
self.bot.models.BanLog.guild_id == str(interaction.guild.id)
)
.where(self.bot.models.BanLog.banning_moderator == str(moderator.id))
.order_by(self.bot.models.BanLog.ban_time.desc())
.limit(10)
.gino.all()
)

embeds = []
for ban in recent_bans_by_user:
embeds.append(
await self.convert_ban_to_pretty_string(
ban, f"Bans by {moderator.name}"
)

Check notice on line 118 in techsupport_bot/commands/modlog.py

View check run for this annotation

codefactor.io / CodeFactor

techsupport_bot/commands/modlog.py#L118

Missing function or method docstring (missing-function-docstring)
)

if len(embeds) == 0:
embed = auxiliary.prepare_deny_embed(
f"No bans by the user {moderator.name} could be found"
)
await interaction.response.send_message(embed=embed)
return

Check notice on line 127 in techsupport_bot/commands/modlog.py

View check run for this annotation

codefactor.io / CodeFactor

techsupport_bot/commands/modlog.py#L127

Using an f-string that does not have any interpolated variables (f-string-without-interpolation)
await interaction.response.defer(ephemeral=False)
view = ui.PaginateView()
await view.send(interaction.channel, interaction.user, embeds, interaction)

async def convert_ban_to_pretty_string(self, ban: munch.Munch, title: str):

Check notice on line 132 in techsupport_bot/commands/modlog.py

View check run for this annotation

codefactor.io / CodeFactor

techsupport_bot/commands/modlog.py#L132

Missing function or method docstring (missing-function-docstring)
member = await self.bot.fetch_user(int(ban.banned_member))
moderator = await self.bot.fetch_user(int(ban.banning_moderator))
embed = discord.Embed(title=title)
embed.description = (
f"**Case:** {ban.pk}\n"
f"**Offender:** {member.name} {member.mention}\n"
f"**Reason:** {ban.reason}\n"
f"**Responsible moderator:** {moderator.name} {moderator.mention}"
)
embed.timestamp = ban.ban_time
embed.color = discord.Color.red()
return embed

@commands.Cog.listener()
async def on_member_ban(
Expand Down Expand Up @@ -116,6 +228,7 @@ async def log_ban(


async def log_unban(
bot: bot.TechSupportBot,
unbanned_member: discord.User | discord.Member,
unbanning_moderator: discord.Member,
guild: discord.Guild,
Expand Down
3 changes: 1 addition & 2 deletions techsupport_bot/commands/report.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
class Report:

Check notice on line 1 in techsupport_bot/commands/report.py

View check run for this annotation

codefactor.io / CodeFactor

techsupport_bot/commands/report.py#L1

Missing module docstring (missing-module-docstring)

Check notice on line 1 in techsupport_bot/commands/report.py

View check run for this annotation

codefactor.io / CodeFactor

techsupport_bot/commands/report.py#L1

Missing class docstring (missing-class-docstring)
async def report_command(self, interaction, report_str):
...
async def report_command(self, interaction, report_str): ...

Check notice on line 2 in techsupport_bot/commands/report.py

View check run for this annotation

codefactor.io / CodeFactor

techsupport_bot/commands/report.py#L2

Missing function or method docstring (missing-function-docstring)

0 comments on commit fda054c

Please sign in to comment.