public override Task <TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider services) { input = input.Replace("`", "").Replace(@"\", "").Trim(); // Find by name foreach (var emote in EmotesHelper.Emotes) { if (input.Equals($":{EmotesHelper.GetEmojiName(emote)}:", StringComparison.CurrentCultureIgnoreCase)) { return(Task.FromResult(TypeReaderResult.FromSuccess(EmotesHelper.GetEmoji(emote)))); } } // Find by unicode value foreach (var emote in EmotesHelper.Emojis) { if (input.Equals(emote.Name, StringComparison.CurrentCultureIgnoreCase)) { return(Task.FromResult(TypeReaderResult.FromSuccess(emote))); } } // Check guild-emotes var guildEmote = context.Guild.Emotes.FirstOrDefault(e => string.Equals($"<:{e.Name}:{e.Id}>", input, StringComparison.CurrentCultureIgnoreCase) || string.Equals($"<a:{e.Name}:{e.Id}>", input, StringComparison.CurrentCultureIgnoreCase)); if (guildEmote != null) { return(Task.FromResult(TypeReaderResult.FromSuccess(guildEmote))); } return(Task.FromResult(TypeReaderResult.FromError(CommandError.Unsuccessful, "Unable to find a valid emote"))); }
public static async Task AddReactionsAsync(this IMessage message, CancellationToken cancellationToken, params Emotes[] emotes) { var errorCount = 0; for (int i = 0; i < emotes.Length;) { var emote = emotes[i]; try { await message.AddReactionAsync( EmotesHelper.GetEmoji(emote), new RequestOptions() { CancelToken = cancellationToken, RetryMode = RetryMode.AlwaysRetry } ).ConfigureAwait(false); i++; errorCount = 0; } catch (Exception ex) { if (errorCount > 2) { Log.Warn($"AddReactionsAsync: Skipping {i}:{emote}"); i++; } else { if (!(ex is RateLimitedException)) { Log.Error($"AddReactionsAsync, {i}:{emote} | {ex}"); errorCount++; } } } } }
public async Task Prune(int count = 100, IUser user = null, [Multiword] string pattern = null) { if (!Permissions.IsAdministratorOrBotOwner(Context)) { await Context.ApplyResultReaction(CommandResult.FailedUserPermission).ConfigureAwait(false); return; } await Context.Message.DeleteAsync().ConfigureAwait(false); await Task.Delay(100).ConfigureAwait(false); if (count > 10) { var usedReaction = await Context.SendOptionDialogueAsync( $"{Context.User.Mention} Please verify. Do you wish to delete {count} messages from this channel?", new List <string>(), true, new[] { EmotesHelper.GetEmoji(Emotes.WhiteCheckMark), EmotesHelper.GetEmoji(Emotes.NoEntrySign) }, null, 60000, 0 ).ConfigureAwait(false); if (usedReaction != 1) { return; } } if (count > 100) { count = 100; } else if (count <= 0) { count = 1; } var list = (await Context.Channel.GetMessagesAsync(count).ToListAsync()) .SelectMany(i => i); if (!string.IsNullOrEmpty(pattern)) { list = list.Where(i => i.Content.Contains(pattern)); } if (user != null) { list = list.Where(i => i.Author?.Id == user.Id); } foreach (var msg in list) { try { if (!msg.IsPinned) { await msg.DeleteAsync().ConfigureAwait(false); } } catch { } } }