Пример #1
0
        internal async Task ReactionAddedAsync(Cacheable <IUserMessage, ulong> Cache, ISocketMessageChannel Channel, SocketReaction Reaction)
        {
            if (Reaction.Emote.Name != "⭐")
            {
                return;
            }
            var Guild   = (Reaction.Channel as SocketGuildChannel).Guild;
            var Message = await Cache.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);
        }
Пример #2
0
        internal async Task MessageDeletedAsync(Cacheable <IMessage, ulong> Cache, ISocketMessageChannel Channel)
        {
            var Config  = GuildHandler.GetGuild((Channel as SocketGuildChannel).Guild.Id);
            var Message = await Cache.GetOrDownloadAsync();

            if (Message == null || Config == null || !Config.Mod.LogDeletedMessages || Message.Author.IsBot)
            {
                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);
        }