예제 #1
0
        private async Task OnGuildUpdated(SocketGuild prevGuild, SocketGuild newGuild)
        {
            GuildBson guild = await this.database.LoadRecordsByGuildId(prevGuild.Id);

            if (GetRestTextChannel(this.shard, guild.GuildUpdatedEvent, out RestTextChannel restTextChannel))
            {
                List <EmbedFieldBuilder> fields = new();

                foreach (PropertyInfo info in EnumeratingUtilities.GetDifferentProperties(prevGuild, newGuild, new[] { "" }))
                {
                    fields.Add(new EmbedFieldBuilder
                    {
                        Name = info.Name, Value = $"{info.GetValue(prevGuild) ?? "null"} to {info.GetValue(newGuild) ?? "null"}"
                    });
                }

                EmbedBuilder embedBuilder = new()
                {
                    Color  = Color.Blue,
                    Fields = fields,
                    Footer = new EmbedFooterBuilder {
                        Text = $"Modified at {DateTime.UtcNow} UTC"
                    }
                };

                await restTextChannel.SendMessageAsync("", false, embedBuilder.Build());
            }
        }
    }
예제 #2
0
        private async Task ShardOnUserUpdated(SocketUser prevUser, SocketUser newUser)
        {
            List <GuildBson> guilds = await this.database.LoadRecords();

            foreach (GuildBson guild in guilds)
            {
                if (GetRestTextChannel(this.shard, guild.UserUpdatedEvent, out RestTextChannel restTextChannel))
                {
                    List <EmbedFieldBuilder> fields = new();

                    IEnumerable <PropertyInfo> differentPropertyInfos = EnumeratingUtilities.GetDifferentProperties(
                        prevUser, newUser,
                        new[] { "" });

                    foreach (PropertyInfo info in differentPropertyInfos)
                    {
                        fields.Add(new EmbedFieldBuilder
                        {
                            Name = $"Old {info.Name}", Value = info.GetValue(prevUser), IsInline = true
                        });
                        fields.Add(new EmbedFieldBuilder
                        {
                            Name = $"New {info.Name}", Value = info.GetValue(newUser), IsInline = true
                        });
                        fields.Add(new EmbedFieldBuilder {
                            Name = "|", Value = "|", IsInline = true
                        });
                    }

                    EmbedBuilder embedBuilder = new()
                    {
                        Color  = Color.Blue,
                        Fields = fields,
                        Footer = new EmbedFooterBuilder {
                            Text = $"Modified on {DateTime.UtcNow} UTC "
                        }
                    };

                    await restTextChannel.SendMessageAsync("", false, embedBuilder.Build());
                }
            }
        }
    }
예제 #3
0
        private async Task ShardOnRoleUpdated(SocketRole oldRole, SocketRole newRole)
        {
            GuildBson guild = await this.database.LoadRecordsByGuildId(oldRole.Guild.Id);

            if (GetRestTextChannel(this.shard, guild.RoleUpdatedEvent, out RestTextChannel restTextChannel))
            {
                List <EmbedFieldBuilder> fields = new();

                foreach (PropertyInfo info in EnumeratingUtilities.GetDifferentProperties(oldRole, newRole,
                                                                                          new[] { "Members" }))
                {
                    fields.Add(new EmbedFieldBuilder
                    {
                        Name     = $"Old {info.Name}",
                        Value    = info.GetValue(oldRole),
                        IsInline = true
                    });
                    fields.Add(new EmbedFieldBuilder
                    {
                        Name     = $"New {info.Name}",
                        Value    = info.GetValue(newRole),
                        IsInline = true
                    });
                    fields.Add(new EmbedFieldBuilder {
                        Name = "|", Value = "|", IsInline = true
                    });
                }

                EmbedBuilder embedBuilder = new()
                {
                    Color  = newRole.Color,
                    Fields = fields,
                    Footer = new EmbedFooterBuilder {
                        Text = $"Modified on {DateTime.UtcNow} UTC "
                    }
                };

                await restTextChannel.SendMessageAsync("", false, embedBuilder.Build());
            }
        }
    }
