コード例 #1
0
        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);
        }
コード例 #2
0
        private static async Task UpdateStarGivenInternalAsync(StarboardContext context, IUser starGivingUser, bool starGiven)
        {
            context.GetOrAddMessageData();

            if (starGivingUser.Id == (await context.GetStarredMessageAsync()).Author.Id)
            {
                await context.RemoveReactionAsync(starGivingUser);

                return;
            }

            if (starGiven)
            {
                if (!context.MessageData.StarGivingUsers.AddOrUpdate(starGivingUser.Id, context.Source, StarboardSource.STARRED_MESSAGE))
                {
                    await context.RemoveReactionFromStarboardMessageAsync(starGivingUser);
                }
            }
            else
            {
                context.MessageData.StarGivingUsers.Remove(starGivingUser.Id, context.Source);
            }

            await CreateOrUpdateStarboardMessage(context);
        }
コード例 #3
0
        public static async Task UpdateStarsGivenAsync(StarboardContext context)
        {
            await context.GetStarredMessageAsync();

            context.GetOrAddMessageData();

            context.MessageData.StarGivingUsers.Clear();

            await UpdateStarsGivenInternalAsync(context, StarboardSource.STARRED_MESSAGE, (await context.GetStarredMessageAsync()).GetReactionUsersAsync(StarboardEmote, 5000));

            if (await context.GetStarboardMessageAsync() != null)
            {
                await UpdateStarsGivenInternalAsync(context, StarboardSource.STARBOARD_MESSAGE, context.StarboardMessage.GetReactionUsersAsync(StarboardEmote, 5000));
            }


            await CreateOrUpdateStarboardMessage(context);
        }
コード例 #4
0
        internal static async Task <StarboardContext> GetStarboardContextFromStarboardMessage(StarboardContext context)
        {
            IEmbed embed = (await context.GetStarredMessageAsync()).Embeds.FirstOrDefault();

            if (embed != null)
            {
                string[] parts = embed.Author?.Url?.Split('/');

                if (parts != null && parts.Length > 6)
                {
                    ulong channelId = UInt64.Parse(parts[5]);
                    ulong messageId = UInt64.Parse(parts[6]);

                    context.StarboardTextChannel      = context.StarredMessageTextChannel;
                    context.StarredMessageTextChannel = (await context.Guild.GetChannelAsync(channelId)) as ITextChannel;

                    if (context.StarredMessageTextChannel != null)
                    {
                        context.StarboardMessage = context.StarredMessage;
                        context.StarredMessage   = await context.StarredMessageTextChannel.GetMessageAsync(messageId) as IUserMessage;

                        context.Source = StarboardSource.STARBOARD_MESSAGE;

                        if (context.StarredMessage == null)
                        {
                            context.Exception = new NullReferenceException("StarredMessage was null (deleted or not found).");
                        }
                    }
                    else
                    {
                        context.Exception = new NullReferenceException("StarredMessageTextChannel was null (deleted or not found).");
                    }

                    return(context);
                }
            }

            return(null);
        }
コード例 #5
0
        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);
        }