Example #1
0
        public async Task UserInfoAsync([Remainder] string args = null)
        {
            // Moderator check
            SocketGuildUser user = BotUtils.GetGUser(Context);

            if (ServerData.HasPermissionLevel(user, ServerData.PermissionLevel.MODERATOR))
            {
                // Only command was used. Get info on current user
                if (string.IsNullOrWhiteSpace(args))
                {
                    await DisplayUserInfoEmbed(user);

                    return;
                }
                else
                {
                    List <SocketGuildUser> users = BotUtils.GetUser(Context.Message);

                    // No user found
                    if (users.Count == 0)
                    {
                        await ReplyAsync(BotUtils.KamtroText("I could not find that user. Please try again and make sure you are spelling the user correctly."));

                        return;
                    }
                    // Get info on user
                    else if (users.Count == 1)
                    {
                        await DisplayUserInfoEmbed(users[0]);

                        return;
                    }
                    // Name is too vague. More than 10 users found
                    else if (users.Count > 10)
                    {
                        await ReplyAsync(BotUtils.KamtroText("That name is too vague. Please try specifying the user."));

                        return;
                    }
                    // More than one user mentioned, or ambiguous user
                    else
                    {
                        UserSelectionEmbed use = new UserSelectionEmbed(users, DisplayUserInfoEmbed, BotUtils.GetGUser(Context.User.Id));
                        await use.Display(Context.Channel);
                    }
                }
            }
        }
Example #2
0
        public async Task RepUserAsync([Remainder] string username = "")
        {
            TimeSpan ts = BotUtils.GetTimeDelay(BotUtils.TimeScale.WEEK);

            if (!UserDataManager.CanAddRep(BotUtils.GetGUser(Context)))
            {
                await ReplyAsync(BotUtils.KamtroText($"You have no more reputation points left to give! Resets in {ts.Days} day{((ts.Days == 1) ? "" : "s")}, {ts.Hours} hour{((ts.Hours == 1) ? "" : "s")}, {ts.Minutes} minute{((ts.Minutes == 1) ? "" : "s")}, and {ts.Seconds} second{((ts.Seconds == 1) ? "" : "s")}"));

                return;
            }

            if (string.IsNullOrEmpty(username))
            {
                int rep = UserDataManager.GetUserData(BotUtils.GetGUser(Context)).ReputationToGive;
                await ReplyAsync(BotUtils.KamtroText($"You have {rep} reputation point{(rep == 1 ? "" : "s")} left to give. Resets in {ts.Days} day{((ts.Days == 1) ? "" : "s")}, {ts.Hours} hour{((ts.Hours == 1) ? "" : "s")}, {ts.Minutes} minute{((ts.Minutes == 1) ? "" : "s")}, and {ts.Seconds} second{((ts.Seconds == 1) ? "" : "s")}"));

                return;
            }

            List <SocketGuildUser> users = BotUtils.GetUser(Context.Message);

            if (users.Count == 0)
            {
                await ReplyAsync(BotUtils.KamtroText("I can't find a user with that name. Make sure the name is spelt correctly!"));

                return;
            }
            else if (users.Count > 10)
            {
                await ReplyAsync(BotUtils.KamtroText("Please be more specific! You can attach a discriminator if you need to (Username#1234)"));

                return;
            }
            else if (users.Count == 1)
            {
                await AddRep(users[0]);
            }
            else
            {
                UserSelectionEmbed use = new UserSelectionEmbed(users, AddRep, BotUtils.GetGUser(Context));
                await use.Display(Context.Channel);
            }
        }
Example #3
0
        public async Task AddAdminAsync([Remainder] string user = "")
        {
            if (!ServerData.HasPermissionLevel(BotUtils.GetGUser(Context), ServerData.PermissionLevel.ADMIN))
            {
                return;                                                                                                // This is an admin only command
            }
            // This command adds an admin to the bot config.

            List <SocketGuildUser> users = BotUtils.GetUser(Context.Message);

            if (users.Count == 0)
            {
                await ReplyAsync(BotUtils.KamtroText("I can't find a user with that name, make sure the name is spelt correctly!"));

                return;
            }
            else if (users.Count > 10)
            {
                await ReplyAsync(BotUtils.KamtroText("Please be more specific! You can attach a discriminator if you need to (Username#1234)"));

                return;
            }
            else if (users.Count == 1)
            {
                // Check if the user is already an admin
                if (Program.Settings.AdminUsers.Contains(users[0].Id))
                {
                    await ReplyAsync(BotUtils.KamtroText(users[0].Username + "#" + users[0].Discriminator + " is already an admin!"));

                    return;
                }

                await AddAdmin(users[0]);
            }
            else
            {
                UserSelectionEmbed use = new UserSelectionEmbed(users, AddAdmin, BotUtils.GetGUser(Context));
                await use.Display(Context.Channel);
            }

            Program.ReloadConfig();
        }
