Beispiel #1
0
 public async Task UnbanGuildMember(ulong user, [Remainder] string reason = null)
 {
     if (GeneralFunctions.CheckUlong(user) == true)
     {
         if (await DiscordBot.CheckIfBanned(Context.Guild.Id, user) == true)
         {
             await Context.Guild.RemoveBanAsync(user);
             await ReplyAsync($"The user with ID: {user} is unbanned.");
         }
         else
         {
             await ReplyAsync("Error 0x3: This user doesn't seem to be banned. Please check your command input.");
         }
     }
     else
     {
         await ReplyAsync("Error 0x2: This doesn't seem like a valid user id. Please check your command input.");
     }
 }
Beispiel #2
0
        public async Task BanGuildMember(string user, [Remainder] string reason = null)
        {
            if (string.IsNullOrEmpty(reason))
            {
                reason = "There was no reason given.";
            }
            IGuildUser bannedUser;

            if (GeneralFunctions.CheckUlong(user) == true && DiscordBot.CheckIsInGuild(Context.Guild.Id, Convert.ToUInt64(user)))
            {
                bannedUser = await Context.Guild.GetUserAsync(Convert.ToUInt64(user));
            }
            else if (GeneralFunctions.CheckUlong(user) == false && Context.Message.MentionedUserIds.Count >= 1 && DiscordBot.CheckIsInGuild(Context.Guild.Id, Context.Message.MentionedUserIds.First()))
            {
                bannedUser = await Context.Guild.GetUserAsync(Context.Message.MentionedUserIds.First());
            }
            else if ((GeneralFunctions.CheckUlong(user) == true && DiscordBot.CheckIsInGuild(Context.Guild.Id, Convert.ToUInt64(user)) == false) || (GeneralFunctions.CheckUlong(user) == false && Context.Message.MentionedUserIds.Count >= 1 && DiscordBot.CheckIsInGuild(Context.Guild.Id, Context.Message.MentionedUserIds.First()) == false))
            {
                await ReplyAsync("Error 0x2: This user was not found in this server.");

                return;
            }
            else if (GeneralFunctions.CheckUlong(user) == false || (GeneralFunctions.CheckUlong(user) == false && Context.Message.MentionedUserIds.Count == 0))
            {
                await ReplyAsync("Error 0x3: There was not a valid id or mention found.");

                return;
            }
            else
            {
                await ReplyAsync("Error 0x4: An error occured during command execution please check your input");

                return;
            }

            #region comment
            //Continue if:
            //1.  The user is in the guild.
            //2.  The user id is valid or if the mention is valid.

            //Errors:

            //Error 1: invalid mention or id
            //Error 2: User not found
            //Error 3: Given too many users
            //Error 4: Unknown Error
            #endregion

            BanInfo bannedUserInfo = new BanInfo
            {
                UserId             = bannedUser.Id,
                Username           = bannedUser.Username,
                UserDiscriminator  = bannedUser.Discriminator,
                UserNickname       = bannedUser.Nickname,
                UserCreationDate   = bannedUser.CreatedAt,
                JoinDate           = bannedUser.JoinedAt,
                StaffId            = Context.Message.Author.Id,
                StaffUsername      = Context.Message.Author.Username,
                StaffDiscriminator = Context.Message.Author.Discriminator,
                Source             = "Ban Command",
                Reason             = reason
            };
            await Context.Guild.AddBanAsync(bannedUser, 0, DiscordBot.client.CurrentUser.Id.ToString() + " - " + reason);

            if (await DiscordBot.CheckIfBanned(Context.Guild.Id, bannedUserInfo.UserId) == true)
            {
                await ReplyAsync("The user was banned.");

                await DiscordBot.SendBanMessage(bannedUserInfo);
            }
            else
            {
                await ReplyAsync("Error 0x5: User was not banned for an unknown reason.");
            }
        }
Beispiel #3
0
        public async Task WhoIs(string inputUser)
        {
            SocketGuildUser user;

            if (GeneralFunctions.CheckUlong(inputUser) == true && DiscordBot.CheckIsInGuild(Context.Guild.Id, Convert.ToUInt64(inputUser)))
            {
                user = await Context.Guild.GetUserAsync(Convert.ToUInt64(inputUser)) as SocketGuildUser;
            }
            else if (GeneralFunctions.CheckUlong(inputUser) == false && Context.Message.MentionedUserIds.Count >= 1 && DiscordBot.CheckIsInGuild(Context.Guild.Id, Context.Message.MentionedUserIds.First()))
            {
                user = await Context.Guild.GetUserAsync(Context.Message.MentionedUserIds.First()) as SocketGuildUser;
            }
            else if ((GeneralFunctions.CheckUlong(inputUser) == true && DiscordBot.CheckIsInGuild(Context.Guild.Id, Convert.ToUInt64(inputUser)) == false) || (GeneralFunctions.CheckUlong(inputUser) == false && Context.Message.MentionedUserIds.Count >= 1 && DiscordBot.CheckIsInGuild(Context.Guild.Id, Context.Message.MentionedUserIds.First()) == false))
            {
                await ReplyAsync("Error 0x2: This user was not found in this server.");

                return;
            }
            else if (GeneralFunctions.CheckUlong(inputUser) == false || (GeneralFunctions.CheckUlong(inputUser) == false && Context.Message.MentionedUserIds.Count == 0))
            {
                await ReplyAsync("Error 0x3: There was not a valid id or mention found.");

                return;
            }
            else
            {
                await ReplyAsync("Error 0x4: An error occured during command execution please check your input");

                return;
            }

            string roles    = "";
            string nickname = "";

            //SocketGuildUser user = DiscordBot.client.GetGuild(Context.Guild.Id).GetUser(userId);

            foreach (var role in user.Roles)
            {
                if (role == user.Roles.Last())
                {
                    roles += $"{role.Name}.";
                }

                else
                {
                    roles += $"{role.Name}, ";
                }
            }

            if (user.Username == null)
            {
                nickname = "There is no nickname used.";
            }

            else
            {
                nickname = user.Nickname;
            }

            var builder = new EmbedBuilder();

            builder.WithColor(Color.Blue);
            builder.WithTitle("User information:");
            builder.WithDescription("The following data is all the data about te user in this guild that could be retrieved.");
            builder.AddField("User data:", $"User Id: {user.Id}.\n" +
                             $"Username: {user.Username}#{user.DiscriminatorValue}.\n" +
                             $"Nickname: {user.Nickname}.\n" +
                             $"User registered at: {user.CreatedAt}.\n" +
                             $"User status: {user.Status}.\n");
            builder.AddField("Guild information:", $"User joined at: { user.JoinedAt}.\n" +
                             $"User hierarchy: {user.Hierarchy}.\n" +
                             $"User roles: {roles}\n" +
                             $"User permission  value: {user.GuildPermissions.RawValue}");

            builder.ThumbnailUrl = user.GetAvatarUrl();
            builder.WithFooter(footer => footer.WithText("The CyberSec Lounge"));
            builder.WithCurrentTimestamp();

            await ReplyAsync("This is the information that was retrieved from the database.", false, builder.Build());
        }