Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blart support with audit log #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion BLART/Commands/Bans/BanCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ await user.SendMessageAsync(
Log.Warn(nameof(Ban), $"Failed to message {user.Username}");
}

await ((IGuildUser)user).BanAsync(7, reason);
await ((IGuildUser)user).BanAsync(7, reason, new() { AuditLogReason = $"Banned by {Context.User.Username} with reason: {reason}." });
await RespondAsync(embed: await EmbedBuilderService.CreateBasicEmbed("User banned", $"{user.Username} has been banned for: {reason}", Color.Orange));
await Logging.SendLogMessage("User banned",
$"{Context.User.Username} has banned {user.Username} for {reason}.", Color.Red);
Expand Down
2 changes: 1 addition & 1 deletion BLART/Commands/Bans/BanIdCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ await RespondAsync(embed: await ErrorHandlingService.GetErrorEmbed(ErrorCodes.Un
}

reason = ReasonParsing.ParseRules(reason);
await Context.Guild.AddBanAsync(userId, 7, reason);
await Context.Guild.AddBanAsync(userId, 7, reason, new() { AuditLogReason = $"Banned by {Context.User.Username} with reason: {reason}." });
await Logging.SendLogMessage("User banned",
$"{Context.User.Username} has banned {id} for {reason}.", Color.Red);
DatabaseHandler.AddEntry(userId, reason, DatabaseType.Ban, Context.User.Id);
Expand Down
2 changes: 1 addition & 1 deletion BLART/Commands/Bans/UnbanIdCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ await RespondAsync(embed: await ErrorHandlingService.GetErrorEmbed(ErrorCodes.Un
return;
}

await Context.Guild.RemoveBanAsync(userId);
await Context.Guild.RemoveBanAsync(userId, new() { AuditLogReason = $"Ban removed by {Context.User.Username}." });
PunishmentInfo? info = DatabaseHandler.GetInfoById(userId, DatabaseType.Ban);
DatabaseHandler.RemoveEntry(userId, DatabaseType.Ban);
await RespondAsync(embed: await EmbedBuilderService.CreateBasicEmbed("User Unbanned", $"{id} has been unbanned", Color.Green));
Expand Down
3 changes: 2 additions & 1 deletion BLART/Commands/ChannelRenting/DenyCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ await RespondAsync(embed: await ErrorHandlingService.GetErrorEmbed(ErrorCodes.Pe
IVoiceChannel channel = Bot.Instance.Guild.GetVoiceChannel(ChannelRenting.RentedChannels[Context.User]);

foreach (IGuildUser user in guildUsers)
await channel.AddPermissionOverwriteAsync(user, new OverwritePermissions(connect: PermValue.Deny));
await channel.AddPermissionOverwriteAsync(user, new OverwritePermissions(connect: PermValue.Deny),
new() { AuditLogReason = $"Channel renting: Permission to join revoked by {Context.User.Username}." });

await RespondAsync("The mentioned users have been denied access to your channel.");
}
Expand Down
3 changes: 2 additions & 1 deletion BLART/Commands/ChannelRenting/PermitCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ await RespondAsync(embed: await ErrorHandlingService.GetErrorEmbed(ErrorCodes.Pe
IVoiceChannel channel = Bot.Instance.Guild.GetVoiceChannel(ChannelRenting.RentedChannels[Context.User]);

foreach (IGuildUser user in guildUsers)
await channel.AddPermissionOverwriteAsync(user, new OverwritePermissions(connect: PermValue.Allow));
await channel.AddPermissionOverwriteAsync(user, new OverwritePermissions(connect: PermValue.Allow),
new() { AuditLogReason = $"Channel renting: Permission to join granted by {Context.User.Username}." });

await RespondAsync("The users mentioned have been permitted to connect to your channel.");
}
Expand Down
2 changes: 1 addition & 1 deletion BLART/Commands/Muting/MuteCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task Mute(
}

await Logging.SendLogMessage("User muted", $"{Context.User.Username} muted {user.Username} for {span} for {reason}.", Color.Orange);
await ((IGuildUser)user).SetTimeOutAsync(span);
await ((IGuildUser)user).SetTimeOutAsync(span, new() { AuditLogReason = $"Muted by {user.Username} with reason: {reason}." });
await RespondAsync(embed: await EmbedBuilderService.CreateBasicEmbed("User Muted",
$"{user.Username} has been muted for {span}.\nReason: {reason}", Color.Red));
}
Expand Down
2 changes: 1 addition & 1 deletion BLART/Commands/Muting/UnmuteCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public async Task Unmute([Summary("User", "The user to unmute")] SocketUser user
}

await Logging.SendLogMessage("User unmuted", $"{Context.User.Username} unmuted {user.Username}.", Color.Orange);
await ((IGuildUser)user).RemoveTimeOutAsync();
await ((IGuildUser)user).RemoveTimeOutAsync(new() { AuditLogReason = $"Unmuted by {Context.User.Username}." });
await RespondAsync(embed: await EmbedBuilderService.CreateBasicEmbed("Mute Removed",
$"{user.Username} has had their mute removed.", Color.Green));
}
Expand Down
2 changes: 1 addition & 1 deletion BLART/Commands/RedRoles/GiveCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public async Task Give([Summary("User", "The user to give the role to.")] Socket
return;
}

await target.AddRoleAsync(role);
await target.AddRoleAsync(role, new() { AuditLogReason = $"Red role added by {Context.User.Username} with reason: {reason}." });
DatabaseHandler.AddEntry(target.Id, reason, DatabaseType.RedRole, Context.User.Id);
await RespondAsync(embed: await EmbedBuilderService.CreateBasicEmbed("Red Role Issued",
$"{target.Username} has been issued a red role.", Color.Red));
Expand Down
2 changes: 1 addition & 1 deletion BLART/Commands/RedRoles/RemoveCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public async Task Remove([Summary("User", "The user who's red role is to be remo
return;
}

await target.RemoveRoleAsync(role);
await target.RemoveRoleAsync(role, new() { AuditLogReason = $"Red role removed by {Context.User.Username}." });
DatabaseHandler.RemoveEntry(target.Id, DatabaseType.RedRole);
await RespondAsync(embed: await EmbedBuilderService.CreateBasicEmbed("Red role removed",
$"{target.Username} has had their red role removed.", Color.Green));
Expand Down
4 changes: 2 additions & 2 deletions BLART/Commands/RoleCommands/RoleAssignCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ public async Task AssignRole([Summary("Role", "The role to give/remove to/from y
IGuildUser user = (IGuildUser)Context.User;
if (user.RoleIds.Any(r => r == role.Id))
{
await user.RemoveRoleAsync(role);
await user.RemoveRoleAsync(role, new() { AuditLogReason = $"Removed self-assignable role." });
await RespondAsync(embed: await EmbedBuilderService.CreateBasicEmbed("Role removed", "The selected role has been removed.", Color.Green), ephemeral: true);
}
else
{
await user.AddRoleAsync(role);
await user.AddRoleAsync(role, new() { AuditLogReason = "Added self-assignable role." });
await RespondAsync(embed: await EmbedBuilderService.CreateBasicEmbed("Role Added", "The selected role has been added.", Color.Green), ephemeral: true);
}
}
Expand Down
8 changes: 4 additions & 4 deletions BLART/Modals/BugReportModal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ private static async Task HandleInvalid(SocketMessageComponent component, IUserM
if (!await CheckPermissions(component, message))
return;

await BugReporting.OpenThreads[message.Id].DeleteAsync();
await message.DeleteAsync();
await BugReporting.OpenThreads[message.Id].DeleteAsync(new() { AuditLogReason = "Bug report marked as invalid." });
await message.DeleteAsync(new() { AuditLogReason = "Bug report marked as invalid." });
await component.RespondAsync(embed: await EmbedBuilderService.CreateBasicEmbed("Bug Report Invalidation", "The given bug report has been deleted.", Color.Red), ephemeral: true);
}

Expand All @@ -197,9 +197,9 @@ await duplicateThread.ModifyAsync(x =>
{
x.Locked = true;
x.Archived = true;
});
}, new() { AuditLogReason = "Bug report marked as duplicate." });

await message.DeleteAsync();
await message.DeleteAsync(new() { AuditLogReason = "Bug report marked as duplicate." });
await modal.RespondAsync(embed: await EmbedBuilderService.CreateBasicEmbed("Bug Duplicate Marking",
$"The selected bug report was marked as a duplicate of <#{originalThread.Id}>.", Color.Green), ephemeral: true);
}
Expand Down
18 changes: 9 additions & 9 deletions BLART/Modals/PluginSubmissionModal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,23 +153,23 @@ await modal.RespondAsync(embed: await ErrorHandlingService.GetErrorEmbed(ErrorCo


RestTextChannel channel = await Bot.Instance.Guild.CreateTextChannelAsync(embed.Title);
await channel.AddPermissionOverwriteAsync(Bot.Instance.Guild.EveryoneRole, new OverwritePermissions(sendMessages: PermValue.Deny));
await channel.AddPermissionOverwriteAsync(Bot.Instance.Guild.EveryoneRole, new OverwritePermissions(sendMessages: PermValue.Deny), new() { AuditLogReason = "Default plugin channel permissions." });

if (user is not null)
{
await channel.AddPermissionOverwriteAsync(user, new OverwritePermissions(manageChannel: PermValue.Allow, sendMessages: PermValue.Allow, manageWebhooks: PermValue.Allow));
await user.AddRoleAsync(656673780332101648);
await channel.AddPermissionOverwriteAsync(user, new OverwritePermissions(manageChannel: PermValue.Allow, sendMessages: PermValue.Allow, manageWebhooks: PermValue.Allow), new() { AuditLogReason = "Default plugin channel permissions." });
await user.AddRoleAsync(656673780332101648, new() { AuditLogReason = $"New plugin developer (submission '{embed.Title}' approved)!" });
}

IUserMessage newMessage = await channel.SendMessageAsync(embed: embed);
RestRole? role = await Bot.Instance.Guild.CreateRoleAsync(embed.Title);
RestRole? role = await Bot.Instance.Guild.CreateRoleAsync(embed.Title, options: new() { AuditLogReason = $"Created role for new plugin '{embed.Title}'." });

await channel.ModifyAsync(x =>
{
x.CategoryId = category.Id;
});
}, new() { AuditLogReason = "Set category of plugin." });
await newMessage.ModifyAsync(x => x.Components = new ComponentBuilder().WithButton(EditButton).WithButton(DeleteButton).Build());
await message.DeleteAsync();
await message.DeleteAsync(new() { AuditLogReason = "Deleted submission of approved plugin." });
DatabaseHandler.AddEntry(role.Id, string.Empty, DatabaseType.SelfRole);

await modal.FollowupAsync(embed: await EmbedBuilderService.CreateBasicEmbed("Plugin Accepted", "The plugin has been accepted.", Color.Green), ephemeral: true);
Expand All @@ -192,13 +192,13 @@ public static async Task HandleButton(SocketMessageComponent component)
{
IRole? role = Bot.Instance.Guild.Roles.FirstOrDefault(r => r.Name == embed.Title);
if (role is not null)
await role.DeleteAsync();
await role.DeleteAsync(new() { AuditLogReason = "Deleted role of associated deleted plugin." });
await component.RespondAsync(embed: await EmbedBuilderService.CreateBasicEmbed("Plugin Deleted", "The plugin, it's channel, and corrosponding role have been removed.", Color.Green), ephemeral: true);
if (component.Channel.Id != 695423213185794059)
await Bot.Instance.Guild.GetChannel(component.Channel.Id).DeleteAsync();
await Bot.Instance.Guild.GetChannel(component.Channel.Id).DeleteAsync(new() { AuditLogReason = "Deleted channel of associated deleted plugin." });
}

await component.Message.DeleteAsync();
await component.Message.DeleteAsync(new() { AuditLogReason = "Canceled plugin submission." });
await component.RespondAsync(embed: await EmbedBuilderService.CreateBasicEmbed("Submission Cancelled", "The plugin submission has been removed.", Color.Green), ephemeral: true);
}
}
Expand Down
15 changes: 8 additions & 7 deletions BLART/Modules/ChannelRenting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,25 @@ private static async Task HandleJoined(SocketUser user, SocketVoiceState before,
properties.UserLimit = 10;
properties.Name = chanName;
properties.CategoryId = Program.Config.ChannelRentCatId;
}, RequestOptions.Default);
}, new() { AuditLogReason = $"User {userName} rented a voice chat channel." });

