private async Task BlacklistUserAsync(SocketGuildUser user, TimeSpan timeSpan) { try { if (await DiscordContextSeymour.IsUserDevOrAdminAsync(user as SocketGuildUser)) { return; } bool existing = await StorageManager.StoreBlacklistReturnIfExisting(new BlacklistUserStorage() { Username = user.Username, DateInserted = DateTime.UtcNow, ModeratorID = Context.Message.Author.Id, DateToRemove = (DateTimeOffset.UtcNow + timeSpan).DateTime, UserID = user.Id }, new UserStorage() { UserID = user.Id, UserName = user.Username, }); var embed = Utilities.BuildBlacklistEmbed(timeSpan, user.Username, existing, Context.Message.Author.Username); await Context.Channel.SendMessageAsync("", false, embed); await DiscordContextOverseer.LogModerationAction(user.Id, "Blacklisted", Context.Message.Author.Id, "", timeSpan.ToString()); } catch (Exception ex) { ExceptionManager.HandleException(ErrMessages.BlacklistException, ex); } }
public static async Task MassMentionCheck(SocketCommandContext context) { try { if (context.Message.MentionedUsers.Count > 8) { SocketUser target = context.Message.Author; await context.Message.DeleteAsync(); await DiscordContextSeymour.AddRole(DiscordContextSeymour.GrabRole(MordhauRoleEnum.Muted), target.Id); await DiscordContextOverseer.LogModerationAction(target.Id, "Muted", "excessive pinging", Utilities.ShortTimeSpanFormatting(new TimeSpan(3, 0, 0, 0))); await TimedEventManager.CreateEvent(DisciplinaryEventEnum.MuteEvent, context.Client.CurrentUser.Id, "excessive pinging", target.Id, target.Username, (DateTimeOffset.UtcNow + new TimeSpan(0, 30, 0)).DateTime); await TimedEventManager.CreateEvent(DisciplinaryEventEnum.WarnEvent, context.Client.CurrentUser.Id, "AutoWarn : excessive pinging", target.Id, target.Username, DateTime.UtcNow.AddDays(ConfigManager.GetIntegerProperty(PropertyItem.WarnDuration))); if (context.Channel != null) { await DiscordContextOverseer.GetChannel(context.Channel.Id).SendMessageAsync($"{context.Message.Author.Mention}, Thou shall not say thy noble's names in vain. {DiscordContextSeymour.GetEmoteAyySeymour()}"); } } } catch (Exception ex) { ExceptionManager.HandleException($"{typeof(AutoModeratorManager).GetType().FullName}: {ExceptionManager.GetAsyncMethodName()}", ex); } }
private async Task UnblacklistUserAsync(ulong userID) { try { SocketGuildUser user = await Context.Channel.GetUserAsync(userID) as SocketGuildUser; if (user == null) { await Context.Channel.SendMessageAsync($"Unable to locate user {DiscordContextSeymour.GetEmoteAyySeymour()}"); return; } bool existing = await StorageManager.RemoveBlacklist(user.Id); if (existing) { var embed = Utilities.BuildRemoveDisciplinaryEmbed("Successfully unblacklisted", user.Username); await Context.Channel.SendMessageAsync("", false, embed); } else { await Context.Channel.SendMessageAsync("Could not find that user within the blacklist"); } await DiscordContextOverseer.LogModerationAction(user.Id, "Unblacklisted", Context.Message.Author.Id, "", ""); } catch (Exception ex) { ExceptionManager.HandleException(ErrMessages.UnblacklistException, ex); } }
private async Task UnrestrictUserAsync(ulong userID) { try { SocketGuildUser user = Context.Guild.GetUser(userID); if (user == null) { await Context.Channel.SendMessageAsync($"Unable to locate user {DiscordContextSeymour.GetEmoteAyySeymour()}"); return; } var role = user.Roles.FirstOrDefault(x => x.Id == ConfigManager.GetUlongProperty(PropertyItem.Role_Restricted)); if (role != null) { await Context.Channel.SendMessageAsync("Cannot see restricted role on that user"); return; } await user.RemoveRoleAsync(role); var embed = Utilities.BuildRemoveDisciplinaryEmbed($"Successfully unrestricted", user.Username); await Context.Channel.SendMessageAsync("", false, embed); await StorageManager.RemoveDisciplinaryEventAsync(userID, DisciplinaryEventEnum.RestrictedUserEvent); await DiscordContextOverseer.LogModerationAction(userID, "Unrestricted", Context.Message.Author.Id, "", ""); } catch (Exception ex) { ExceptionManager.HandleException(ErrMessages.UnlimitException, ex); } }
private async Task UnmuteUserAsync(SocketGuildUser user) { try { var role = user.Roles.FirstOrDefault(x => x.Id == ConfigManager.GetUlongProperty(PropertyItem.Role_Muted)); if (role == null) { await Context.Channel.SendMessageAsync("Cannot see muted role on that user"); return; } await user.RemoveRoleAsync(role); var embed = Utilities.BuildRemoveDisciplinaryEmbed($"Successfully unmuted", user.Username); await Context.Channel.SendMessageAsync("", false, embed); await StorageManager.RemoveDisciplinaryEventAsync(user.Id, DisciplinaryEventEnum.MuteEvent); await DiscordContextOverseer.LogModerationAction(user.Id, "Unmuted", Context.Message.Author.Id, "", ""); } catch (Exception ex) { ExceptionManager.HandleException(ErrMessages.UnmuteException, ex); } }
private async Task ExileUserAsync(ulong userID) { try { SocketGuildUser user = Context.Guild.GetUser(userID); if (await DiscordContextSeymour.IsUserDevOrAdminAsync(user as SocketGuildUser)) { return; } ulong peasantRoleID = ConfigManager.GetUlongProperty(PropertyItem.Role_Peasant); var roleToApply = Context.Guild.GetRole(peasantRoleID); var rolesToRemove = user.Roles.Where(x => x.IsEveryone == false); var embed = new EmbedBuilder(); embed.WithTitle($"{user.Username} has been stripped of their lands and titles, and banished to the gate {DiscordContextSeymour.GetEmoteReee()}"); embed.WithColor(new Color(255, 0, 0)); await Context.Channel.SendMessageAsync("", false, embed.Build()); await user.RemoveRolesAsync(rolesToRemove); await user.AddRoleAsync(roleToApply); await DiscordContextOverseer.LogModerationAction(userID, "Exiled", Context.Message.Author.Id, "", ""); } catch (Exception ex) { ExceptionManager.HandleException(ErrMessages.ExileException, ex); } }
public static async Task VerifyUserAsync(Cacheable <IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction) { try { if (DiscordContextOverseer.GetNoobGateChannel().Id == channel.Id) { if (message.Id == DiscordContextSeymour.GetNoobGateWelcome().Id) { if (reaction.Emote.Name == DiscordContextOverseer.GetEmotePommel().Name) { SocketGuildUser user = reaction.User.Value as SocketGuildUser; if (user != null) { var roleToRemove = DiscordContextOverseer.GrabRole(MordhauRoleEnum.Peasant); if (user.Roles.Any(x => x.Id == roleToRemove.Id) || roleToRemove != null) { await user.RemoveRoleAsync(roleToRemove); } } } } } } catch (Exception ex) { ExceptionManager.HandleException(ErrMessages.UserVerifyException, ex); } }
public static async Task CheckForWarnThreshold(SocketGuildUser target, SocketCommandContext context, int warnCount, ITextChannel chnl = null) { try { if (warnCount >= (ConfigManager.GetIntegerProperty(PropertyItem.MaxWarns))) //more or equal the warn thresold { await DiscordContextSeymour.AddRole(DiscordContextSeymour.GrabRole(MordhauRoleEnum.Muted), target.Id); await DiscordContextOverseer.LogModerationAction(target.Id, "Muted", $"User has been warned {warnCount} times, exceeding the {ConfigManager.GetIntegerProperty(PropertyItem.MaxWarns)} warn threshold", Utilities.ShortTimeSpanFormatting(new TimeSpan(1, 0, 0, 0))); await TimedEventManager.CreateEvent(DisciplinaryEventEnum.MuteEvent, context.Client.CurrentUser.Id, $"User has been warned {warnCount} times, exceeding the {ConfigManager.GetIntegerProperty(PropertyItem.MaxWarns)} warn threshold", target.Id, target.Username, (DateTimeOffset.UtcNow + new TimeSpan(1, 0, 0, 0)).DateTime); if (chnl == null) { await DiscordContextOverseer.GetChannel(context.Channel.Id).SendMessageAsync($"Silence. {target.Mention}"); } else { await DiscordContextOverseer.GetChannel(chnl.Id).SendMessageAsync($"Silence. {target.Mention}"); } } else if (warnCount > (ConfigManager.GetIntegerProperty(PropertyItem.MaxWarns) / 2)) //more than half the warn thresold { await DiscordContextSeymour.AddRole(DiscordContextSeymour.GrabRole(MordhauRoleEnum.Muted), target.Id); await DiscordContextOverseer.LogModerationAction(target.Id, "Muted", $"User has been warned {warnCount} times, exceeding half of the {ConfigManager.GetIntegerProperty(PropertyItem.MaxWarns)} warn threshold", Utilities.ShortTimeSpanFormatting(new TimeSpan(0, 30, 0))); await TimedEventManager.CreateEvent(DisciplinaryEventEnum.MuteEvent, context.Client.CurrentUser.Id, $"User has been warned {warnCount} times, exceeding half of the {ConfigManager.GetIntegerProperty(PropertyItem.MaxWarns)} warn threshold", target.Id, target.Username, (DateTimeOffset.UtcNow + new TimeSpan(0, 30, 0)).DateTime); if (chnl == null) //channel specified check { await DiscordContextOverseer.GetChannel(context.Channel.Id).SendMessageAsync($"{target.Mention}, enough."); } else { await DiscordContextOverseer.GetChannel(chnl.Id).SendMessageAsync($"{target.Mention}, enough."); } } } catch (Exception ex) { ExceptionManager.HandleException(ErrMessages.CheckForWarnThresholdException, ex); } }
public static async Task LogExceptionAsync(string message, Exception ex) { try { HandleExceptionHelper(ex, message); } catch (Exception e) { await DiscordContextOverseer.LogErrorAsync(e.Message); } }
public static async Task ApplyPeasantRoleAsync(SocketGuildUser user) { try { await user.AddRoleAsync(DiscordContextOverseer.GrabRole(MordhauRoleEnum.Peasant)); } catch (Exception ex) { ExceptionManager.HandleException($"{typeof(RoleApplication).GetType().FullName}: {ExceptionManager.GetAsyncMethodName()}", ex); } }
private static async Task HandleEventElapsed(ActiveTimedEvent activeEvent) { try { switch (activeEvent.DisciplinaryEvent) { case DisciplinaryEventEnum.MuteEvent: ActiveEvents.Remove(activeEvent); await DiscordContextSeymour.RemoveRoleAsync(activeEvent.UserId, ConfigManager.GetUlongProperty(PropertyItem.Role_Muted)); await DiscordContextOverseer.LogModerationAction(activeEvent.UserId, "Unmuted", activeEvent.Reason, ""); await StorageManager.ArchiveTimedEventAsync(activeEvent.DisciplinaryEventId); break; case DisciplinaryEventEnum.WarnEvent: ActiveEvents.Remove(activeEvent); await StorageManager.ArchiveTimedEventAsync(activeEvent.DisciplinaryEventId); break; case DisciplinaryEventEnum.LimitedUserEvent: ActiveEvents.Remove(activeEvent); await DiscordContextSeymour.RemoveRoleAsync(activeEvent.UserId, ConfigManager.GetUlongProperty(PropertyItem.Role_LimitedUser)); await DiscordContextOverseer.LogModerationAction(activeEvent.UserId, "Unlimited", activeEvent.Reason, ""); await StorageManager.ArchiveTimedEventAsync(activeEvent.DisciplinaryEventId); break; case DisciplinaryEventEnum.RestrictedUserEvent: ActiveEvents.Remove(activeEvent); await DiscordContextSeymour.RemoveRoleAsync(activeEvent.UserId, ConfigManager.GetUlongProperty(PropertyItem.Role_Restricted)); await DiscordContextOverseer.LogModerationAction(activeEvent.UserId, "Unrestricted", activeEvent.Reason, ""); await StorageManager.ArchiveTimedEventAsync(activeEvent.DisciplinaryEventId); break; default: ActiveEvents.Remove(activeEvent); await DiscordContextOverseer.LogModerationAction(activeEvent.UserId, $"Err : {activeEvent.DisciplinaryEvent.ToString()}", activeEvent.Reason, ""); break; } } catch (Exception ex) { await ExceptionManager.LogExceptionAsync(ex); } }
public static async Task ReceivedMessageEvent(SocketMessage arg) { if (arg.Channel.Id != DiscordContextOverseer.GetLoggingChannel().Id) //avoid caching images the bot is posting { var names = new List <string>(); var result = GetImageUrls(arg, out names); if (result != null) { await ImageCacheManager.CacheImageAsync(result, names, arg.Id); } } }
private async Task InitializeContext() { try { DiscordContextOverseer.InitContext(_client); } catch (Exception ex) { Console.WriteLine("Unable to intialize Overseer's discord context: ", ex.Message); throw; } }
public static async Task EnforceRestricted(SocketCommandContext context) { try { if (new Regex(@"(http(s)?:\/\/)?([a-z][-\w]+(?:\.\w+)+(?:\S+)?)", RegexOptions.IgnoreCase | RegexOptions.Compiled).IsMatch(context.Message.Content)) { await context.Message.DeleteAsync(); await DiscordContextOverseer.LogModerationAction(context.Message.Author.Id, "Blocked from posting a link", $"posting links while restricted in message id : {context.Message.Id}", ""); } } catch (Exception ex) { ExceptionManager.HandleException($"{typeof(AutoModeratorManager).GetType().FullName}: {ExceptionManager.GetAsyncMethodName()}", ex); } }
private async Task MuteUserAsync(ulong userID, TimeSpan timeSpan, [Remainder] string reason = "no reason specified") { try { SocketGuildUser user = Context.Guild.GetUser(userID); if (user == null) { await Context.Channel.SendMessageAsync($"Unable to locate user {DiscordContextSeymour.GetEmoteAyySeymour()}"); return; } if (await DiscordContextSeymour.IsUserDevOrAdminAsync(user as SocketGuildUser)) { return; } var mutedRole = DiscordContextSeymour.GrabRole(MordhauRoleEnum.Muted); await user.AddRoleAsync(mutedRole); UserDisciplinaryEventStorage newEvent = new UserDisciplinaryEventStorage() { DateInserted = DateTime.UtcNow, DateToRemove = (DateTimeOffset.UtcNow + timeSpan).DateTime, DiscipinaryEventType = DisciplinaryEventEnum.MuteEvent, ModeratorID = Context.Message.Author.Id, Reason = reason, UserID = user.Id }; UserStorage newUser = new UserStorage() { UserID = user.Id, UserName = user.Username }; bool existing = await TimedEventManager.CreateEvent(newEvent, newUser); await DiscordContextOverseer.LogModerationAction(userID, "Muted", Context.Message.Author.Id, reason, Utilities.ShortTimeSpanFormatting(timeSpan)); var embed = Utilities.BuildDefaultEmbed(DisciplinaryEventEnum.MuteEvent, timeSpan, reason, user.Username, existing); await DiscordContextSeymour.GetMainChannel().SendMessageAsync("", false, embed); } catch (Exception ex) { ExceptionManager.HandleException(ErrMessages.MuteException, ex); } }
private async Task PermaRestrictUserAsync(ulong userID, [Remainder] string reason = "no reason specified") { try { SocketGuildUser user = Context.Guild.GetUser(userID); if (user == null) { await Context.Channel.SendMessageAsync($"Unable to locate user {DiscordContextSeymour.GetEmoteAyySeymour()}"); return; } if (await DiscordContextSeymour.IsUserDevOrAdminAsync(user as SocketGuildUser)) { return; } var limitedRole = DiscordContextSeymour.GrabRole(MordhauRoleEnum.Restricted); await user.AddRoleAsync(limitedRole); UserDisciplinaryPermanentStorage newEvent = new UserDisciplinaryPermanentStorage() { DateInserted = DateTime.UtcNow, DiscipinaryEventType = DisciplinaryEventEnum.RestrictedUserEvent, ModeratorID = Context.Message.Author.Id, Reason = reason, UserID = user.Id }; UserStorage newUser = new UserStorage() { UserID = user.Id, UserName = user.Username }; bool existing = await StorageManager.StoreDisciplinaryPermanentEventAsync(newEvent, newUser); var embed = Utilities.BuildDefaultEmbed(DisciplinaryEventEnum.RestrictedUserEvent, new TimeSpan(), reason, user.Username, existing); await DiscordContextSeymour.GetMainChannel().SendMessageAsync("", false, embed); await DiscordContextOverseer.LogModerationAction(userID, "Restricted", Context.Message.Author.Id, reason, ""); } catch (Exception ex) { ExceptionManager.HandleException(ErrMessages.LimitException, ex); } }
private async Task PardonUserAsync(ulong userID) { try { var user = Context.Guild.GetUser(userID); if (user != null) { bool existing = await StorageManager.RemoveActiveDisciplinaries(userID); if (existing) { ulong mutedRoleID = ConfigManager.GetUlongProperty(PropertyItem.Role_Muted); ulong limitedRoleID = ConfigManager.GetUlongProperty(PropertyItem.Role_LimitedUser); var rolesToRemove = new List <IRole>(); foreach (var role in user.Roles) { if (role.Id == limitedRoleID || role.Id == mutedRoleID) { rolesToRemove.Add(role); } } if (rolesToRemove.Count() > 0) { await user.RemoveRolesAsync(rolesToRemove); } await DiscordContextOverseer.LogModerationAction(userID, "Pardonned", Context.Message.Author.Id, "", ""); await Context.Channel.SendMessageAsync($"{user.Mention} has been pardoned for their crimes"); } else { await Context.Channel.SendMessageAsync($"Could not find active punishments for {user.Mention}"); } } else { await Context.Channel.SendMessageAsync($"Unable to locate user"); } } catch (Exception ex) { ExceptionManager.HandleException(ErrMessages.PardonException, ex); } }
private async Task MonthBlacklistUserAsync(ulong userID) { try { SocketGuildUser user = await Context.Channel.GetUserAsync(userID) as SocketGuildUser; if (user == null) { await Context.Channel.SendMessageAsync($"Unable to locate user {DiscordContextSeymour.GetEmoteAyySeymour()}"); return; } if (await DiscordContextSeymour.IsUserDevOrAdminAsync(user as SocketGuildUser)) { return; } bool existing = await StorageManager.StoreBlacklistReturnIfExisting(new BlacklistUserStorage() { Username = user.Username, DateInserted = DateTime.UtcNow, ModeratorID = Context.Message.Author.Id, DateToRemove = DateTime.UtcNow.AddMonths(1), UserID = user.Id }, new UserStorage() { UserID = user.Id, UserName = user.Username, }); var embed = Utilities.BuildBlacklistEmbed(new TimeSpan(), user.Username, existing); await DiscordContextSeymour.GetMainChannel().SendMessageAsync("", false, embed); await DiscordContextOverseer.LogModerationAction(user.Id, "Blacklisted", Context.Message.Author.Id, "", DateTime.UtcNow.AddMonths(1).Subtract(DateTime.UtcNow).ToString()); } catch (Exception ex) { ExceptionManager.HandleException(ErrMessages.BlacklistException, ex); } }
private async Task RestrictUserAsync(SocketGuildUser user, TimeSpan timeSpan, [Remainder] string reason = "no reason specified") { try { if (await DiscordContextSeymour.IsUserDevOrAdminAsync(user as SocketGuildUser)) { return; } var limitedRole = DiscordContextSeymour.GrabRole(MordhauRoleEnum.Restricted); await user.AddRoleAsync(limitedRole); UserDisciplinaryEventStorage newEvent = new UserDisciplinaryEventStorage() { DateInserted = DateTime.UtcNow, DateToRemove = (DateTimeOffset.UtcNow + timeSpan).DateTime, DiscipinaryEventType = DisciplinaryEventEnum.RestrictedUserEvent, ModeratorID = Context.Message.Author.Id, Reason = reason, UserID = user.Id }; UserStorage newUser = new UserStorage() { UserID = user.Id, UserName = user.Username }; bool existing = await TimedEventManager.CreateEvent(newEvent, newUser); var embed = Utilities.BuildDefaultEmbed(DisciplinaryEventEnum.RestrictedUserEvent, timeSpan, reason, user.Username, existing, Context.Message.Author.Username); await Context.Channel.SendMessageAsync("", false, embed); await DiscordContextOverseer.LogModerationAction(user.Id, "Restricted", Context.Message.Author.Id, reason, Utilities.ShortTimeSpanFormatting(timeSpan)); } catch (Exception ex) { ExceptionManager.HandleException(ErrMessages.LimitException, ex); } }
private async Task UnblacklistUserAsync(SocketGuildUser user) { try { bool existing = await StorageManager.RemoveBlacklist(user.Id); if (existing) { var embed = Utilities.BuildRemoveDisciplinaryEmbed("Successfully unblacklisted", user.Username); await Context.Channel.SendMessageAsync("", false, embed); } else { await Context.Channel.SendMessageAsync("Could not find that user within the blacklist"); } await DiscordContextOverseer.LogModerationAction(user.Id, "Unblacklisted", Context.Message.Author.Id, "", ""); } catch (Exception ex) { ExceptionManager.HandleException(ErrMessages.UnblacklistException, ex); } }
private async Task PermaMuteUserAsync(SocketGuildUser user, [Remainder] string reason = "no reason specified") { try { if (await DiscordContextSeymour.IsUserDevOrAdminAsync(user as SocketGuildUser)) { return; } var mutedRole = DiscordContextSeymour.GrabRole(MordhauRoleEnum.Muted); await user.AddRoleAsync(mutedRole); UserDisciplinaryPermanentStorage newEvent = new UserDisciplinaryPermanentStorage() { DateInserted = DateTime.UtcNow, DiscipinaryEventType = DisciplinaryEventEnum.MuteEvent, ModeratorID = Context.Message.Author.Id, Reason = reason, UserID = user.Id }; UserStorage newUser = new UserStorage() { UserID = user.Id, UserName = user.Username }; bool existing = await StorageManager.StoreDisciplinaryPermanentEventAsync(newEvent, newUser); var embed = Utilities.BuildDefaultEmbed(DisciplinaryEventEnum.MuteEvent, new TimeSpan(), reason, user.Username, existing, Context.Message.Author.Username); await Context.Channel.SendMessageAsync("", false, embed); await DiscordContextOverseer.LogModerationAction(user.Id, "Muted", Context.Message.Author.Id, reason, ""); } catch (Exception ex) { ExceptionManager.HandleException(ErrMessages.MuteException, ex); } }
private async Task OverseerSayCustomMessage([Remainder] string input) { try { if (Context.Message.MentionedChannels.Count == 0) { await Context.Channel.SendMessageAsync("You must mention the channel: (#channel_name)"); return; } var targetChannel = Context.Message.MentionedChannels.FirstOrDefault() as ITextChannel; var targetChannelAsString = $"<#{targetChannel.Id}>"; var sanitizedInput = input.Replace(targetChannelAsString, string.Empty); var overseerTargetChannel = DiscordContextOverseer.GetChannel(targetChannel.Id); await overseerTargetChannel.SendMessageAsync(sanitizedInput); } catch (Exception ex) { ExceptionManager.HandleException(ErrMessages.SayException, ex); } }
public static async Task DeletedMessageEvent(Cacheable <IMessage, ulong> msg, ISocketMessageChannel channel) { try { var logChannel = DiscordContextOverseer.GetDeletedMessageLog(); var message = await msg.GetOrDownloadAsync(); if (message != null) { var embed = new EmbedBuilder(); List <CachedFile> filesData = null; bool hasImages = false; //if at least one image (embedded or attached) was in the deleted message, look for it in the cache bool imageExists = CheckForImageWithinEmbeds(message); bool hasURLs = CheckForURLs(message); if ((message.Embeds.Count > 0 && imageExists) || (message.Attachments.Count > 0 && hasURLs)) { hasImages = true; filesData = ImageCacheManager.FindImagesInCache(message.Id); } if (hasImages) { if (filesData != null) { embed.WithTitle($"🗑 {message.Author.Username}#{message.Author.Discriminator} deleted message containing {filesData.Count} image{((filesData.Count > 1) ? "s" : "") } in {message.Channel.Name}. UserID = {message.Author.Id}"); } else { embed.WithTitle($"🗑 {message.Author.Username}#{message.Author.Discriminator} deleted message containing images that weren't cached in {message.Channel.Name}. UserID = {message.Author.Id}"); } } else //it's just a message { embed.WithTitle($"🗑 {message.Author.Username}#{message.Author.Discriminator} deleted message messageID {message.Id} in {message.Channel.Name}. UserID = {message.Author.Id}"); } //check for other types of embeds string extraMessageContent = SearchForOtherEmbedTypes(message); embed.WithDescription(message.Content + extraMessageContent); embed.WithColor(new Color(255, 0, 0)); await logChannel.SendMessageAsync("", false, embed.Build()); if (filesData != null) { foreach (var file in filesData) { using (var ms = new MemoryStream(file.File)) { await logChannel.SendFileAsync(ms, file.FileName); } } } } } catch (System.Exception ex) { await ExceptionManager.LogExceptionAsync(ErrMessages.DeletedMessageException, ex); } }
public static async Task EditedMessageEvent(Cacheable <IMessage, ulong> msgBefore, SocketMessage msgAfter, ISocketMessageChannel channel) { try { if (string.IsNullOrEmpty(msgAfter.Content)) { return; } if (msgBefore.Value.Content == msgAfter.Content) { return; } var logChannel = DiscordContextOverseer.GetDeletedMessageLog(); var message = await msgBefore.GetOrDownloadAsync(); if (message != null) { List <byte[]> imagesData = null; bool hasImages = false; string time = msgAfter.Timestamp.DateTime.ToLongDateString() + " " + msgAfter.Timestamp.DateTime.ToLongTimeString(); var embed = new EmbedBuilder(); if (hasImages) { if (imagesData != null) { embed.WithTitle($"✍️ {msgAfter.Author.Username}#{msgAfter.Author.Discriminator} edited messageID {message.Id} at {time} containing {imagesData.Count} image{((imagesData.Count > 1) ? "" : "s") }"); } else { embed.WithTitle($"✍️ {msgAfter.Author.Username}#{msgAfter.Author.Discriminator} edited messageID {message.Id} at {time} containing images that weren't cached"); } } else { embed.WithTitle($"🗑 {message.Author.Username}#{message.Author.Discriminator} deleted message in {message.Channel.Name}. UserID = {message.Author.Id}"); } embed.WithTitle($"✍️ {msgAfter.Author.Username}#{msgAfter.Author.Discriminator} edited messageID {message.Id} at {time}"); embed.WithDescription($"in #{channel.Name}, Original: " + msgBefore.Value.Content); embed.WithColor(new Color(250, 255, 0)); await logChannel.SendMessageAsync("", false, embed.Build()); if (imagesData != null) { foreach (byte[] image in imagesData) { using (var ms = new MemoryStream(image)) { await logChannel.SendFileAsync(ms, "cached.png"); } } } } } catch (System.Exception ex) { ExceptionManager.HandleException($"{typeof(MessageLogger).GetType().FullName}: {ExceptionManager.GetAsyncMethodName()}", ex); } }