Ejemplo n.º 1
0
        internal async Task ReactionAddedAsync(Cacheable <IUserMessage, ulong> cacheable, ISocketMessageChannel channel, SocketReaction reaction)
        {
            if (reaction.Emote.Name != "⭐")
            {
                return;
            }
            var guild   = (reaction.Channel as SocketGuildChannel).Guild;
            var message = await cacheable.GetOrDownloadAsync();

            var config           = GuildHandler.GetGuild(guild.Id);
            var starboardChannel = guild.GetTextChannel(config.Starboard.TextChannel) as IMessageChannel;

            if (message == null || starboardChannel == null || reaction.Channel.Id == config.Starboard.TextChannel)
            {
                return;
            }
            var embed = GetEmbed(Paint.Yellow)
                        .WithAuthor(message.Author.Username, message.Author.GetAvatarUrl())
                        .WithFooter(message.Timestamp.ToString("F"));
            var reactionCount = message.Reactions.Count(x => x.Key.Name == "⭐");

            if (!string.IsNullOrWhiteSpace(message.Content))
            {
                embed.WithDescription(message.Content);
            }
            if (message.Attachments.FirstOrDefault() != null)
            {
                embed.WithImageUrl(message.Attachments.FirstOrDefault().Url);
            }
            var exists = config.Starboard.StarboardMessages.FirstOrDefault(x => x.MessageId == message.Id);

            if (config.Starboard.StarboardMessages.Contains(exists))
            {
                exists.Stars++;
                var sMsg = await starboardChannel.GetMessageAsync(exists.StarboardMessageId, CacheMode.AllowDownload) as IUserMessage;

                await sMsg.ModifyAsync(x =>
                {
                    x.Content = $"{StringHelper.Star(exists.Stars)}{exists.Stars} {(reaction.Channel as ITextChannel).Mention} ID: {exists.StarboardMessageId}";
                    x.Embed   = embed.Build();
                });
            }
            else
            {
                var msg = await starboardChannel.SendMessageAsync($"{StringHelper.Star(reactionCount)}{reactionCount} {(reaction.Channel as ITextChannel).Mention} ID: {reaction.MessageId}", embed : embed.Build());

                config.Starboard.StarboardMessages.Add(new StarboardMessage
                {
                    Stars              = 1,
                    MessageId          = message.Id,
                    StarboardMessageId = msg.Id,
                    AuthorId           = message.Author.Id,
                    ChannelId          = message.Channel.Id
                });
            }
            GuildHandler.Save(config);
        }
Ejemplo n.º 2
0
        internal async Task MessageDeletedAsync(Cacheable <IMessage, ulong> cacheable, ISocketMessageChannel channel)
        {
            var config  = GuildHandler.GetGuild((channel as SocketGuildChannel).Guild.Id);
            var message = await cacheable.GetOrDownloadAsync();

            if (message == null || config == null || !config.Mod.LogDeletedMessages || CommandExecuted)
            {
                return;
            }
            config.DeletedMessages.Add(new MessageWrapper
            {
                ChannelId = channel.Id,
                MessageId = message.Id,
                AuthorId  = message.Author.Id,
                DateTime  = message.Timestamp.DateTime,
                Content   = message.Content ?? message.Attachments.FirstOrDefault()?.Url
            });
            GuildHandler.Save(config);
        }