public async Task Rescan() { try { GuildData guildData = Data.BotData.guildDictionary[Context.Guild.Id]; foreach (KeyValuePair <ulong, MessageData> messageDataKV in guildData.messageData) { IUserMessage message = await messageDataKV.Value.GetMessageAsync(Context.Guild); if (message != null) { await Starboard.RescanMessage(new StarboardContext(StarboardContextType.COMMAND_RESCANALL, guildData, messageDataKV.Value, message)); } else { await ReplyAsync($"❌ Could not find message `{messageDataKV.Key}`."); } } await ReplyAsync("✅ Rescanned all saved messages."); } catch (Exception e) { await HandleException(e); } }
public async Task Scan(SocketTextChannel channel, string messageId) { try { GuildData guildData = Data.BotData.guildDictionary[Context.Guild.Id]; if (!UInt64.TryParse(messageId, out ulong msgId)) { await ReplyAsync(":x: Invalid message id"); return; } if (await channel.GetMessageAsync(msgId) is IUserMessage message) { await Starboard.RescanMessage(new StarboardContext(StarboardContextType.COMMAND_SCAN, guildData, message, channel)); await ReplyAsync(":white_check_mark: Message Was Scanned!"); } else { await ReplyAsync(":x: Message Not Found!"); } } catch (Exception e) { await HandleException(e); } }
public async Task Rediscover(ITextChannel channel) { try { DateTimeOffset rediscoverStart = DateTimeOffset.Now; GuildData guildData = Data.BotData.guildDictionary[Context.Guild.Id]; await ReplyAsync($"▶ Starting rediscover for channel {channel.Mention}"); IAsyncEnumerable <IReadOnlyCollection <IMessage> > messages = channel.GetMessagesAsync(200); await messages.ForEachAsync(async batch => { try { int rescanCount = 0; foreach (IMessage msg in batch) { if (msg.Timestamp > rediscoverStart) { continue; } if (msg is IUserMessage usrMsg) { if (!usrMsg.Author.IsBot) { await Starboard.RescanMessage(new StarboardContext(StarboardContextType.COMMANMD_REDISCOVER, guildData, usrMsg, channel)); rescanCount++; } else if (usrMsg.Author.Id == Context.Client.CurrentUser.Id) { StarboardContext context = await StarboardUtil.GetStarboardContextFromStarboardMessage(new StarboardContext(StarboardContextType.COMMANMD_REDISCOVER, guildData, usrMsg, channel)); if (context != null) { if (context.Exception != null) { await HandleContextException(context.Exception); } else { await Starboard.RescanMessage(context); rescanCount += 2; } } else { await Starboard.RescanMessage(new StarboardContext(StarboardContextType.COMMANMD_REDISCOVER, guildData, usrMsg, channel)); rescanCount++; } } } } await ReplyAsync($":white_check_mark: Rescanned `{rescanCount}` messages."); } catch (Exception e) { await HandleException(e); } }); } catch (Exception e) { await HandleException(e); } }