Skip to content

Commit

Permalink
Better bot legitimacy controls
Browse files Browse the repository at this point in the history
  • Loading branch information
Naamloos committed Nov 14, 2023
1 parent 162fa04 commit 6251eea
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
36 changes: 36 additions & 0 deletions ModCore/Components/BotManagerComponents.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using DSharpPlus;
using DSharpPlus.Entities;
using DSharpPlus.EventArgs;
using ModCore.Database;
using ModCore.Extensions;
using ModCore.Extensions.Abstractions;
using ModCore.Extensions.Attributes;
Expand All @@ -12,6 +14,15 @@ namespace ModCore.Components
{
public class BotManagerComponents : BaseComponentModule
{
private DatabaseContextBuilder database;
private DiscordClient client;

public BotManagerComponents(DatabaseContextBuilder database, DiscordClient client)
{
this.database = database;
this.client = client;
}

[Component("fb", ComponentType.Button)]
public async Task RespondFeedbackAsync(ComponentInteractionCreateEventArgs e, IDictionary<string, string> context)
{
Expand All @@ -28,5 +39,30 @@ public async Task RespondFeedbackAsync(ComponentInteractionCreateEventArgs e, ID
});
}
}

[Component("lguild", ComponentType.Button)]
public async Task LeaveGuildAsync(ComponentInteractionCreateEventArgs e, IDictionary<string, string> context)
{
if (Client.CurrentApplication.Owners.All(x => x.Id != e.User.Id))
return;

if (ulong.TryParse(context["id"], out ulong id))
{
var naughtyGuild = await client.GetGuildAsync(id);
if (naughtyGuild is not null)
{
await naughtyGuild.LeaveAsync();
var response = new DiscordInteractionResponseBuilder()
.WithContent("")
.AsEphemeral()
.AddEmbed(new DiscordEmbedBuilder().WithTitle($"Left naughty guild.")
.WithDescription($"{id}: {naughtyGuild.Name}")
.WithThumbnail(naughtyGuild.GetIconUrl(ImageFormat.Png))
.WithColor(DiscordColor.Red));

await e.Interaction.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, response);
}
}
}
}
}
8 changes: 5 additions & 3 deletions ModCore/Listeners/MessageSnipe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static async Task MessageSniped(MessageDeleteEventArgs eventargs, SharedD
{
await Task.Yield();

if (eventargs.Message == null)
if (eventargs.Message is null)
return;
if (eventargs.Message.WebhookMessage)
return;
Expand Down Expand Up @@ -54,10 +54,12 @@ public static async Task MessageSniped(MessageDeleteEventArgs eventargs, SharedD
[AsyncListener(EventType.MessageUpdated)]
public static async Task MessageEdited(MessageUpdateEventArgs eventargs, SharedData sharedData, DatabaseContextBuilder database, IMemoryCache cache)
{
if (eventargs.Message == null)
if (eventargs.Message is null)
return;
if (eventargs.Message.WebhookMessage)
return;
if (eventargs.MessageBefore is null)
return;

await Task.Yield();

Expand All @@ -71,7 +73,7 @@ public static async Task MessageEdited(MessageUpdateEventArgs eventargs, SharedD
if(cfg != null && cfg.Logging.EditLog_Enable)
{
var channel = eventargs.Guild.GetChannel(cfg.Logging.ChannelId);
if (channel == null)
if (channel is null)
return;

if (eventargs.Message.Content != eventargs.MessageBefore.Content)
Expand Down
7 changes: 6 additions & 1 deletion ModCore/Listeners/NoBotFarm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static async Task NoBotFarmsPleaseAsync(GuildCreateEventArgs e, DiscordCl

var embed = new DiscordEmbedBuilder()
.WithTitle("Joined new guild!")
.WithDescription($"Guild Name: {e.Guild.Name}")
.WithDescription($"Guild Name: {e.Guild.Name}\nID: {e.Guild.Id}")
.AddField("Members", e.Guild.MemberCount.ToString(), true)
.AddField("Bots", botCount >= 0 ? botCount.ToString() : "LargeGuild", true)
.AddField("Bot Ratio", botCount >= 0 ? $"{botRatio}%" : "LargeGuild", true);
Expand All @@ -54,6 +54,11 @@ public static async Task NoBotFarmsPleaseAsync(GuildCreateEventArgs e, DiscordCl

messageBuilder.AddEmbed(embed);

messageBuilder.AddComponents(new DiscordComponent[]
{
new DiscordButtonComponent(ButtonStyle.Danger, "lguild", "Leave Guild", emoji: new DiscordComponentEmoji(""))
});

await channel.SendMessageAsync(messageBuilder);
}
}
Expand Down

0 comments on commit 6251eea

Please sign in to comment.