Example #4
0
        public async Task BanMemberAsync([Remainder] string name = "")
        {
            SocketGuildUser caller = BotUtils.GetGUser(Context);

            if (!ServerData.HasPermissionLevel(caller, ServerData.PermissionLevel.MODERATOR))
            {
                return;
            }

            if (name == "")
            {
                await ReplyAsync(BotUtils.KamtroText("Please specify a user!"));

                return;
            }

            List <SocketGuildUser> users = BotUtils.GetUser(Context.Message);

            if (users.Count == 0)
            {
                await ReplyAsync(BotUtils.KamtroText("I can't find a user with that name. Make sure the name is spelt correctly!"));

                return;
            }
            else if (users.Count > 10)
            {
                await ReplyAsync(BotUtils.KamtroText("Please be more specific! You can attach a discriminator if you need to (Username#1234)"));

                return;
            }
            else if (users.Count == 1)
            {
                await BanUser(users[0]);
            }
            else
            {
                UserSelectionEmbed use = new UserSelectionEmbed(users, BanUser, BotUtils.GetGUser(Context));
                await use.Display(Context.Channel);
            }
        }
Example #5
0
        public async Task ProfileAsync([Remainder] string username = "")
        {
            if (username == "")
            {
                // user's profile
                SocketGuildUser usr = BotUtils.GetGUser(Context);

                ProfileEmbed pe = new ProfileEmbed(UserDataManager.GetUserData(usr), usr);
                UpdateUserNames(usr);
                await pe.Display(Context.Channel);

                return;
            }

            // else, the requested user's profile

            List <SocketGuildUser> users = BotUtils.GetUser(Context.Message);

            if (users.Count == 0)
            {
                await ReplyAsync(BotUtils.KamtroText("I can't find a user with that name, make sure the name is spelt correctly!"));

                return;
            }
            else if (users.Count > 10)
            {
                await ReplyAsync(BotUtils.KamtroText("Please be more specific! You can attach a discriminator if you need to (Username#1234)"));

                return;
            }
            else if (users.Count == 1)
            {
                await Profile(users[0]);
            }
            else
            {
                UserSelectionEmbed use = new UserSelectionEmbed(users, Profile, BotUtils.GetGUser(Context));
                await use.Display(Context.Channel);
            }
        }
Example #6
0
        public async Task PermCheckAsync([Remainder] string user = "")
        {
            if (!ServerData.HasPermissionLevel(BotUtils.GetGUser(Context), ServerData.PermissionLevel.ADMIN))
            {
                return;                                                                                                // This is an admin only command
            }
            if (string.IsNullOrWhiteSpace(user))
            {
                await PermCheck(BotUtils.GetGUser(Context));
            }
            else
            {
                List <SocketGuildUser> users = BotUtils.GetUser(Context.Message);

                if (users.Count == 0)
                {
                    await ReplyAsync(BotUtils.KamtroText("I can't find a user with that name, make sure the name is spelt correctly!"));

                    return;
                }
                else if (users.Count > 10)
                {
                    await ReplyAsync(BotUtils.KamtroText("Please be more specific! You can attach a discriminator if you need to (Username#1234)"));

                    return;
                }
                else if (users.Count == 1)
                {
                    await PermCheck(users[0]);
                }
                else
                {
                    UserSelectionEmbed use = new UserSelectionEmbed(users, PermCheck, BotUtils.GetGUser(Context));
                    await use.Display(Context.Channel);
                }
            }
        }
