public static async Task UpdateStarGivenAsync(StarboardContext context, IUser starGivingUser, bool starGiven) { //If the starred message was sent by the current bot user... if ((await context.GetStarredMessageAsync()).Author.Id == Program.sc.CurrentUser.Id) { //... check if it is a starboard message StarboardContext starboardContext = await StarboardUtil.GetStarboardContextFromStarboardMessage(context); if (starboardContext != null) { if (context.Exception != null) { //We should probably delete the broken starboard message, ignore for now. return; } await UpdateStarGivenInternalAsync(starboardContext, starGivingUser, starGiven); return; } } context.Source = StarboardSource.STARRED_MESSAGE; await UpdateStarGivenInternalAsync(context, starGivingUser, starGiven); }
public static async Task RescanMessage(StarboardContext context) { await context.GetStarredMessageAsync(); if (context.StarredMessage.Author.Id == Program.sc.CurrentUser.Id) { StarboardContext starboardContext = await StarboardUtil.GetStarboardContextFromStarboardMessage(context); if (starboardContext != null) { if (context.Exception != null) { //We should probably delete the broken starboard message, ignore for now. return; } await UpdateStarsGivenAsync(starboardContext); return; } } await UpdateStarsGivenAsync(context); }
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); } }