예제 #1
0
        private async Task Client_UserUnbanned(SocketUser user, SocketGuild guild)
        {
            RestAuditLogEntry logEntry = await GetAuditLogEntry(guild);

            if (logEntry.Action != ActionType.Unban)
            {
                return;
            }
            UnbanAuditLogData data           = (UnbanAuditLogData)logEntry.Data;
            string            targetUsername = "******" + user + "** _(" + user.Id + ")_";
            string            adminUsername  = "******" + logEntry.User + "**";
            string            msg            = targetUsername + " was unbanned by " + adminUsername +
                                               "\nReason: " + (string.IsNullOrEmpty(logEntry.Reason) ? "No reason provided." : logEntry.Reason);

            foreach (SocketTextChannel channel in Global.SECURITY_CHANNELS)
            {
                if (channel.Guild.Id == guild.Id)
                {
                    await SendSecurityLog(msg, new Color(255, 0, 0), channel, logEntry.Id.ToString(), logEntry.User.GetAvatarUrl());

                    break;
                }
            }
        }
예제 #2
0
        public static async Task AuditUpdate(SocketGuild guild)
        {
            foreach (SocketTextChannel chan in guild.TextChannels)
            {
                if (chan.Name.ToLower().Contains("security"))
                {
                    ConsolePrint("Security channel found in " + guild.Name);
                    IAsyncEnumerable <IReadOnlyCollection <RestAuditLogEntry> > auditLog  = guild.GetAuditLogsAsync(10);
                    List <IReadOnlyCollection <RestAuditLogEntry> >             auditList = await auditLog.ToList();

                    IAsyncEnumerable <IReadOnlyCollection <IMessage> > messages = chan.GetMessagesAsync(1);
                    List <IReadOnlyCollection <IMessage> >             msgList  = await messages.ToList();

                    IMessage mesg = null;
                    if (msgList[1].Count > 0)
                    {
                        mesg = msgList[1].ToArray()[0];// Newest Message
                    }
                    RestAuditLogEntry[] restAuditLogs = auditList[0].ToArray();
                    if (mesg != null)
                    {
                        if (mesg.Embeds.Count > 0)
                        {
                            if (restAuditLogs[0].Id.ToString() == mesg.Embeds.FirstOrDefault().Footer.Value.Text)
                            {
                                break;
                            }
                        }
                        else
                        {
                            continue;
                        }
                    }
                    for (int i = restAuditLogs.Length - 1; i >= 0; i--)
                    {
                        if (mesg != null)
                        {
                            if (mesg.Embeds.Count > 0)
                            {
                                int dif = DateTimeOffset.Compare(mesg.Embeds.FirstOrDefault().Timestamp.Value, restAuditLogs[i].CreatedAt);
                                if (dif >= 0)
                                {
                                    continue;
                                }
                            }
                            else
                            {
                                continue;
                            }
                        }
                        RestAuditLogEntry logEntry = restAuditLogs[i];
                        bool         send          = false;
                        EmbedBuilder embed         = new EmbedBuilder();
                        string       adminUsername = "******" + logEntry.User + "**";
                        string       title         = "Server Report";
                        embed.WithTimestamp(logEntry.CreatedAt);
                        string msg = "";
                        if (logEntry.Action == ActionType.MemberRoleUpdated)
                        {
                            MemberRoleAuditLogData data = (MemberRoleAuditLogData)logEntry.Data;
                            string targetUsername       = "******" + data.Target + "** _(" + data.Target.Id + ")_";
                            string roles = "";
                            foreach (MemberRoleEditInfo role in data.Roles)
                            {
                                roles += string.Format(((role.Added) ? " Added role {0} to " : " Removed role {0} from "), "**_" + role.Name + "_**");
                            }

                            msg = adminUsername + roles + targetUsername;
                            embed.WithColor(new Color(255, 190, 0));
                            send = true;
                        }// end if log entry role updated
                        else if (logEntry.Action == ActionType.MemberUpdated)
                        {
                            MemberUpdateAuditLogData data = (MemberUpdateAuditLogData)logEntry.Data;
                            string targetUsername         = "******" + data.Target + "** _(" + data.Target.Id + ")_";
                            if (data.Before.Deaf != data.After.Deaf)
                            {
                                msg += string.Format(adminUsername + " {0} " + targetUsername + "\n", (data.After.Deaf.Value) ? "deafened" : "undeafened");
                            }

                            if (data.Before.Mute != data.After.Mute)
                            {
                                msg += string.Format(adminUsername + " {0} " + targetUsername + "\n", (data.After.Mute.Value) ? "muted" : "unmuted");
                            }


                            if (data.Before.Nickname != data.After.Nickname)
                            {
                                msg += string.Format(adminUsername + " changed {0}'s nickname from *{1}* to *{2}*\n", targetUsername,
                                                     (data.Before.Nickname == null) ? data.Target.Username : data.Before.Nickname,
                                                     (data.After.Nickname == null) ? data.Target.Username : data.After.Nickname);
                            }

                            Console.WriteLine(msg);
                            embed.WithColor(255, 255, 0);
                            send = true;
                        }
                        else if (logEntry.Action == ActionType.Kick)
                        {
                            KickAuditLogData data           = (KickAuditLogData)logEntry.Data;
                            string           targetUsername = "******" + data.Target + "** _(" + data.Target.Id + ")_";
                            msg = targetUsername + " was kicked by " + adminUsername +
                                  "\nReason: " + logEntry.Reason;

                            embed.WithColor(new Color(255, 0, 0));
                            send = true;
                        }
                        else if (logEntry.Action == ActionType.Ban)
                        {
                            BanAuditLogData data           = (BanAuditLogData)logEntry.Data;
                            string          targetUsername = "******" + data.Target + "** _(" + data.Target.Id + ")_";
                            msg = targetUsername + " was banned by " + adminUsername +
                                  "\nReason: " + logEntry.Reason;

                            embed.WithColor(new Color(255, 0, 0));
                            send = true;
                        }
                        else if (logEntry.Action == ActionType.Unban)
                        {
                            UnbanAuditLogData data           = (UnbanAuditLogData)logEntry.Data;
                            string            targetUsername = "******" + data.Target + "** _(" + data.Target.Id + ")_";
                            msg = targetUsername + " was unbanned by " + adminUsername +
                                  "\nReason: " + logEntry.Reason;

                            embed.WithColor(new Color(255, 255, 0));
                            send = true;
                        }
                        else if (logEntry.Action == ActionType.Prune)
                        {
                            PruneAuditLogData data = (PruneAuditLogData)logEntry.Data;
                            msg = adminUsername + " removed " + data.MembersRemoved + " users in a " + data.PruneDays + " day prune" +
                                  "\nReason: " + logEntry.Reason;

                            embed.WithColor(new Color(255, 0, 0));
                            send = true;
                        }
                        else if (logEntry.Action == ActionType.MessageDeleted)
                        {
                            MessageDeleteAuditLogData data = (MessageDeleteAuditLogData)logEntry.Data;
                            msg = adminUsername + " deleted _" + data.MessageCount + "_ messages in **#" + guild.GetChannel(data.ChannelId).Name + "** channel";

                            embed.WithColor(new Color(255, 190, 0));
                            send = true;
                        }
                        else if (logEntry.Action == ActionType.InviteCreated)
                        {
                            InviteCreateAuditLogData data = (InviteCreateAuditLogData)logEntry.Data;
                            string creatorUsername        = "******" + data.Creator + "** _(" + data.Creator.Id + ")_";
                            msg = creatorUsername + " created invite **" + data.Code + "**\n" +
                                  "Channel: " + guild.GetChannel(data.ChannelId).Name + "\n" +
                                  "Max Uses: " + data.MaxUses + "\n" +
                                  "Max Age: " + (data.MaxAge / 60 / 60 / 24) + "\n" +
                                  "Temporary: " + data.Temporary;

                            embed.WithColor(new Color(255, 255, 0));
                            send = true;
                        }
                        else if (logEntry.Action == ActionType.InviteDeleted)
                        {
                            InviteDeleteAuditLogData data = (InviteDeleteAuditLogData)logEntry.Data;
                            string creatorUsername        = "******" + data.Creator + "** _(" + data.Creator.Id + ")_";
                            msg = adminUsername + " deleted invite **" + data.Code + "** created by " + creatorUsername + "\n" +
                                  "Channel: " + guild.GetChannel(data.ChannelId).Name + "\n" +
                                  "Uses: " + data.Uses + "\n" +
                                  "Max Uses: " + data.MaxUses + "\n" +
                                  "Max Age: " + (data.MaxAge / 60 / 60 / 24) + "\n" +
                                  "Temporary: " + data.Temporary;

                            embed.WithColor(new Color(255, 255, 0));
                            send = true;
                        }
                        else
                        {
                            ConsolePrint("LE_Action: " + logEntry.Action + "; LE_Data: " + logEntry.Data.ToString() + "; ");
                        }
                        embed.WithAuthor(title, logEntry.User.GetAvatarUrl());
                        embed.WithDescription(msg);
                        embed.WithFooter(logEntry.Id.ToString());
                        if (send)
                        {
                            await chan.SendMessageAsync("", false, embed.Build());
                        }
                        if (send)
                        {
                            ConsolePrint("Sent " + embed.Description);
                        }
                    }//end restAuditLog loop
                    ConsolePrint("Finished Audit Log for " + guild.Name);
                    break;
                } // end if security channel
            }     // end for each text channel in guild
        }