mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-05-16 02:36:07 +03:00
Reduce indenting, fix critical bug with private feedback being public and vice versa
Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
parent
6f5a969704
commit
0bdf2cd33e
3 changed files with 166 additions and 116 deletions
121
EventHandler.cs
121
EventHandler.cs
|
@ -7,8 +7,8 @@ using Discord.WebSocket;
|
|||
namespace Boyfriend;
|
||||
|
||||
public static class EventHandler {
|
||||
private static readonly DiscordSocketClient Client = Boyfriend.Client;
|
||||
private static bool _sendReadyMessages = true;
|
||||
private static readonly DiscordSocketClient Client = Boyfriend.Client;
|
||||
private static bool _sendReadyMessages = true;
|
||||
|
||||
public static void InitEvents() {
|
||||
Client.Ready += ReadyEvent;
|
||||
|
@ -49,11 +49,13 @@ public static class EventHandler {
|
|||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private static async Task MessageDeletedEvent(Cacheable<IMessage, ulong> message,
|
||||
private static async Task MessageDeletedEvent(
|
||||
Cacheable<IMessage, ulong> message,
|
||||
Cacheable<IMessageChannel, ulong> channel) {
|
||||
var msg = message.Value;
|
||||
if (channel.Value is not SocketGuildChannel gChannel || msg is null or ISystemMessage ||
|
||||
msg.Author.IsBot) return;
|
||||
if (channel.Value is not SocketGuildChannel gChannel
|
||||
|| msg is null or ISystemMessage
|
||||
|| msg.Author.IsBot) return;
|
||||
|
||||
var guild = gChannel.Guild;
|
||||
|
||||
|
@ -64,22 +66,25 @@ public static class EventHandler {
|
|||
await Task.Delay(500);
|
||||
|
||||
var auditLogEntry = (await guild.GetAuditLogsAsync(1).FlattenAsync()).First();
|
||||
if (auditLogEntry.CreatedAt >= DateTimeOffset.Now.Subtract(TimeSpan.FromSeconds(1)) &&
|
||||
auditLogEntry.Data is MessageDeleteAuditLogData data && msg.Author.Id == data.Target.Id)
|
||||
if (auditLogEntry.CreatedAt >= DateTimeOffset.Now.Subtract(TimeSpan.FromSeconds(1))
|
||||
&& 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),
|
||||
Utils.Wrap(msg.CleanContent)), guild, mention);
|
||||
await Utils.SendFeedbackAsync(
|
||||
string.Format(
|
||||
Messages.CachedMessageDeleted, msg.Author.Mention,
|
||||
Utils.MentionChannel(channel.Id),
|
||||
Utils.Wrap(msg.CleanContent)), guild, mention);
|
||||
}
|
||||
|
||||
private static Task MessageReceivedEvent(IDeletable messageParam) {
|
||||
if (messageParam is not SocketUserMessage message) return Task.CompletedTask;
|
||||
|
||||
_ = message.CleanContent.ToLower() switch {
|
||||
"whoami" => message.ReplyAsync("`nobody`"),
|
||||
"whoami" => message.ReplyAsync("`nobody`"),
|
||||
"сука !!" => message.ReplyAsync("`root`"),
|
||||
"воооо" => message.ReplyAsync("`removing /...`"),
|
||||
"воооо" => message.ReplyAsync("`removing /...`"),
|
||||
"op ??" => message.ReplyAsync(
|
||||
"некоторые пасхальные цитаты которые вы могли найти были легально взяты у <@573772175572729876>"),
|
||||
_ => new CommandProcessor(message).HandleCommandAsync()
|
||||
|
@ -87,18 +92,23 @@ public static class EventHandler {
|
|||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private static async Task MessageUpdatedEvent(Cacheable<IMessage, ulong> messageCached, IMessage messageSocket,
|
||||
ISocketMessageChannel channel) {
|
||||
private static async Task MessageUpdatedEvent(
|
||||
Cacheable<IMessage, ulong> messageCached, IMessage messageSocket,
|
||||
ISocketMessageChannel channel) {
|
||||
var msg = messageCached.Value;
|
||||
if (channel is not SocketGuildChannel gChannel || msg is null or ISystemMessage ||
|
||||
msg.CleanContent == messageSocket.CleanContent || msg.Author.IsBot) return;
|
||||
if (channel is not SocketGuildChannel gChannel
|
||||
|| msg is null or ISystemMessage
|
||||
|| msg.CleanContent == messageSocket.CleanContent
|
||||
|| msg.Author.IsBot) return;
|
||||
|
||||
var guild = gChannel.Guild;
|
||||
Utils.SetCurrentLanguage(guild);
|
||||
|
||||
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, msg.Author.Mention);
|
||||
}
|
||||
|
@ -111,10 +121,12 @@ public static class EventHandler {
|
|||
Utils.SetCurrentLanguage(guild);
|
||||
|
||||
if (config["SendWelcomeMessages"] is "true" && data.PublicFeedbackChannel is not null)
|
||||
await Utils.SilentSendAsync(data.PublicFeedbackChannel,
|
||||
string.Format(config["WelcomeMessage"] is "default"
|
||||
? Messages.DefaultWelcomeMessage
|
||||
: config["WelcomeMessage"], user.Mention, guild.Name));
|
||||
await Utils.SilentSendAsync(
|
||||
data.PublicFeedbackChannel,
|
||||
string.Format(
|
||||
config["WelcomeMessage"] is "default"
|
||||
? Messages.DefaultWelcomeMessage
|
||||
: config["WelcomeMessage"], user.Mention, guild.Name));
|
||||
|
||||
if (config["StarterRole"] is not "0") await user.AddRoleAsync(ulong.Parse(config["StarterRole"]));
|
||||
|
||||
|
@ -148,23 +160,24 @@ public static class EventHandler {
|
|||
var eventConfig = GuildData.Get(guild).Preferences;
|
||||
var channel = Utils.GetEventNotificationChannel(guild);
|
||||
Utils.SetCurrentLanguage(guild);
|
||||
if (channel is null) return;
|
||||
|
||||
if (channel is not null) {
|
||||
var role = guild.GetRole(ulong.Parse(eventConfig["EventNotificationRole"]));
|
||||
var mentions = role is not null
|
||||
? $"{role.Mention} {scheduledEvent.Creator.Mention}"
|
||||
: $"{scheduledEvent.Creator.Mention}";
|
||||
var role = guild.GetRole(ulong.Parse(eventConfig["EventNotificationRole"]));
|
||||
var mentions = role is not null
|
||||
? $"{role.Mention} {scheduledEvent.Creator.Mention}"
|
||||
: $"{scheduledEvent.Creator.Mention}";
|
||||
|
||||
var location = Utils.Wrap(scheduledEvent.Location) ?? Utils.MentionChannel(scheduledEvent.Channel.Id);
|
||||
var descAndLink
|
||||
= $"\n{Utils.Wrap(scheduledEvent.Description)}\nhttps://discord.com/events/{guild.Id}/{scheduledEvent.Id}";
|
||||
var location = Utils.Wrap(scheduledEvent.Location) ?? Utils.MentionChannel(scheduledEvent.Channel.Id);
|
||||
var descAndLink
|
||||
= $"\n{Utils.Wrap(scheduledEvent.Description)}\nhttps://discord.com/events/{guild.Id}/{scheduledEvent.Id}";
|
||||
|
||||
await Utils.SilentSendAsync(channel,
|
||||
string.Format(Messages.EventCreated, mentions,
|
||||
Utils.Wrap(scheduledEvent.Name), location,
|
||||
scheduledEvent.StartTime.ToUnixTimeSeconds().ToString(), descAndLink),
|
||||
true);
|
||||
}
|
||||
await Utils.SilentSendAsync(
|
||||
channel,
|
||||
string.Format(
|
||||
Messages.EventCreated, mentions,
|
||||
Utils.Wrap(scheduledEvent.Name), location,
|
||||
scheduledEvent.StartTime.ToUnixTimeSeconds().ToString(), descAndLink),
|
||||
true);
|
||||
}
|
||||
|
||||
private static async Task ScheduledEventCancelledEvent(SocketGuildEvent scheduledEvent) {
|
||||
|
@ -173,8 +186,10 @@ public static class EventHandler {
|
|||
var channel = Utils.GetEventNotificationChannel(guild);
|
||||
Utils.SetCurrentLanguage(guild);
|
||||
if (channel is not null)
|
||||
await channel.SendMessageAsync(string.Format(Messages.EventCancelled, Utils.Wrap(scheduledEvent.Name),
|
||||
eventConfig["FrowningFace"] is "true" ? $" {Messages.SettingsFrowningFace}" : ""));
|
||||
await channel.SendMessageAsync(
|
||||
string.Format(
|
||||
Messages.EventCancelled, Utils.Wrap(scheduledEvent.Name),
|
||||
eventConfig["FrowningFace"] is "true" ? $" {Messages.SettingsFrowningFace}" : ""));
|
||||
}
|
||||
|
||||
private static async Task ScheduledEventStartedEvent(SocketGuildEvent scheduledEvent) {
|
||||
|
@ -183,22 +198,24 @@ public static class EventHandler {
|
|||
var channel = Utils.GetEventNotificationChannel(guild);
|
||||
Utils.SetCurrentLanguage(guild);
|
||||
|
||||
if (channel is not null) {
|
||||
var receivers = eventConfig["EventStartedReceivers"];
|
||||
var role = guild.GetRole(ulong.Parse(eventConfig["EventNotificationRole"]));
|
||||
var mentions = Boyfriend.StringBuilder;
|
||||
if (channel is null) return;
|
||||
|
||||
if (receivers.Contains("role") && role is not null) mentions.Append($"{role.Mention} ");
|
||||
if (receivers.Contains("users") || receivers.Contains("interested"))
|
||||
mentions = (await scheduledEvent.GetUsersAsync(15))
|
||||
.Where(user => role is null || !((RestGuildUser)user).RoleIds.Contains(role.Id))
|
||||
.Aggregate(mentions, (current, user) => current.Append($"{user.Mention} "));
|
||||
var receivers = eventConfig["EventStartedReceivers"];
|
||||
var role = guild.GetRole(ulong.Parse(eventConfig["EventNotificationRole"]));
|
||||
var mentions = Boyfriend.StringBuilder;
|
||||
|
||||
await channel.SendMessageAsync(string.Format(Messages.EventStarted, mentions,
|
||||
if (receivers.Contains("role") && role is not null) mentions.Append($"{role.Mention} ");
|
||||
if (receivers.Contains("users") || receivers.Contains("interested"))
|
||||
mentions = (await scheduledEvent.GetUsersAsync(15))
|
||||
.Where(user => role is null || !((RestGuildUser)user).RoleIds.Contains(role.Id))
|
||||
.Aggregate(mentions, (current, user) => current.Append($"{user.Mention} "));
|
||||
|
||||
await channel.SendMessageAsync(
|
||||
string.Format(
|
||||
Messages.EventStarted, mentions,
|
||||
Utils.Wrap(scheduledEvent.Name),
|
||||
Utils.Wrap(scheduledEvent.Location) ?? Utils.MentionChannel(scheduledEvent.Channel.Id)));
|
||||
mentions.Clear();
|
||||
}
|
||||
mentions.Clear();
|
||||
}
|
||||
|
||||
private static async Task ScheduledEventCompletedEvent(SocketGuildEvent scheduledEvent) {
|
||||
|
@ -206,7 +223,9 @@ public static class EventHandler {
|
|||
var channel = Utils.GetEventNotificationChannel(guild);
|
||||
Utils.SetCurrentLanguage(guild);
|
||||
if (channel is not null)
|
||||
await channel.SendMessageAsync(string.Format(Messages.EventCompleted, Utils.Wrap(scheduledEvent.Name),
|
||||
Utils.GetHumanizedTimeSpan(DateTimeOffset.Now.Subtract(scheduledEvent.StartTime))));
|
||||
await channel.SendMessageAsync(
|
||||
string.Format(
|
||||
Messages.EventCompleted, Utils.Wrap(scheduledEvent.Name),
|
||||
Utils.GetHumanizedTimeSpan(DateTimeOffset.Now.Subtract(scheduledEvent.StartTime))));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue