Delete the guild blacklist

This commit is contained in:
Octol1ttle 2022-11-11 23:17:44 +05:00
parent 857047c77c
commit 0e144db2e2
Signed by: Octol1ttle
GPG key ID: B77C34313AEE1FFF
3 changed files with 24 additions and 44 deletions

View file

@ -59,8 +59,7 @@ public sealed class CommandProcessor {
.GetUser(Context.User.Id); // Getting an up-to-date copy .GetUser(Context.User.Id); // Getting an up-to-date copy
if (member == null || member.Roles.Contains(muteRole) if (member == null || member.Roles.Contains(muteRole)
|| member.TimedOutUntil.GetValueOrDefault(DateTimeOffset.UnixEpoch).ToUnixTimeSeconds() > || member.TimedOutUntil.GetValueOrDefault(DateTimeOffset.UnixEpoch).ToUnixTimeSeconds() >
DateTimeOffset.Now.ToUnixTimeSeconds()) DateTimeOffset.Now.ToUnixTimeSeconds()) break;
break;
} }
await Task.WhenAll(_tasks); await Task.WhenAll(_tasks);
@ -77,10 +76,6 @@ public sealed class CommandProcessor {
foreach (var command in Commands) { foreach (var command in Commands) {
var lineNoMention = line.Remove(0, prefixed ? prefix.Length : Mention.Length); var lineNoMention = line.Remove(0, prefixed ? prefix.Length : Mention.Length);
if (!command.Aliases.Contains(lineNoMention.Trim().Split()[0])) continue; if (!command.Aliases.Contains(lineNoMention.Trim().Split()[0])) continue;
if (Utils.IsServerBlacklisted(Context.Guild)) {
_serverBlacklisted = true;
return;
}
var args = lineNoMention.Trim().Split().Skip(1).ToArray(); var args = lineNoMention.Trim().Split().Skip(1).ToArray();
var cleanArgs = cleanLine.Split().Skip(lineNoMention.StartsWith(" ") ? 2 : 1).ToArray(); var cleanArgs = cleanLine.Split().Skip(lineNoMention.StartsWith(" ") ? 2 : 1).ToArray();
@ -123,8 +118,7 @@ public sealed class CommandProcessor {
if (startIndex >= from.Length && argument != null) if (startIndex >= from.Length && argument != null)
Utils.SafeAppendToBuilder(_stackedReplyMessage, Utils.SafeAppendToBuilder(_stackedReplyMessage,
$"{MissingArgument}{Utils.GetMessage($"Missing{argument}")}", Context.Message); $"{MissingArgument}{Utils.GetMessage($"Missing{argument}")}", Context.Message);
else else return string.Join(" ", from, startIndex, from.Length - startIndex);
return string.Join(" ", from, startIndex, from.Length - startIndex);
return null; return null;
} }
@ -232,8 +226,7 @@ public sealed class CommandProcessor {
public static TimeSpan GetTimeSpan(string[] args, int index) { public static TimeSpan GetTimeSpan(string[] args, int index) {
var infinity = TimeSpan.FromMilliseconds(-1); var infinity = TimeSpan.FromMilliseconds(-1);
if (index >= args.Length) if (index >= args.Length) return infinity;
return infinity;
var chars = args[index].AsSpan(); var chars = args[index].AsSpan();
var numberBuilder = Boyfriend.StringBuilder; var numberBuilder = Boyfriend.StringBuilder;
int days = 0, hours = 0, minutes = 0, seconds = 0; int days = 0, hours = 0, minutes = 0, seconds = 0;

View file

@ -30,8 +30,7 @@ public static class EventHandler {
var channel = guild.GetTextChannel(Convert.ToUInt64(config["BotLogChannel"])); var channel = guild.GetTextChannel(Convert.ToUInt64(config["BotLogChannel"]));
Utils.SetCurrentLanguage(guild.Id); Utils.SetCurrentLanguage(guild.Id);
if (config["ReceiveStartupMessages"] is not "true" || channel == null || if (config["ReceiveStartupMessages"] is not "true" || channel == null) continue;
Utils.IsServerBlacklisted(guild)) continue;
_ = channel.SendMessageAsync(string.Format(Messages.Ready, Utils.GetBeep(i))); _ = channel.SendMessageAsync(string.Format(Messages.Ready, Utils.GetBeep(i)));
} }
@ -45,7 +44,6 @@ public static class EventHandler {
if (msg is null or ISystemMessage || msg.Author.IsBot) return; if (msg is null or ISystemMessage || msg.Author.IsBot) return;
var guild = Boyfriend.FindGuild(channel.Value.Id); var guild = Boyfriend.FindGuild(channel.Value.Id);
if (Utils.IsServerBlacklisted(guild)) return;
Utils.SetCurrentLanguage(guild.Id); Utils.SetCurrentLanguage(guild.Id);
@ -57,9 +55,9 @@ public static class EventHandler {
if (auditLogEntry.Data is MessageDeleteAuditLogData data && msg.Author.Id == data.Target.Id) if (auditLogEntry.Data is MessageDeleteAuditLogData data && msg.Author.Id == data.Target.Id)
mention = auditLogEntry.User.Mention; mention = auditLogEntry.User.Mention;
await Utils.SendFeedbackAsync( await Utils.SendFeedbackAsync(string.Format(Messages.CachedMessageDeleted, msg.Author.Mention,
string.Format(Messages.CachedMessageDeleted, msg.Author.Mention, Utils.MentionChannel(channel.Id), Utils.MentionChannel(channel.Id),
Utils.Wrap(msg.CleanContent)), guild.Id, mention); Utils.Wrap(msg.CleanContent)), guild.Id, mention);
} }
private static Task MessageReceivedEvent(SocketMessage messageParam) { private static Task MessageReceivedEvent(SocketMessage messageParam) {
@ -87,59 +85,55 @@ public static class EventHandler {
if (msg is null or ISystemMessage || msg.CleanContent == messageSocket.CleanContent || msg.Author.IsBot) return; if (msg is null or ISystemMessage || msg.CleanContent == messageSocket.CleanContent || msg.Author.IsBot) return;
var guild = Boyfriend.FindGuild(channel.Id); var guild = Boyfriend.FindGuild(channel.Id);
if (Utils.IsServerBlacklisted(guild)) return;
Utils.SetCurrentLanguage(guild.Id); Utils.SetCurrentLanguage(guild.Id);
var isLimitedSpace = msg.CleanContent.Length + messageSocket.CleanContent.Length < 1940; var isLimitedSpace = msg.CleanContent.Length + messageSocket.CleanContent.Length < 1940;
await Utils.SendFeedbackAsync( await Utils.SendFeedbackAsync(string.Format(Messages.CachedMessageEdited, Utils.MentionChannel(channel.Id),
string.Format(Messages.CachedMessageEdited, Utils.MentionChannel(channel.Id),
Utils.Wrap(msg.CleanContent, isLimitedSpace), Utils.Wrap(messageSocket.CleanContent, isLimitedSpace)), Utils.Wrap(msg.CleanContent, isLimitedSpace), Utils.Wrap(messageSocket.CleanContent, isLimitedSpace)),
guild.Id, msg.Author.Mention); guild.Id, msg.Author.Mention);
} }
private static async Task UserJoinedEvent(SocketGuildUser user) { private static async Task UserJoinedEvent(SocketGuildUser user) {
var guild = user.Guild; var guild = user.Guild;
if (Utils.IsServerBlacklisted(guild)) return;
var config = Boyfriend.GetGuildConfig(guild.Id); var config = Boyfriend.GetGuildConfig(guild.Id);
if (config["SendWelcomeMessages"] is "true") if (config["SendWelcomeMessages"] is "true")
await Utils.SilentSendAsync(guild.SystemChannel, await Utils.SilentSendAsync(guild.SystemChannel,
string.Format(config["WelcomeMessage"], user.Mention, guild.Name)); string.Format(config["WelcomeMessage"], user.Mention, guild.Name));
if (config["StarterRole"] is not "0") if (config["StarterRole"] is not "0") await user.AddRoleAsync(ulong.Parse(config["StarterRole"]));
await user.AddRoleAsync(ulong.Parse(config["StarterRole"]));
} }
private static async Task ScheduledEventCreatedEvent(SocketGuildEvent scheduledEvent) { private static async Task ScheduledEventCreatedEvent(SocketGuildEvent scheduledEvent) {
var guild = scheduledEvent.Guild; var guild = scheduledEvent.Guild;
if (Utils.IsServerBlacklisted(guild)) return;
var eventConfig = Boyfriend.GetGuildConfig(guild.Id); var eventConfig = Boyfriend.GetGuildConfig(guild.Id);
var channel = guild.GetTextChannel(Convert.ToUInt64(eventConfig["EventCreatedChannel"])); var channel = guild.GetTextChannel(Convert.ToUInt64(eventConfig["EventCreatedChannel"]));
if (channel != null) { if (channel != null) {
var roleMention = ""; var roleMention = "";
var role = guild.GetRole(Convert.ToUInt64(eventConfig["EventNotifyReceiverRole"])); var role = guild.GetRole(Convert.ToUInt64(eventConfig["EventNotifyReceiverRole"]));
if (role != null) if (role != null) roleMention = $"{role.Mention} ";
roleMention = $"{role.Mention} ";
var location = Utils.Wrap(scheduledEvent.Location) ?? Utils.MentionChannel(scheduledEvent.Channel.Id); var location = Utils.Wrap(scheduledEvent.Location) ?? Utils.MentionChannel(scheduledEvent.Channel.Id);
await Utils.SilentSendAsync(channel, await Utils.SilentSendAsync(channel,
string.Format(Messages.EventCreated, "\n", roleMention, scheduledEvent.Creator.Mention, string.Format(Messages.EventCreated, "\n", roleMention, scheduledEvent.Creator.Mention,
Utils.Wrap(scheduledEvent.Name), location, Utils.Wrap(scheduledEvent.Name), location,
scheduledEvent.StartTime.ToUnixTimeSeconds().ToString(), Utils.Wrap(scheduledEvent.Description), guild.Id, scheduledEvent.Id), scheduledEvent.StartTime.ToUnixTimeSeconds().ToString(), Utils.Wrap(scheduledEvent.Description),
guild.Id, scheduledEvent.Id),
true); true);
} }
if (eventConfig["EventEarlyNotificationOffset"] != "0") { if (eventConfig["EventEarlyNotificationOffset"] != "0") {
_ = Utils.SendEarlyEventStartNotificationAsync(channel, scheduledEvent, Convert.ToInt32(eventConfig["EventEarlyNotificationOffset"])); _ = Utils.SendEarlyEventStartNotificationAsync(channel, scheduledEvent,
Convert.ToInt32(eventConfig["EventEarlyNotificationOffset"]));
} }
} }
private static async Task ScheduledEventCancelledEvent(SocketGuildEvent scheduledEvent) { private static async Task ScheduledEventCancelledEvent(SocketGuildEvent scheduledEvent) {
var guild = scheduledEvent.Guild; var guild = scheduledEvent.Guild;
if (Utils.IsServerBlacklisted(guild)) return;
var eventConfig = Boyfriend.GetGuildConfig(guild.Id); var eventConfig = Boyfriend.GetGuildConfig(guild.Id);
var channel = guild.GetTextChannel(Convert.ToUInt64(eventConfig["EventCancelledChannel"])); var channel = guild.GetTextChannel(Convert.ToUInt64(eventConfig["EventCancelledChannel"]));
if (channel != null) if (channel != null)
@ -149,7 +143,6 @@ public static class EventHandler {
private static async Task ScheduledEventStartedEvent(SocketGuildEvent scheduledEvent) { private static async Task ScheduledEventStartedEvent(SocketGuildEvent scheduledEvent) {
var guild = scheduledEvent.Guild; var guild = scheduledEvent.Guild;
if (Utils.IsServerBlacklisted(guild)) return;
var eventConfig = Boyfriend.GetGuildConfig(guild.Id); var eventConfig = Boyfriend.GetGuildConfig(guild.Id);
var channel = guild.GetTextChannel(Convert.ToUInt64(eventConfig["EventStartedChannel"])); var channel = guild.GetTextChannel(Convert.ToUInt64(eventConfig["EventStartedChannel"]));
@ -172,7 +165,6 @@ public static class EventHandler {
private static async Task ScheduledEventCompletedEvent(SocketGuildEvent scheduledEvent) { private static async Task ScheduledEventCompletedEvent(SocketGuildEvent scheduledEvent) {
var guild = scheduledEvent.Guild; var guild = scheduledEvent.Guild;
if (Utils.IsServerBlacklisted(guild)) return;
var eventConfig = Boyfriend.GetGuildConfig(guild.Id); var eventConfig = Boyfriend.GetGuildConfig(guild.Id);
var channel = guild.GetTextChannel(Convert.ToUInt64(eventConfig["EventCompletedChannel"])); var channel = guild.GetTextChannel(Convert.ToUInt64(eventConfig["EventCompletedChannel"]));
if (channel != null) if (channel != null)

View file

@ -59,8 +59,7 @@ public static class Utils {
public static async Task SendDirectMessage(SocketUser user, string toSend) { public static async Task SendDirectMessage(SocketUser user, string toSend) {
try { await user.SendMessageAsync(toSend); } catch (HttpException e) { try { await user.SendMessageAsync(toSend); } catch (HttpException e) {
if (e.DiscordCode != DiscordErrorCode.CannotSendMessageToUser) if (e.DiscordCode != DiscordErrorCode.CannotSendMessageToUser) throw;
throw;
} }
} }
@ -117,10 +116,8 @@ public static class Utils {
var adminChannel = GetAdminLogChannel(guildId); var adminChannel = GetAdminLogChannel(guildId);
var systemChannel = Boyfriend.Client.GetGuild(guildId).SystemChannel; var systemChannel = Boyfriend.Client.GetGuild(guildId).SystemChannel;
var toSend = string.Format(Messages.FeedbackFormat, mention, feedback); var toSend = string.Format(Messages.FeedbackFormat, mention, feedback);
if (adminChannel != null) if (adminChannel != null) await SilentSendAsync(adminChannel, toSend);
await SilentSendAsync(adminChannel, toSend); if (sendPublic && systemChannel != null) await SilentSendAsync(systemChannel, toSend);
if (sendPublic && systemChannel != null)
await SilentSendAsync(systemChannel, toSend);
} }
public static string GetHumanizedTimeOffset(TimeSpan span) { public static string GetHumanizedTimeOffset(TimeSpan span) {
@ -163,13 +160,10 @@ public static class Utils {
await UnmuteCommand.UnmuteMemberAsync(cmd, muted, reason); await UnmuteCommand.UnmuteMemberAsync(cmd, muted, reason);
} }
public static bool IsServerBlacklisted(SocketGuild guild) { public static async Task SendEarlyEventStartNotificationAsync(SocketTextChannel? channel,
return guild.GetUser(196160375593369600) != null && guild.OwnerId != 326642240229474304 && SocketGuildEvent scheduledEvent, int minuteOffset) {
guild.OwnerId != 504343489664909322; await Task.Delay(scheduledEvent.StartTime.Subtract(DateTimeOffset.Now)
} .Subtract(TimeSpan.FromMinutes(minuteOffset)));
public static async Task SendEarlyEventStartNotificationAsync(SocketTextChannel? channel, SocketGuildEvent scheduledEvent, int minuteOffset) {
await Task.Delay(scheduledEvent.StartTime.Subtract(DateTimeOffset.Now).Subtract(TimeSpan.FromMinutes(minuteOffset)));
var guild = scheduledEvent.Guild; var guild = scheduledEvent.Guild;
if (guild.GetEvent(scheduledEvent.Id) is null) return; if (guild.GetEvent(scheduledEvent.Id) is null) return;
var eventConfig = Boyfriend.GetGuildConfig(guild.Id); var eventConfig = Boyfriend.GetGuildConfig(guild.Id);
@ -182,7 +176,8 @@ public static class Utils {
if (receivers.Contains("users") || receivers.Contains("interested")) if (receivers.Contains("users") || receivers.Contains("interested"))
mentions = (await scheduledEvent.GetUsersAsync(15)).Aggregate(mentions, mentions = (await scheduledEvent.GetUsersAsync(15)).Aggregate(mentions,
(current, user) => current.Append($"{user.Mention} ")); (current, user) => current.Append($"{user.Mention} "));
await channel?.SendMessageAsync(string.Format(Messages.EventEarlyNotification, mentions, Wrap(scheduledEvent.Name), scheduledEvent.StartTime.ToUnixTimeSeconds()))!; await channel?.SendMessageAsync(string.Format(Messages.EventEarlyNotification, mentions,
Wrap(scheduledEvent.Name), scheduledEvent.StartTime.ToUnixTimeSeconds()))!;
mentions.Clear(); mentions.Clear();
} }
} }