Example #7
0
        public async Task VoiceKickAsync([Remainder] string args = null)
        {
            // Moderator check
            SocketGuildUser user = BotUtils.GetGUser(Context);

            if (ServerData.HasPermissionLevel(user, ServerData.PermissionLevel.MODERATOR))
            {
                // Only command was used. Reply to user saying a user needs to be specified for the command.
                if (string.IsNullOrWhiteSpace(args))
                {
                    await ReplyAsync(BotUtils.KamtroText("You did not specify the user to remove from voice chat."));

                    return;
                }
                else
                {
                    List <SocketGuildUser> users = BotUtils.GetUser(Context.Message);

                    // No user found
                    if (users.Count == 0)
                    {
                        await ReplyAsync(BotUtils.KamtroText("I could not find that user. Please try again and make sure you are spelling the user correctly."));

                        return;
                    }
                    // Check for users in voice channels and remove those that aren't
                    else
                    {
                        List <SocketGuildUser> removeUsers = new List <SocketGuildUser>();
                        foreach (SocketGuildUser currentUser in users)
                        {
                            if (currentUser.VoiceChannel == null)
                            {
                                removeUsers.Add(currentUser);
                            }
                        }

                        foreach (SocketGuildUser currentUser in removeUsers)
                        {
                            users.Remove(currentUser);
                        }
                    }

                    // No users found in voice channels
                    if (users.Count == 0)
                    {
                        await ReplyAsync(BotUtils.KamtroText("That user is not in a voice channel."));
                    }
                    // Create temporary voice channel, move user, then delete voice channel
                    else if (users.Count == 1)
                    {
                        SocketVoiceChannel currentVc = users[0].VoiceChannel;
                        await users[0].ModifyAsync(x => x.Channel = null);

                        await ReplyAsync(BotUtils.KamtroText($"{users[0].GetDisplayName()} has been removed from {currentVc.Name}."));

                        return;
                    }
                    // Name is too vague. More than 10 users found
                    else if (users.Count > 10)
                    {
                        await ReplyAsync(BotUtils.KamtroText("That name is too vague. Please try specifying the user."));

                        return;
                    }
                    // More than one user mentioned, or ambiguous user
                    else
                    {
                        UserSelectionEmbed use = new UserSelectionEmbed(users, VoiceKickUserAsync, BotUtils.GetGUser(Context.User.Id));
                        await use.Display(Context.Channel);
                    }
                }
            }
        }
Example #8
0
        public async Task DirectMessageAsync([Remainder] string args = null)
        {
            if (!ServerData.HasPermissionLevel(BotUtils.GetGUser(Context), ServerData.PermissionLevel.ADMIN))
            {
                return;
            }

            SocketGuildUser user = BotUtils.GetGUser(Context);

            // Check if admin
            if (user.GuildPermissions.Administrator || ServerData.AdminUsers.Contains(user))
            {
                /// TO DO
                ///
                /// Get the user in remainder of the message [DONE]
                /// Make prompt on what message to send to the user [DONE]
                /// Include attachments
                /// Sends the message to the user [DONE]

                // Inform user to specify the user to DM
                if (args == null)
                {
                    await ReplyAsync(BotUtils.KamtroText("You must specify the user to directly message."));

                    return;
                }
                else
                {
                    // Split the message to get the corresponding parts
                    string[]        msgSplit = Context.Message.Content.Split(' ');
                    SocketGuildUser target   = BotUtils.GetUser(msgSplit[1]);

                    if (target == null)
                    {
                        await ReplyAsync(BotUtils.KamtroText("I cannot find that user."));

                        return;
                    }
                    else if (msgSplit.Length == 2)
                    {
                        /// To Do:
                        /// Show embed for messaging the user [DONE]
                        /// Toggle on messaging that user

                        MessagingEmbed embed = new MessagingEmbed(user);
                        // Send embed in DMs to user
                        try
                        {
                            await embed.Display((IMessageChannel)user.GetOrCreateDMChannelAsync());
                        }
                        // Could not send to the user
                        catch (Exception)
                        {
                            if (user.Nickname != null)
                            {
                                await ReplyAsync(BotUtils.KamtroText($"I cannot send direct messages to you, {user.Nickname}. Please allow direct messages from me."));
                            }
                            else
                            {
                                await ReplyAsync(BotUtils.KamtroText($"I cannot send direct messages to you, {user.Username}. Please allow direct messages from me."));
                            }
                        }
                    }
                    else
                    {
                        // Build the message back together
                        string msgSend = "";
                        for (int i = 2; i < msgSplit.Length; i++)
                        {
                            msgSend += msgSplit[i];
                            if (i != msgSplit.Length - 1)
                            {
                                msgSend += " ";
                            }
                        }

                        // Send message and notify user using the command
                        try
                        {
                            await target.SendMessageAsync(msgSend);
                            await ReplyAsync(BotUtils.KamtroText($"Message sent to {target.Username}#{user.Discriminator}."));
                        }
                        // Could not send to the user
                        catch (Exception)
                        {
                            await ReplyAsync(BotUtils.KamtroText($"Message could not be sent to the user. The user either has messages from only friends allowed or has blocked me."));
                        }
                    }
                }
            }
        }