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 void UpdateMessagesByUser(SocketGuild guild, ulong userId) { Parallel.ForEach <KeyValuePair <ulong, MessageData> >(messageData, async msgData => { try { if (msgData.Value.userId == userId) { await Starboard.UpdateStarboardMessage(new StarboardContext(StarboardContextType.USER_UPDATED, this, msgData.Value)); } } catch (Exception e) { Program.Log($"Exception while updating starboard message {msgData.Value?.starboardMessageId}: {e.GetType().FullName}: {e.Message}\n{e.StackTrace}", LogSeverity.Error); } }); }
internal static async Task Sc_ReactionRemoved(Cacheable <IUserMessage, ulong> arg1, ISocketMessageChannel arg2, SocketReaction arg3) { try { IUserMessage msg = arg1.Value ?? await arg1.DownloadAsync(); if (arg3.Emote.Name.Equals("⭐", StringComparison.InvariantCultureIgnoreCase)) { if (msg.Author.Id != arg3.User.Value.Id) { await Starboard.UpdateStarGivenAsync(new StarboardContext(StarboardContextType.REACTION_REMOVED, msg), arg3.User.Value, false); } } } catch (Exception ex) { Program.Log($"Exception in Sc_ReactionRemoved {ex.GetType().FullName}: {ex.Message}\n{ex.StackTrace}", LogSeverity.Error); } }
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); } }