예제 #4
0
        private async Task ShardOnGuildMemberUpdated(SocketGuildUser prevUser, SocketGuildUser newUser)
        {
            GuildBson guild = await this.database.LoadRecordsByGuildId(prevUser.Guild.Id);

            if (GetRestTextChannel(this.shard, guild.GuildMemberUpdatedEvent, out RestTextChannel restTextChannel))
            {
                List <EmbedFieldBuilder> fields = new()
                {
                    new EmbedFieldBuilder {
                        Name = "User Id", Value = newUser.Id
                    }
                };

                IEnumerable <PropertyInfo> differentPropertyInfos = EnumeratingUtilities.GetDifferentProperties(prevUser,
                                                                                                                newUser,
                                                                                                                new[] { "MutualGuilds", "Roles", "JoinedAt" });

                foreach (PropertyInfo info in differentPropertyInfos)
                {
                    fields.Add(new EmbedFieldBuilder
                    {
                        Name  = info.Name,
                        Value = $"{info.GetValue(prevUser) ?? "null"} to {info.GetValue(newUser) ?? "null"}"
                    });
                }

                EmbedBuilder embedBuilder = new()
                {
                    Color  = Color.Blue,
                    Fields = fields,
                    Footer = new EmbedFooterBuilder {
                        Text = $"Modified at {DateTime.UtcNow} UTC"
                    }
                };

                await restTextChannel.SendMessageAsync("", false, embedBuilder.Build());
            }
        }
    }
}
예제 #5
0
        private async Task ShardOnChannelUpdated(SocketChannel oldChannel, SocketChannel newChannel)
        {
            GuildBson       guild;
            RestTextChannel restTextChannel;

            string[] channelConstantChanges = { "Users", "CachedMessages" };
            IEnumerable <PropertyInfo> differentPropertyInfos;

            List <EmbedFieldBuilder> fields = new()
            {
                new EmbedFieldBuilder {
                    Name = "Channel", Value = $"<#{oldChannel.Id}>"
                }
            };

            // TODO: Fix permissions overwrites, should output what permissions are changed.
            switch (oldChannel)
            {
            case SocketTextChannel socketTextChannel:
                guild = await this.database.LoadRecordsByGuildId(socketTextChannel.Guild.Id);

                if (!GetRestTextChannel(this.shard, guild.ChannelUpdatedEvent, out restTextChannel))
                {
                    return;
                }

                SocketTextChannel newSocketTextChannel = newChannel as SocketTextChannel;

                differentPropertyInfos = EnumeratingUtilities.GetDifferentProperties(
                    socketTextChannel,
                    newSocketTextChannel, channelConstantChanges);

                foreach (PropertyInfo info in differentPropertyInfos)
                {
                    if (info.GetType() == typeof(IEnumerable <Overwrite>))
                    {
                        foreach (Overwrite overwrite in (IEnumerable <Overwrite>)info)
                        {
                            fields.Add(new EmbedFieldBuilder
                            {
                                Name     = overwrite.TargetType.ToString(),
                                Value    = info.GetValue(socketTextChannel) + " to " + info.GetValue(newSocketTextChannel),
                                IsInline = true
                            });
                        }
                    }

                    fields.Add(new EmbedFieldBuilder
                    {
                        Name     = info.Name,
                        Value    = info.GetValue(socketTextChannel) + " to " + info.GetValue(newSocketTextChannel),
                        IsInline = true
                    });
                }

                break;

            case SocketVoiceChannel socketVoiceChannel:
                guild = await this.database.LoadRecordsByGuildId(socketVoiceChannel.Guild.Id);

                if (!GetRestTextChannel(this.shard, guild.ChannelUpdatedEvent, out restTextChannel))
                {
                    return;
                }

                SocketVoiceChannel newSocketVoiceChannel = newChannel as SocketVoiceChannel;

                differentPropertyInfos = EnumeratingUtilities.GetDifferentProperties(
                    socketVoiceChannel,
                    newSocketVoiceChannel, channelConstantChanges);

                foreach (PropertyInfo info in differentPropertyInfos)
                {
                    fields.Add(new EmbedFieldBuilder
                    {
                        Name     = info.Name,
                        Value    = info.GetValue(socketVoiceChannel) + " to " + info.GetValue(newSocketVoiceChannel),
                        IsInline = true
                    });
                }

                break;

            default:
                return;
            }


            EmbedBuilder embedBuilder = new()
            {
                Color  = Color.Blue,
                Fields = fields,
                Footer = new EmbedFooterBuilder {
                    Text = $"Modified at {DateTime.UtcNow} UTC"
                }
            };

            await restTextChannel.SendMessageAsync("", false, embedBuilder.Build());
        }
    }
}