/// <summary> /// Process emote mode for a message. /// </summary> /// <param name="message">Message to process.</param> /// <returns>True if message was deleted.</returns> private static async Task <bool> ProcessMessageEmotesAsync(SocketUserMessage message) { (EmoteModeTracker.Mode mode, object args) = EmoteModeTracker.GetMode(message.Channel.Id); if (mode != EmoteModeTracker.Mode.Off) { if (message.Attachments.Count > 0) { return(await DeleteMessageAsync()); } List <EmoteOrEmoji> emotes = message.Content.ParseDiscordMessageEmotes(); if (mode == EmoteModeTracker.Mode.TextOnly) { if (emotes.Count > 0) { return(await DeleteMessageAsync()); } } else if (mode == EmoteModeTracker.Mode.EmoteOnly) { string content = message.Content; foreach (EmoteOrEmoji emote in emotes) { content = content.Replace(emote.ToString(), ""); } if (!string.IsNullOrWhiteSpace(content)) { return(await DeleteMessageAsync()); } } else if (mode == EmoteModeTracker.Mode.Exactly) { if (args is string argString) { if (!string.Equals(message.Content, argString, StringComparison.InvariantCultureIgnoreCase)) { return(await DeleteMessageAsync()); } } } async Task <bool> DeleteMessageAsync() { await message.DeleteAsync(); if (EmoteModeTracker.ShouldSendNotification(message.Channel.Id)) { await message.Channel.SendMessageAsync($"The channel is currently in **{mode.Humanize().ToLower()}** mode."); } return(true); } } return(false); }
private static async Task ReactionAdded(Cacheable <IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction) { // BongBot //try { // if (reaction.User.IsSpecified && reaction.User.Value.Id == 735232851431260290 && message.HasValue) { // _ = message.Value.AddReactionAsync(reaction.Emote); // LoggingManager.Log.Debug($"Reacted to BongBot {reaction.Emote}"); // } //} catch (Exception ex) { // LoggingManager.Log.Error(ex); //} // Bong trap try { if (BongTrapMessageId.HasValue && message.Id == BongTrapMessageId && reaction.User.IsSpecified && reaction.User.Value is SocketGuildUser socketUser) { Random rand = new Random(); if (!string.IsNullOrEmpty(socketUser.Nickname)) { string scrambledNick = new string(socketUser.Nickname.ToCharArray().OrderBy(s => (rand.Next(2) % 2) == 0).ToArray()); _ = socketUser.ModifyAsync(x => x.Nickname = scrambledNick); } else { string scrambledUsername = new string(socketUser.Username.ToCharArray().OrderBy(s => (rand.Next(2) % 2) == 0).ToArray()); _ = socketUser.ModifyAsync(x => x.Nickname = scrambledUsername); } } } catch (Exception ex) { LoggingManager.Log.Error(ex); } // Emote mode (EmoteModeTracker.Mode mode, object _) = EmoteModeTracker.GetMode(channel.Id); if (mode == EmoteModeTracker.Mode.TextOnly) { if (message.HasValue & reaction.User.IsSpecified) { if (WubbysFunHouse.IsDiscordOrTwitchStaff(reaction.User.Value)) { return; } await message.Value.RemoveReactionAsync(reaction.Emote, reaction.User.Value); } } }