await channel.AddPermissionOverwriteAsync(guild.EveryoneRole,
new OverwritePermissions(connect: PermValue.Deny));
await channel.AddPermissionOverwriteAsync(guildUser, new(connect: PermValue.Allow));
new OverwritePermissions(connect: PermValue.Deny), new() { AuditLogReason = "Default voice chat rent permissions." });
await channel.AddPermissionOverwriteAsync(guildUser, new(connect: PermValue.Allow), new() { AuditLogReason = "Default voice chat rent permissions." });
var staffRole = guild.GetRole(Program.Config.DiscStaffId);
await channel.AddPermissionOverwriteAsync(staffRole, new OverwritePermissions(connect: PermValue.Allow, manageChannel: PermValue.Allow));
await channel.AddPermissionOverwriteAsync(staffRole, new OverwritePermissions(connect: PermValue.Allow, manageChannel: PermValue.Allow), new() { AuditLogReason = "Default voice chat rent permissions." });

await guildUser.ModifyAsync(x => x.ChannelId = channel.Id);
await guildUser.ModifyAsync(x => x.ChannelId = channel.Id, new() { AuditLogReason = "Moved voice channel renter to new voice channel." });

RentedChannels.Add(user, channel.Id);
}

private static async Task HandleLeft(SocketUser user, SocketVoiceState before, SocketVoiceState after)
{
{
await Task.Delay(1000);
if (before.VoiceChannel.Users.Count == 0)
{
await before.VoiceChannel.DeleteAsync();
await before.VoiceChannel.DeleteAsync(new() { AuditLogReason = "Deleted empty rented voice channel." });
RentedChannels.Remove(user);
}
}
Expand Down
4 changes: 2 additions & 2 deletions BLART/Modules/ServerCountUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public static async Task DoUpdate()
SocketVoiceChannel vc = Bot.Instance.Guild.GetVoiceChannel(Channel1Id);
SocketVoiceChannel domination = Bot.Instance.Guild.GetVoiceChannel(Channel2Id);

await vc.ModifyAsync(x => x.Name = $"Total EXILED Servers: {exiledCount}");
await domination.ModifyAsync(x => x.Name = text);
await vc.ModifyAsync(x => x.Name = $"Total EXILED Servers: {exiledCount}", new() { AuditLogReason = "Update Exiled server count." });
await domination.ModifyAsync(x => x.Name = text, new() { AuditLogReason = "Update Exiled server count." });
}
catch (Exception e)
{
Expand Down
14 changes: 7 additions & 7 deletions BLART/Modules/SpamPrevention.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ public static async Task OnMessageReceived(SocketMessage message, bool skipSpam)
await Logging.SendLogMessage($"User auto-{(RaidProtection.Check(message.Author) ? "banned" : "muted")}", $"{message.Author.Username} has been auto-moderated for {(spam ? "spamming" : "linking")}.", Color.Red);

if (RaidProtection.Check(message.Author))
await ((IGuildUser)message.Author).BanAsync(7, "Raid protection triggered (spamming/linking)");
await ((IGuildUser)message.Author).BanAsync(7, "Raid protection triggered (spamming/linking)", new() { AuditLogReason = "Raid protection" });
else
{
await ((IGuildUser)message.Author).SetTimeOutAsync(TimeSpan.FromHours(2));
await message.DeleteAsync();
await ((IGuildUser)message.Author).SetTimeOutAsync(TimeSpan.FromHours(2), new() { AuditLogReason = "Raid protection" });
await message.DeleteAsync(new() { AuditLogReason = "Raid protection" });
int count = 0;
foreach (SocketTextChannel channel in Bot.Instance.Guild.TextChannels)
{
foreach (IMessage msg in await channel.GetMessagesAsync(20).FlattenAsync())
{
if (msg.Author.Id == message.Author.Id && (DateTime.UtcNow - msg.Timestamp).TotalMinutes < 5)
{
await msg.DeleteAsync();
await msg.DeleteAsync(new() { AuditLogReason = "Raid protection" });
count++;

if (count > 20)
Expand Down Expand Up @@ -145,18 +145,18 @@ await Logging.SendLogMessage($"User auto-{(RaidProtection.Check(message.User) ?
$"{message.User.Username} has been auto-moderated for spamming.", Color.Red);

if (RaidProtection.Check(message.User))
await ((IGuildUser) message.User).BanAsync(7, "Raid protection triggered (spamming/linking)");
await ((IGuildUser) message.User).BanAsync(7, "Raid protection triggered (spamming/linking)", new() { AuditLogReason = "Raid protection" });
else
{
await ((IGuildUser) message.User).SetTimeOutAsync(TimeSpan.FromHours(6));
await ((IGuildUser) message.User).SetTimeOutAsync(TimeSpan.FromHours(6), new() { AuditLogReason = "Raid protection" });
int count = 0;
foreach (SocketTextChannel channel in Bot.Instance.Guild.TextChannels)
{
foreach (IMessage msg in await channel.GetMessagesAsync(20).FlattenAsync())
{
if (msg.Author.Id == message.User.Id && (DateTime.UtcNow - msg.Timestamp).TotalMinutes < 5)
{
await msg.DeleteAsync();
await msg.DeleteAsync(new() { AuditLogReason = "Raid protection" });
count++;

if (count > 20)
Expand Down