private async Task <Option <IUserMessage> > GetStarboardMessage(ulong messageId, ITextChannel starboardChannel) { return(await _cache.TryGetOrSetAndGetAsync( CacheId.GetMessageId(messageId), async() => await starboardChannel.GetMessageAsync(messageId, CacheMode.AllowDownload) .ConfigureAwait(false) as IUserMessage, _postedMsgTtl).ConfigureAwait(false)); }
private async Task <IUserMessage> PostAndCacheMessage(IUserMessage msg, ITextChannel starboardChannel, int reactionCount) { var eb = new EmbedBuilder() { Color = SoraSocketCommandModule.Purple, Author = new EmbedAuthorBuilder() { IconUrl = msg.Author.GetAvatarUrl() ?? msg.Author.GetDefaultAvatarUrl(), Name = Formatter.UsernameDiscrim(msg.Author) } }; if (!TryAddImageAttachment(msg, eb)) // First check if there's an attached image { if (!TryAddImageLink(msg, eb)) // Check if there's an image link { TryAddArticleThumbnail(msg, eb); // Is it a link? } } // Otherwise make a normal embed if (!string.IsNullOrWhiteSpace(msg.Content)) { eb.WithDescription(msg.Content); } eb.AddField("Posted in", $"[#{msg.Channel.Name} (take me!)]({msg.GetJumpUrl()})"); eb.WithTimestamp(msg.Timestamp); var postedMsg = await starboardChannel .SendMessageAsync($"**{reactionCount.ToString()}** {STAR_EMOTE}", embed : eb.Build()) .ConfigureAwait(false); _cache.Set(CacheId.GetMessageId(postedMsg.Id), postedMsg, _postedMsgTtl); return(postedMsg); }
private async Task <Option <IUserMessage> > GetOrDownloadMessage(Cacheable <IUserMessage, ulong> msg) => await _cache.TryGetOrSetAndGetAsync( CacheId.GetMessageId(msg.Id), async() => await msg.GetOrDownloadAsync().ConfigureAwait(false), this._messageCacheTtl) .ConfigureAwait(false);
private async Task RemoveStarboardMessageFromCacheAndDb(ulong messageId, ulong postedMessageId) { _cache.TryRemove <object>(CacheId.GetMessageId(messageId)); _cache.TryRemove <object>(CacheId.GetMessageId(postedMessageId)); await _starRepo.RemoveStarboardMessage(messageId).ConfigureAwait(false); }