1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-01-31 09:09:00 +03:00

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
if (member == null || member.Roles.Contains(muteRole)
|| member.TimedOutUntil.GetValueOrDefault(DateTimeOffset.UnixEpoch).ToUnixTimeSeconds() >
DateTimeOffset.Now.ToUnixTimeSeconds())
break;
DateTimeOffset.Now.ToUnixTimeSeconds()) break;
}
await Task.WhenAll(_tasks);
@ -77,10 +76,6 @@ public sealed class CommandProcessor {
foreach (var command in Commands) {
var lineNoMention = line.Remove(0, prefixed ? prefix.Length : Mention.Length);
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 cleanArgs = cleanLine.Split().Skip(lineNoMention.StartsWith(" ") ? 2 : 1).ToArray();
@ -123,8 +118,7 @@ public sealed class CommandProcessor {
if (startIndex >= from.Length && argument != null)
Utils.SafeAppendToBuilder(_stackedReplyMessage,
$"{MissingArgument}{Utils.GetMessage($"Missing{argument}")}", Context.Message);
else
return string.Join(" ", from, startIndex, from.Length - startIndex);
else return string.Join(" ", from, startIndex, from.Length - startIndex);
return null;
}
@ -232,8 +226,7 @@ public sealed class CommandProcessor {
public static TimeSpan GetTimeSpan(string[] args, int index) {
var infinity = TimeSpan.FromMilliseconds(-1);
if (index >= args.Length)
return infinity;
if (index >= args.Length) return infinity;
var chars = args[index].AsSpan();
var numberBuilder = Boyfriend.StringBuilder;
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"]));
Utils.SetCurrentLanguage(guild.Id);
if (config["ReceiveStartupMessages"] is not "true" || channel == null ||
Utils.IsServerBlacklisted(guild)) continue;
if (config["ReceiveStartupMessages"] is not "true" || channel == null) continue;
_ = 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;
var guild = Boyfriend.FindGuild(channel.Value.Id);
if (Utils.IsServerBlacklisted(guild)) return;
Utils.SetCurrentLanguage(guild.Id);
@ -57,8 +55,8 @@ public static class EventHandler {
if (auditLogEntry.Data is MessageDeleteAuditLogData data && msg.Author.Id == data.Target.Id)
mention = auditLogEntry.User.Mention;
await Utils.SendFeedbackAsync(
string.Format(Messages.CachedMessageDeleted, msg.Author.Mention, Utils.MentionChannel(channel.Id),
await Utils.SendFeedbackAsync(string.Format(Messages.CachedMessageDeleted, msg.Author.Mention,
Utils.MentionChannel(channel.Id),
Utils.Wrap(msg.CleanContent)), guild.Id, mention);
}
@ -87,59 +85,55 @@ public static class EventHandler {
if (msg is null or ISystemMessage || msg.CleanContent == messageSocket.CleanContent || msg.Author.IsBot) return;
var guild = Boyfriend.FindGuild(channel.Id);
if (Utils.IsServerBlacklisted(guild)) return;
Utils.SetCurrentLanguage(guild.Id);
var isLimitedSpace = msg.CleanContent.Length + messageSocket.CleanContent.Length < 1940;
await Utils.SendFeedbackAsync(
string.Format(Messages.CachedMessageEdited, Utils.MentionChannel(channel.Id),
await Utils.SendFeedbackAsync(string.Format(Messages.CachedMessageEdited, Utils.MentionChannel(channel.Id),
Utils.Wrap(msg.CleanContent, isLimitedSpace), Utils.Wrap(messageSocket.CleanContent, isLimitedSpace)),
guild.Id, msg.Author.Mention);
}
private static async Task UserJoinedEvent(SocketGuildUser user) {
var guild = user.Guild;
if (Utils.IsServerBlacklisted(guild)) return;
var config = Boyfriend.GetGuildConfig(guild.Id);
if (config["SendWelcomeMessages"] is "true")
await Utils.SilentSendAsync(guild.SystemChannel,
string.Format(config["WelcomeMessage"], user.Mention, guild.Name));
if (config["StarterRole"] is not "0")
await user.AddRoleAsync(ulong.Parse(config["StarterRole"]));
if (config["StarterRole"] is not "0") await user.AddRoleAsync(ulong.Parse(config["StarterRole"]));
}
private static async Task ScheduledEventCreatedEvent(SocketGuildEvent scheduledEvent) {
var guild = scheduledEvent.Guild;
if (Utils.IsServerBlacklisted(guild)) return;
var eventConfig = Boyfriend.GetGuildConfig(guild.Id);
var channel = guild.GetTextChannel(Convert.ToUInt64(eventConfig["EventCreatedChannel"]));
if (channel != null) {
var roleMention = "";
var role = guild.GetRole(Convert.ToUInt64(eventConfig["EventNotifyReceiverRole"]));
if (role != null)
roleMention = $"{role.Mention} ";
if (role != null) roleMention = $"{role.Mention} ";
var location = Utils.Wrap(scheduledEvent.Location) ?? Utils.MentionChannel(scheduledEvent.Channel.Id);
await Utils.SilentSendAsync(channel,
string.Format(Messages.EventCreated, "\n", roleMention, scheduledEvent.Creator.Mention,
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);
}
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) {
var guild = scheduledEvent.Guild;
if (Utils.IsServerBlacklisted(guild)) return;
var eventConfig = Boyfriend.GetGuildConfig(guild.Id);
var channel = guild.GetTextChannel(Convert.ToUInt64(eventConfig["EventCancelledChannel"]));
if (channel != null)
@ -149,7 +143,6 @@ public static class EventHandler {
private static async Task ScheduledEventStartedEvent(SocketGuildEvent scheduledEvent) {
var guild = scheduledEvent.Guild;
if (Utils.IsServerBlacklisted(guild)) return;
var eventConfig = Boyfriend.GetGuildConfig(guild.Id);
var channel = guild.GetTextChannel(Convert.ToUInt64(eventConfig["EventStartedChannel"]));
@ -172,7 +165,6 @@ public static class EventHandler {
private static async Task ScheduledEventCompletedEvent(SocketGuildEvent scheduledEvent) {
var guild = scheduledEvent.Guild;
if (Utils.IsServerBlacklisted(guild)) return;
var eventConfig = Boyfriend.GetGuildConfig(guild.Id);
var channel = guild.GetTextChannel(Convert.ToUInt64(eventConfig["EventCompletedChannel"]));
if (channel != null)

View file

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