Ejemplo n.º 1
0
        public async Task BanAsync(IUser requestedUser, [Remainder] string reason = null)
        {
            using (DiscordContext db = new DiscordContext())
            {
                ulong userId = Context.User.Id;
                if (db.Users.Where(x => x.DiscordId == userId).FirstOrDefault().Privilege < User.Privileges.Moderator)
                {
                    Logger.Warning(Context.User.Username, "User tried to use ban command and failed");
                    await ReplyAsync($"Looks like someone wants to *get* a ban. Call a mod will ya?");

                    return;
                }

                if (reason == null)
                {
                    await Context.Guild.AddBanAsync(requestedUser, 0, $"Banned by {Context.User.Username}: no reason given");

                    return;
                }

                await Context.Guild.AddBanAsync(requestedUser, 0, $"Banned by {Context.User.Username}: {reason}");

                await BotReporting.ReportAsync(ReportColors.adminCommand,
                                               (SocketTextChannel)Context.Channel,
                                               $"Ban Command by {Context.User.Username}",
                                               $"<@{requestedUser.Id}> has been kicked. Reason: `{reason}`",
                                               Context.User,
                                               (SocketUser)requestedUser).ConfigureAwait(false);
            }
        }
Ejemplo n.º 2
0
        public async Task KickAsync(IUser requestedUser, [Remainder] string reason = null)
        {
            using (DiscordContext db = new DiscordContext())
            {
                ulong userId = Context.User.Id;
                if (db.Users.Where(x => x.DiscordId == userId).FirstOrDefault().Privilege < User.Privileges.Moderator)
                {
                    Logger.Warning(Context.User.Username, "User tried to use kick command and failed");
                    await ReplyAsync($"No can do Jonny boy. You need moddlet for that.");

                    return;
                }

                await KickUserHelper.KickAsync(Context.Channel as SocketTextChannel, requestedUser as SocketGuildUser);

                Logger.Warning(Context.User.Username, $"Kicked {requestedUser.Username} by {Context.User.Username}");

                await BotReporting.ReportAsync(ReportColors.adminCommand,
                                               (SocketTextChannel)Context.Channel,
                                               $"Kick Command by {Context.User.Username}",
                                               $"<@{requestedUser.Id}> has been kicked",
                                               Context.User,
                                               (SocketUser)requestedUser).ConfigureAwait(false);
            }
        }
Ejemplo n.º 3
0
        public async Task denyUserAsync(IUser requestedUser)
        {
            using (DiscordContext db = new DiscordContext())
            {
                ulong userId = Context.User.Id;
                if (db.Users.Where(x => x.DiscordId == userId).FirstOrDefault().Privilege < User.Privileges.Moderator)
                {
                    Logger.Warning(Context.User.Username, "User tried to use deny command and failed");
                    await ReplyAsync($"You're not my real mom. Go away.");

                    return;
                }
            }

            if (Context.Channel.Id != Channels.ProvingGrounds)
            {
                await ReplyAsync("You can only use the deny command in #proving-grounds.");

                return;
            }

            await ReplyAsync($"<@{requestedUser.Id}> has been denied by <@{Context.User.Id}>.");

            await BotReporting.ReportAsync(ReportColors.modCommand,
                                           Context.Channel as SocketTextChannel,
                                           $"User denied",
                                           $"<@{Context.User.Id}> denied <@{requestedUser.Id}>",
                                           Context.User,
                                           requestedUser as SocketUser);

            await KickUserHelper.KickAsync(Context.Channel as SocketTextChannel, requestedUser as SocketGuildUser);
        }
Ejemplo n.º 4
0
        public async Task InterventionAsync(IUser requestedUser)
        {
            await BotReporting.ReportAsync(ReportColors.modCommand,
                                           (SocketTextChannel)Context.Channel,
                                           $"Intervention command by {Context.User.Username}",
                                           $"<@{Context.User.Id}> placed <@{requestedUser.Id}> in an intervention.",
                                           Context.User,
                                           (SocketUser)requestedUser).ConfigureAwait(false);

            using (DiscordContext db = new DiscordContext())
            {
                ulong userId = Context.User.Id;
                if (db.Users.Where(x => x.DiscordId == userId).FirstOrDefault().Privilege == User.Privileges.User)
                {
                    Logger.Warning(Context.User.Username, "Failed intervention command. Not enough privileges.");
                    await ReplyAsync("You are not a moderator, go away.");

                    return;
                }

                try
                {
                    // Look for intervention role
                    SocketRole intervetionRole = Context.Guild.Roles.Where(x => x.Name.ToLower() == "intervention").First();

                    // give user the role
                    SocketGuildUser user = requestedUser as SocketGuildUser;
                    await user.AddRoleAsync(intervetionRole);

                    // Create the channel and add the user
                    RestTextChannel interventionChannel = await Context.Guild.CreateTextChannelAsync($"intervention-{user.Id}");

                    await interventionChannel.AddPermissionOverwriteAsync(Context.Guild.EveryoneRole, Permissions.removeAllPerm);

                    await interventionChannel.AddPermissionOverwriteAsync(user, Permissions.userPerm);

                    await interventionChannel.AddPermissionOverwriteAsync(Context.Guild.Roles.Where(r => r.Name == Roles.Staff).FirstOrDefault(), Permissions.adminPerm);

                    // Notify user of intervention
                    await interventionChannel.SendMessageAsync($"{user.Mention} you have been placed in intervention due to either your profile or attitude in the server.\n" +
                                                               $"A staff member should be here shortly to assist you.");
                }
                catch (Exception e)
                {
                    await BotReporting.ReportAsync(ReportColors.exception,
                                                   (SocketTextChannel)Context.Channel,
                                                   e.Message,
                                                   $"Source: {e.Source}\n {e.InnerException}\n {e.StackTrace}",
                                                   Engine.luna);

                    return;
                }


                // Add permissions (user and staff)
                // un-limbo person
            }
        }
Ejemplo n.º 5
0
        public async Task SetOpenDMAsync()
        {
            SocketUser author = Context.User;
            ulong      userId = author.Id;

            SocketGuildChannel guildChannel = Context.Channel as SocketGuildChannel;
            List <SocketRole>  roles        = guildChannel.Guild.Roles.ToList();

            using (DiscordContext db = new DiscordContext())
            {
                User user = db.Users.FirstOrDefault(x => x.DiscordId == userId);

                if (user != null)
                {
                    Predicate <SocketRole> RoleFinder       = (SocketRole sr) => { return(sr.Name == Roles.OpenDM); };
                    SocketRole             AnnouncementRole = roles.Find(RoleFinder);
                    AnnouncementRole = roles.Find(RoleFinder);

                    // Check if role was found on the server
                    if (AnnouncementRole == null)
                    {
                        Logger.Warning("System", $"Couldn't find role {Roles.OpenDM}");
                        await BotReporting.ReportAsync(ReportColors.exception, Context.Channel as SocketTextChannel, "Error finding Role.", $"Could not find role: {Roles.OpenDM}, contact admin.", Context.User);
                        await ReplyAsync("Error finding role, notifying staff.");
                    }

                    if (user.OpenDM == true)
                    {
                        // Remove the role
                        await guildChannel.GetUser((ulong)userId).RemoveRoleAsync(AnnouncementRole);

                        Logger.Verbose("System", $"found role {AnnouncementRole.Name} and removed it.");
                        user.OpenDM = false;

                        await ReplyAsync($"<@{userId}> left the `{Roles.OpenDM}` role.");
                    }
                    else
                    {
                        // Add the role
                        await guildChannel.GetUser((ulong)userId).AddRoleAsync(AnnouncementRole);

                        Logger.Verbose("System", $"Found role {AnnouncementRole.Name} and added it.");
                        user.OpenDM = true;

                        await ReplyAsync($"<@{userId}> joined the `{Roles.OpenDM}` role.");
                    }

                    db.SaveChanges();
                }
                else
                {
                    Logger.Verbose(author.Username, $"Failed to find user: {userId}");
                    await ReplyAsync($"Failed to find user: `{author.Username}`");
                }
            }
        }
Ejemplo n.º 6
0
        public async Task PromoteAsync(IUser requestedUser)
        {
            SocketUser author = Context.User;

            // User to ascend
            ulong parsedUserId = requestedUser.Id;

            using (DiscordContext db = new DiscordContext())
            {
                ulong userId = author.Id;
                if (db.Users.Where(x => x.DiscordId == userId).FirstOrDefault().Privilege < User.Privileges.Admin)
                {
                    Logger.Warning(author.Id.ToString(), "User tried to use ascend command and failed");
                    await ReplyAsync($"Nice try. Dont want me calling your parents, right?");

                    return;
                }

                User user = db.Users.Where(x => x.DiscordId == parsedUserId).FirstOrDefault();
                {
                    if (user.Privilege >= User.Privileges.Moderator)
                    {
                        Logger.Info(author.Id.ToString(), $"User <@{author.Id}> already mod or above.");
                        await ReplyAsync($"<@{author.Id}> is already `mod` or above.");

                        return;
                    }

                    user.Privilege = User.Privileges.Moderator;

                    SocketGuildChannel channel = Context.Channel as SocketGuildChannel;
                    IReadOnlyCollection <SocketRole> guildRoles = channel.Guild.Roles;

                    List <SocketRole> roles = new List <SocketRole>()
                    {
                        guildRoles.Where(x => x.Name.Equals("Mod")).FirstOrDefault(),
                        guildRoles.Where(x => x.Name.Equals("Staff")).FirstOrDefault()
                    };

                    await channel.Guild.GetUser(parsedUserId).AddRolesAsync(roles);

                    Logger.Info(author.Id.ToString(), $"Made <@{requestedUser.Id}> moderator");
                    await ReplyAsync($"SMACK! <@{requestedUser.Id}> has been made `moddlet`!");
                }

                db.SaveChanges();

                await BotReporting.ReportAsync(ReportColors.adminCommand,
                                               (SocketTextChannel)Context.Channel,
                                               $"Promote Command by {Context.User.Username}",
                                               $"<@{requestedUser.Id}> has been promoted to moderator.",
                                               Context.User,
                                               (SocketUser)requestedUser).ConfigureAwait(false);
            }
        }
Ejemplo n.º 7
0
        public async Task clearAsync(int amount = 1)
        {
            using (DiscordContext db = new DiscordContext())
            {
                User author = db.Users.Where(u => u.DiscordId == Context.User.Id).FirstOrDefault();

                if (author == null)
                {
                    await BotReporting.ReportAsync(ReportColors.exception,
                                                   Context.Channel as SocketTextChannel,
                                                   "Cannot find user",
                                                   $"Cannot find `{Context.User.Username}` in the database.",
                                                   Engine.luna,
                                                   Context.User);

                    await ReplyAsync($"Cannot find {Context.User.Username} in the database.");

                    return;
                }
                else if (author.Privilege < User.Privileges.Moderator)
                {
                    await BotReporting.ReportAsync(ReportColors.modCommand,
                                                   Context.Channel as SocketTextChannel,
                                                   "User attempted mod command",
                                                   $"{Context.User.Username} attempted to use `clear` command in `{Context.Channel.Name}`\n" +
                                                   $"Message: `{Context.Message.Content}`",
                                                   Engine.luna,
                                                   Context.User);

                    await ReplyAsync($"Want me to clear *you* from this server?");

                    return;
                }

                await BotReporting.ReportAsync(ReportColors.modCommand,
                                               Context.Channel as SocketTextChannel,
                                               $"Clear all command",
                                               $"{Context.User.Username} used `clear` command in `{Context.Channel.Name}` to clear `{amount}` messages.",
                                               Engine.luna,
                                               Context.User);

                var allMessages = Context.Channel.GetMessagesAsync(amount + 1).Flatten();

                IUserMessage replyMessage = await ReplyAsync($"Deleting last `{amount}` messages");

                await(Context.Channel as SocketTextChannel).DeleteMessagesAsync(await allMessages.ToList().ConfigureAwait(false));

                Task.Run(async() =>
                {
                    Thread.Sleep(2000);
                    await replyMessage.DeleteAsync();
                }).Start();
            }
        }
Ejemplo n.º 8
0
        public async Task RegisterAllAsync()
        {
            using (DiscordContext db = new DiscordContext())
            {
                SocketUser author = Context.User;
                ulong      userId = author.Id;

                if (db.Users.Where(x => x.DiscordId == userId).FirstOrDefault().Privilege == User.Privileges.User)
                {
                    Logger.Warning(author.Username, "Failed RegisterAll command");
                    await ReplyAsync("You're not a moderator, go away.");

                    return;
                }

                Logger.Info(author.Username, "Fixing Registrations");
                await ReplyAsync("Fixing registrations...");

                SocketGuildChannel     channel = Context.Channel as SocketGuildChannel;
                List <SocketGuildUser> users   = channel.Guild.Users.ToList();

                foreach (SocketGuildUser u in users)
                {
                    if (db.Users.Where(x => x.DiscordId == u.Id).Count() == 0)
                    {
                        Logger.Verbose(author.Username, $"Creating User Data for {u.Username}");

                        User newUser = new User();
                        newUser.DiscordId        = u.Id;
                        newUser.Level            = 1;
                        newUser.Privilege        = 0;
                        newUser.TutorialFinished = false;
                        newUser.Gender           = User.Genders.Null;
                        db.Users.Add(newUser);
                        var list = db.Users.ToList();

                        Logger.Verbose(author.Username, $"Created User {newUser.ID.ToString()}");
                    }
                }

                db.SaveChanges();

                await ReplyAsync("Finished registering users.");

                Logger.Info(author.Username, "Finished registering users.");

                await BotReporting.ReportAsync(ReportColors.modCommand,
                                               (SocketTextChannel)Context.Channel,
                                               $"RegisterAll command by {Context.User.Username}",
                                               $"",
                                               Context.User).ConfigureAwait(false);
            }
        }
Ejemplo n.º 9
0
        public async Task approveUserAsync(IUser requestedUser)
        {
            using (DiscordContext db = new DiscordContext())
            {
                ulong userId = Context.User.Id;
                if (db.Users.Where(x => x.DiscordId == userId).FirstOrDefault().Privilege < User.Privileges.Moderator)
                {
                    Logger.Warning(Context.User.Username, "User tried to use approve command and failed");
                    await ReplyAsync($"You're not my real dad. Go away.");

                    return;
                }
            }

            if (Context.Channel.Id != Channels.ProvingGrounds)
            {
                await ReplyAsync("You can only use the deny command in #proving-grounds.");

                return;
            }

            await ReplyAsync($"<@{requestedUser.Id}> has been approved by <@{Context.User.Id}>.");

            await BotReporting.ReportAsync(ReportColors.modCommand,
                                           Context.Channel as SocketTextChannel,
                                           $"User approved",
                                           $"<@{Context.User.Id}> approved <@{requestedUser.Id}>",
                                           Context.User,
                                           requestedUser as SocketUser);

            // Remove Newbie role
            SocketRole newbie = Context.Guild.Roles.FirstOrDefault((role) => role.Name == Roles.Newbie);

            if (newbie == null)
            {
                Logger.Critical("!approve", "newbie role not found.");
                await BotReporting.ReportAsync(ReportColors.exception, Context.Channel as SocketTextChannel, "Couldn't find newbie role", $"Couldn't find role with name: `{Roles.Newbie}`", Context.User);

                return;
            }

            await Context.Guild.GetUser(requestedUser.Id).RemoveRoleAsync(newbie);

            // Remove from approval channel
            await Context.Guild.GetChannel(Channels.ProvingGrounds).RemovePermissionOverwriteAsync(requestedUser);

            // Server announcement
            await Context.Guild.GetTextChannel(Channels.Lobby).SendMessageAsync($"Please welcome <@{requestedUser.Id}> to the server!").ConfigureAwait(false);
        }
Ejemplo n.º 10
0
        public async Task removeWarnAsync(IUser requestedUser, int amount = 0)
        {
            using (DiscordContext db = new DiscordContext())
            {
                ulong userId = Context.User.Id;
                if (db.Users.Where(x => x.DiscordId == userId).FirstOrDefault().Privilege < User.Privileges.Moderator)
                {
                    Logger.Warning(Context.User.Username, "User tried to use removeWarn command and failed");
                    await ReplyAsync($"Tough luck kiddo, you aint got any powers over me.");

                    return;
                }
                if (amount < 0)
                {
                    await ReplyAsync($"I can't remove a negative number of warns. You gave me `{amount}`");

                    return;
                }

                User databaseUser = db.Users.Where(x => x.DiscordId == requestedUser.Id).FirstOrDefault();

                databaseUser.WarnCount = amount == 0 ? databaseUser.WarnCount - 1 : databaseUser.WarnCount - amount;

                if (databaseUser.WarnCount < 0)
                {
                    databaseUser.WarnCount = 0;
                }

                await ReplyAsync($"<@{requestedUser.Id}> warnings reduced to: {databaseUser.WarnCount}");


                await BotReporting.ReportAsync(ReportColors.modCommand,
                                               (SocketTextChannel)Context.Channel,
                                               $"{Context.User.Username} used removeWarn command",
                                               $"{Context.User.Username} set warns for {requestedUser.Username} to {databaseUser.WarnCount} in {Context.Channel.Name}.",
                                               Context.User,
                                               (SocketGuildUser)requestedUser,
                                               $"Mod ID: {Context.User.Id}");

                db.SaveChanges();
            }
        }
Ejemplo n.º 11
0
        public async Task warnAsync(IUser requestedUser)
        {
            using (DiscordContext db = new DiscordContext())
            {
                ulong userId = Context.User.Id;
                if (db.Users.Where(x => x.DiscordId == userId).FirstOrDefault().Privilege < User.Privileges.Moderator)
                {
                    Logger.Warning(Context.User.Username, "User tried to use warn command and failed");
                    await ReplyAsync($"You wanna get warned? Cause that's how you get warned.");

                    return;
                }

                User databaseUser = db.Users.Where(x => x.DiscordId == requestedUser.Id).FirstOrDefault();

                databaseUser.WarnCount++;

                // When a user reaches 5 warns they will be kicked.
                if (databaseUser.WarnCount % 5 == 0)
                {
                    await ReplyAsync($"<@{requestedUser.Id}>, we warned you and you didn't listen. Goodbye.");

                    await KickUserHelper.KickAsync((SocketTextChannel)Context.Channel, (SocketGuildUser)requestedUser);
                }
                else
                {
                    await ReplyAsync($"<@{requestedUser.Id}> you have been warned. Current: {databaseUser.WarnCount}, get 5 and you *will* be kicked.");
                }

                db.SaveChanges();

                await BotReporting.ReportAsync(ReportColors.modCommand,
                                               (SocketTextChannel)Context.Channel,
                                               $"{Context.User.Username} used warn command",
                                               $"{Context.User.Username} warned {requestedUser.Username} in {Context.Channel.Name}.",
                                               Context.User,
                                               (SocketGuildUser)requestedUser,
                                               $"Mod ID: {Context.User.Id}");
            }
        }
Ejemplo n.º 12
0
        public async Task TimeoutAsync(IUser requestedUser, int minutes)
        {
            using (DiscordContext db = new DiscordContext())
            {
                ulong userId = Context.User.Id;
                if (db.Users.Where(x => x.DiscordId == userId).FirstOrDefault().Privilege == 0)
                {
                    Logger.Warning(Context.User.Username, "Failed timout command. Not enough privileges.");
                    await ReplyAsync("You're not a moderator, go away.");

                    return;
                }

                await MuteUserHelper.MuteAsync(Context.Channel as SocketTextChannel, requestedUser as SocketGuildUser, minutes);

                await BotReporting.ReportAsync(ReportColors.modCommand,
                                               (SocketTextChannel)Context.Channel,
                                               $"Timeout command by {Context.User.Username}",
                                               $"<@{Context.User.Id}> has muted <@{requestedUser.Id}> for `{minutes}` minutes.",
                                               Context.User,
                                               (SocketUser)requestedUser).ConfigureAwait(false);
            }
        }
Ejemplo n.º 13
0
        public async Task DescendAsync(IUser requestedUser)
        {
            SocketUser author = Context.User;

            // User to descend
            ulong parsedUserId = requestedUser.Id;

            using (DiscordContext db = new DiscordContext())
            {
                ulong userId = author.Id;
                if (db.Users.Where(x => x.DiscordId == userId).FirstOrDefault().Privilege != User.Privileges.Owner)
                {
                    Logger.Warning(author.Id.ToString(), "User tried to use descend command and failed");
                    await ReplyAsync($"Nice try. Dont want me calling your parents, right?");

                    return;
                }

                User user = db.Users.Where(x => x.DiscordId == parsedUserId).FirstOrDefault();
                {
                    if (user.Privilege == User.Privileges.User)
                    {
                        Logger.Info(author.Id.ToString(), $"User <@{requestedUser.Id}> not admin.");
                        await ReplyAsync($"<@{requestedUser.Id}> is not an `admin` or `moderator`.");
                    }
                    else if (user.Privilege == User.Privileges.Moderator)
                    {
                        Logger.Info(author.Id.ToString(), $"Removed moderator from <@{requestedUser.Id}>");
                        await ReplyAsync($"<@{requestedUser.Id}> is no longer `moderator`");
                    }
                    else
                    {
                        Logger.Info(author.Id.ToString(), $"Removed admin  and moderator from <@{requestedUser.Id}>");
                        await ReplyAsync($"<@{requestedUser.Id}> is no longer `admin` or `moderator`");
                    }

                    user.Privilege = User.Privileges.User;

                    SocketGuildChannel channel = Context.Channel as SocketGuildChannel;
                    IReadOnlyCollection <SocketRole> guildRoles = channel.Guild.Roles;

                    List <SocketRole> roles = new List <SocketRole>()
                    {
                        guildRoles.Where(x => x.Name.Equals("Admin")).FirstOrDefault(),
                        guildRoles.Where(x => x.Name.Equals("Staff")).FirstOrDefault(),
                        guildRoles.Where(x => x.Name.Equals("Moddlet")).FirstOrDefault()
                    };

                    await channel.Guild.GetUser(parsedUserId).RemoveRolesAsync(roles);
                }

                db.SaveChanges();

                await BotReporting.ReportAsync(ReportColors.ownerCommand,
                                               (SocketTextChannel)Context.Channel,
                                               $"Descend Command by {Context.User.Username}",
                                               $"<@{requestedUser.Id}> has been descended to user.",
                                               Context.User,
                                               (SocketUser)requestedUser).ConfigureAwait(false);
            }
        }
Ejemplo n.º 14
0
        public async Task CleanServerAsync()
        {
            SocketUser author = Context.User;

            await BotReporting.ReportAsync(ReportColors.adminCommand,
                                           (SocketTextChannel)Context.Channel,
                                           $"CleanServer Command by {Context.User.Username}",
                                           $"",
                                           Context.User).ConfigureAwait(false);

            using (DiscordContext db = new DiscordContext())
            {
                // Check Priviledges
                ulong userId = author.Id;
                if (db.Users.Where(x => x.DiscordId == userId).FirstOrDefault().Privilege < User.Privileges.Admin)
                {
                    Logger.Warning(author.Id.ToString(), "User tried to use ascend command and failed");
                    await ReplyAsync($"Although we appreciate that you want to clean the server, this vacuum requires special operator's license.");

                    return;
                }

                await ReplyAsync("Removing users from NSFW rooms...");

                // Iterate through the users and remove underaged users from NSFW rooms
                foreach (SocketGuildUser user in Context.Guild.Users)
                {
                    Logger.Verbose("System", $"Checking for {user.Nickname}");
                    User databaseUser = db.Users.Where(x => x.DiscordId == user.Id).First();
                    if (databaseUser.Age < 18 && databaseUser.Age > 0)
                    {
                        Logger.Verbose("System", $"User age {databaseUser.Age}");
                        SocketRole role = user.Roles.Where((r) => r.Name == "SFW").FirstOrDefault();
                        if (role == null)
                        {
                            await ReplyAsync($"{user.Username} is under 18 and in NSFW rooms. Adding SFW tab.");

                            await user.AddRoleAsync(Context.Guild.Roles.Where((r) => r.Name == "SFW").FirstOrDefault());
                        }
                        Logger.Verbose("System", "User underaged and not in NSFW rooms");
                    }
                    else
                    {
                        Logger.Verbose("System", "User not underaged.");
                    }
                }

                await ReplyAsync("Finished NSFW check.");

                await ReplyAsync("Removing unused rooms...");

                // Remove rooms of users no longer in the server
                int roomsRemovedCount = 0;
                foreach (SocketGuildChannel channel in Context.Guild.TextChannels.Where(x => x.Name.StartsWith("room-")))
                {
                    if (channel == null)
                    {
                        continue;
                    }

                    // Get user ID from room name
                    string roomUserId = channel.Name.Substring(5);

                    // If user isn't in the server anymore, remove the room
                    if (Context.Guild.GetUser(ulong.Parse(roomUserId)) == null)
                    {
                        Logger.Info("System", $"Found empty room {channel.Name}, total: {roomsRemovedCount}");
                        roomsRemovedCount++;
                        await channel.DeleteAsync();
                    }
                }

                await ReplyAsync($"Finished removing rooms. Total: {roomsRemovedCount}");

                // Fix monk and other roles
            }
        }
Ejemplo n.º 15
0
        public async Task PurgeAsync()
        {
            SocketUser author = Context.User;

            using (DiscordContext db = new DiscordContext())
            {
                if (db.Users.Where(x => x.DiscordId == author.Id).FirstOrDefault().Privilege < User.Privileges.Admin)
                {
                    Logger.Debug(author.Username, "User attempted pruge command");
                    await ReplyAsync("Do you want to start a riot? ");
                }

                await BotReporting.ReportAsync(ReportColors.adminCommand,
                                               (SocketTextChannel)Context.Channel,
                                               $"Purge Command by {Context.User.Username}",
                                               $"<@{Context.User.Id}> started a purge.",
                                               Context.User).ConfigureAwait(false);

                SocketGuildChannel     channel = Context.Channel as SocketGuildChannel;
                List <SocketGuildUser> users   = channel.Guild.Users.ToList();

                await ReplyAsync("Let the purge begin! :trumpet: ");

                Logger.Debug(author.Username, "Purging the server!");

                DateTime twoWeeksAgo = DateTime.UtcNow.AddDays(-14);

                foreach (SocketGuildUser u in users)
                {
                    User databaseUser = db.Users.Where(x => x.DiscordId == u.Id).FirstOrDefault();

                    if (databaseUser == null)
                    {
                        Logger.Warning("System", $"{u.Username} not registered!");
                        continue;
                    }

                    if (databaseUser.Privilege >= User.Privileges.Moderator)
                    {
                        Logger.Info("System", $"Skipping: {u.Username}, user is moderator or higher.");
                        continue;
                    }

                    if (u.Id == 155149108183695360 || u.Id == UserIds.Luna)
                    {
                        Logger.Info("System", $"Skipping: {u.Username}, bot");
                        continue;
                    }

                    // check if user has messaged in the past 2 weeks. Kick if false
                    if (databaseUser.LastMessage.Subtract(twoWeeksAgo).TotalDays < 0)//&& databaseUser.TutorialFinished == true)
                    {
                        Thread.Sleep(500);
                        Logger.Info("System", $"Purging:  {u.Username} for inactivity.");
                        await KickUserHelper.KickAsync(channel as SocketTextChannel, u);
                    }
                    else if (databaseUser.TutorialFinished == false)
                    {
                        Logger.Verbose("System", $"Skipping: {u.Username}, tutorial not finished.");
                    }
                    else
                    {
                        Logger.Verbose("System", $"Skipping: {u.Username}, active user.");
                    }
                }

                await ReplyAsync("Purging finished. You all, are the lucky few...");
            }
        }
Ejemplo n.º 16
0
        public async Task fixRolesAsync()
        {
            using (DiscordContext db = new DiscordContext())
            {
                User author = db.Users.Where(u => u.DiscordId == Context.User.Id).FirstOrDefault();

                if (author == null)
                {
                    await BotReporting.ReportAsync(ReportColors.exception,
                                                   Context.Channel as SocketTextChannel,
                                                   "Cannot find user",
                                                   $"Cannot find `{Context.User.Username}` in the database.",
                                                   Engine.luna,
                                                   Context.User);

                    await ReplyAsync($"Cannot find {Context.User.Username} in the database.");

                    return;
                }
                else if (author.Privilege < User.Privileges.Moderator)
                {
                    await BotReporting.ReportAsync(ReportColors.modCommand,
                                                   Context.Channel as SocketTextChannel,
                                                   "User attempted mod command",
                                                   $"{Context.User.Username} attempted to use `fixroles` command in `{Context.Channel.Name}`:\n" +
                                                   $"Message: `{Context.Message.Content}`",
                                                   Engine.luna,
                                                   Context.User);

                    await ReplyAsync($"Get out of here chump");

                    return;
                }

                await BotReporting.ReportAsync(ReportColors.modCommand,
                                               Context.Channel as SocketTextChannel,
                                               $"Fix Roles command",
                                               $"{Context.User.Username} used `fixroles` command in `{Context.Channel.Name}`.",
                                               Engine.luna,
                                               Context.User);

                await ReplyAsync("Applying `Verified` role to users above level 10...");

                SocketRole verifiedRole = Context.Guild.Roles.Where(r => r.Name == Roles.Verified).FirstOrDefault();

                if (verifiedRole == null)
                {
                    await ReplyAsync("Verified role not found!");

                    return;
                }

                foreach (SocketGuildUser discordUser in Context.Guild.Users)
                {
                    if (db.Users.Where(u => u.DiscordId == discordUser.Id && u.Level >= 10).FirstOrDefault() != null)
                    {
                        await Context.Guild.GetUser(discordUser.Id).AddRoleAsync(verifiedRole);
                    }
                }

                await ReplyAsync("Finished adding `Verified` role.");
            }
        }
Ejemplo n.º 17
0
        public async Task SetAsync(IUser requestedUser, string attribute, [Remainder] string content)
        {
            using (DiscordContext db = new DiscordContext())
            {
                SocketUser author = Context.User;

                // check privileges
                ulong userId = author.Id;
                User  user   = db.Users.FirstOrDefault(x => x.DiscordId == userId);
                if (user.Privilege < User.Privileges.Moderator)
                {
                    Logger.Warning(author.Username, "Not enough permissions.");
                    await ReplyAsync("Can't let you do that Dave.");

                    return;
                }

                // Modify given user
                userId = requestedUser.Id;
                user   = db.Users.FirstOrDefault(x => x.DiscordId == userId);
                if (user != null)
                {
                    switch (attribute.ToLower())
                    {
                    case "nick":
                    case "nickname":
                        SocketGuildUser gUser = (SocketGuildUser)requestedUser;
                        await gUser.ModifyAsync(u => u.Nickname = content);

                        user.Nickname = content;
                        Logger.Info(author.Username, $"Changed user <@{ requestedUser.Id}> 's nick from {user.Nickname} to {content}");
                        break;

                    case "description":
                    case "desc":
                        Logger.Info(author.Username, $"Changed user <@{requestedUser.Id}>'s description from {user.Description} to {content}");
                        user.Description = content;
                        await ReplyAsync($"Success: <@{requestedUser.Id}>'s description updated to {content}");

                        break;

                    case "fur":
                    case "f":
                        Logger.Info(author.Username, $"Changed user <@{requestedUser.Id}>'s fur from {user.Fur} to {content}");
                        user.Fur = content;
                        await ReplyAsync($"Success: <@{requestedUser.Id}>'s fur updated to {content}");

                        break;

                    case "level":
                    case "lvl":
                        if (int.TryParse(content, out int n))
                        {
                            Logger.Info(author.Username, $"Changed user <@{requestedUser.Id}>'s level from {user.Level} to {content}");
                            user.Level = Convert.ToInt32(content);
                            user.Xp    = 0;
                            await ReplyAsync($"Success: <@{requestedUser.Id}>'s level set to `{user.Level}`");
                        }
                        else
                        {
                            Logger.Warning(author.Username, "Failed database set level command");
                            await ReplyAsync($"Error: Level requires a number to set. You gave: `{content}`");
                        }
                        break;

                    case "xp":
                        if (int.TryParse(content, out int o))
                        {
                            Logger.Info(author.Username, $"Changed user <@{requestedUser.Id}>'s xp from {user.Xp} to {content}");
                            user.Xp = Convert.ToInt32(content);
                            await ReplyAsync($"Success: <@{requestedUser.Id}>'s xp set to `{user.Xp}`");
                        }
                        else
                        {
                            Logger.Warning(author.Username, "Failed database set xp command");
                            await ReplyAsync($"Error: XP requires a number to set. You gave: `{content}`");
                        }
                        break;

                    case "age":
                    case "a":
                        if (int.TryParse(content, out int m))
                        {
                            Logger.Info(author.Username, $"Changed user <@{requestedUser.Id}>'s age from {user.Age} to {content}");
                            user.Age = Convert.ToInt32(content);
                            await ReplyAsync($"Success: <@{requestedUser.Id}>'s age set to `{user.Age}`");
                        }
                        else
                        {
                            Logger.Warning(author.Username, "Failed database set age command");
                            await ReplyAsync($"Error: Age requires a number to set. You gave: `{content}`");
                        }
                        break;

                    case "gender":
                    case "g":
                        Predicate <SocketRole> genderFinder;
                        SocketRole             gender;
                        SocketTextChannel      channel     = Context.Channel as SocketTextChannel;
                        List <SocketRole>      roles       = channel.Guild.Roles.ToList();
                        SocketGuildUser        discordUser = requestedUser as SocketGuildUser;

                        User.Genders genderEnum = EnumParsers.StringToGender(content);
                        if (genderEnum == User.Genders.Null)
                        {
                            await ReplyAsync("I'm sorry I couldn't understand your message. Make sure the gender is either male, female, trans-male, trans-female, or other.\n" +
                                             $"You gave: {content}");

                            return;
                        }

                        // Remove old role
                        genderFinder = (SocketRole sr) => { return(sr.Name == user.Gender.ToString().ToLower()); };
                        gender       = roles.Find(genderFinder);
                        if (gender == null)
                        {
                            Logger.Error("System", $"Could not find user gender {user.Gender.ToString().ToString()}");
                        }
                        else
                        {
                            await discordUser.RemoveRoleAsync(gender);
                        }

                        // Add new role
                        genderFinder = (SocketRole sr) => { return(sr.Name == genderEnum.ToString().ToLower()); };
                        gender       = roles.Find(genderFinder);
                        await discordUser.AddRoleAsync(gender);

                        user.Gender = genderEnum;
                        db.SaveChanges();

                        Logger.Info(author.Username, $"Changed user <@{requestedUser.Id}>'s gender from {user.Gender} to {content}");
                        await ReplyAsync($"Success: <@{requestedUser.Id}>'s gender set to `{user.Gender}`");

                        break;

                    case "orientation":
                    case "o":
                        Predicate <SocketRole> orientationFinder;
                        SocketRole             orientation;
                        channel     = Context.Channel as SocketTextChannel;
                        roles       = channel.Guild.Roles.ToList();
                        discordUser = requestedUser as SocketGuildUser;

                        User.Orientation orientationEnum = EnumParsers.StringToOrientation(content);
                        if (orientationEnum == User.Orientation.None)
                        {
                            await ReplyAsync("Couldn't understand that gender... it can either be\n" +
                                             "```\n" +
                                             "- Male\n" +
                                             "- Female\n" +
                                             "- Trans-Female\n" +
                                             "- Transe-Male\n" +
                                             "- Other\n" +
                                             "```");

                            return;
                        }

                        // Remove old role
                        orientationFinder = (SocketRole sr) => { return(sr.Name == user.orientation.ToString().ToLower()); };
                        orientation       = roles.Find(orientationFinder);
                        if (orientation == null)
                        {
                            Logger.Error("System", $"Could not find user orientation {user.orientation.ToString().ToString()}");
                        }
                        else
                        {
                            await discordUser.RemoveRoleAsync(orientation);
                        }

                        // Add new role
                        orientationFinder = (SocketRole sr) => { return(sr.Name == orientationEnum.ToString().ToLower()); };
                        orientation       = roles.Find(orientationFinder);
                        await discordUser.AddRoleAsync(orientation);

                        user.orientation = orientationEnum;
                        db.SaveChanges();

                        Logger.Info(author.Username, $"Changed user <@{requestedUser.Id}>'s orientation to {user.orientation.ToString()}");
                        await ReplyAsync($"Success: <@{requestedUser.Id}>'s orientation set to `{user.orientation.ToString()}`");

                        break;

                    case "ref":
                    case "r":
                        if (Uri.TryCreate(content, UriKind.Absolute, out var uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps))
                        {
                            Logger.Info(author.Username, $"Changed user <@{requestedUser.Id}>'s ref from {user.Ref} to {content}");
                            user.Ref = content;
                            await ReplyAsync($"Success: <@{requestedUser.Id}>'s ref has been updated");
                        }
                        else
                        {
                            Logger.Warning(author.Username, "Failed database set ref command");
                            await ReplyAsync($"Error: Ref sheet must be a link. You gave: `{content}`");
                        }
                        break;

                    case "forcetut":
                        bool value;
                        if (!Boolean.TryParse(content, out value))
                        {
                            await ReplyAsync($"Could not set `forcetut` to {value}. It can be either `true` or `false`");

                            Logger.Info(author.Username, $"Failed to change user <@{requestedUser.Id}> 's tutorial state from {user.TutorialFinished} to {value}");
                            return;
                        }
                        Logger.Info(author.Username, $"Changed user <@{requestedUser.Id}> 's tutorial state from {user.TutorialFinished} to {value}");
                        await ReplyAsync($"Changed <@{requestedUser.Id}>'s tutorial state from {user.TutorialFinished} to {value}");

                        user.TutorialFinished = value;
                        break;

                    default:
                        Logger.Warning(author.Username, "Failed database set command.");
                        await ReplyAsync($"Error: Could not find attribute {attribute}. Check you syntax!");

                        return;
                    }

                    db.SaveChanges();
                    Logger.Verbose(author.Username, $"Updated data for {userId}");

                    await BotReporting.ReportAsync(ReportColors.modCommand,
                                                   (SocketTextChannel)Context.Channel,
                                                   $"Mod Attribute Set by {Context.User.Username}",
                                                   $"<@{Context.User.Id}> has changed <@{requestedUser.Id}>'s {attribute} to `{content}` ",
                                                   Context.User,
                                                   (SocketUser)requestedUser).ConfigureAwait(false);

                    return;
                }

                Logger.Verbose(author.Username, $"Failed to find user: {userId}");
                await ReplyAsync($"Failed to find user: {userId}");

                //Logger.Verbose(author.Username, "Created User");
                //ReplyAsync("Created User");

                Logger.Verbose("System", $"Updated information for user {author}");
            }
        }
Ejemplo n.º 18
0
        public async Task ForcetutAsync(IUser requestedUser)
        {
            // User to forcetut
            ulong parsedUserId = requestedUser.Id;

            using (DiscordContext db = new DiscordContext())
            {
                ulong           userId      = Context.User.Id;
                SocketGuildUser discordUser = requestedUser as SocketGuildUser;

                if (db.Users.Where(x => x.DiscordId == userId).FirstOrDefault().Privilege == User.Privileges.User)
                {
                    Logger.Warning(Context.User.Id.ToString(), "User tried to use forcetut command and failed");
                    await ReplyAsync($"Nice try. Dont want me calling your parents, right?");

                    return;
                }

                User user = db.Users.Where(x => x.DiscordId == parsedUserId).FirstOrDefault();

                // Remove old gender and orientation
                Predicate <SocketRole> genderFinder = (SocketRole sr) => { return(sr.Name == user.Gender.ToString().ToLower()); };
                SocketRole             genderRole   = Context.Guild.Roles.ToList().Find(genderFinder);
                if (genderRole != null)
                {
                    await((SocketGuildUser)requestedUser).RemoveRoleAsync(genderRole);
                    Logger.Verbose("System", $"found role {genderRole.Name} and removed it.");
                }
                else
                {
                    Logger.Warning("System", $"Couldn't find role {user.Gender.ToString().ToLower()}.");
                }

                Predicate <SocketRole> orientationFinder = (SocketRole sr) => { return(sr.Name == user.orientation.ToString().ToLower()); };
                SocketRole             orientationRole   = Context.Guild.Roles.ToList().Find(orientationFinder);
                if (orientationRole != null)
                {
                    await((SocketGuildUser)requestedUser).RemoveRoleAsync(orientationRole);
                    Logger.Verbose("System", $"found role {orientationRole.Name} and removed it.");
                }
                else
                {
                    Logger.Warning("System", $"Couldn't find role {user.orientation.ToString().ToLower()}.");
                }

                //Reset database entry for user
                user.ResetUser();
                UserUtilities.manualRegister(discordUser);

                SocketGuildChannel channel = Context.Channel as SocketGuildChannel;
                IReadOnlyCollection <SocketRole> guildRoles = channel.Guild.Roles;

                SocketRole role = guildRoles.Where(x => x.Name.Equals("Newbie")).FirstOrDefault();
                await channel.Guild.GetUser((ulong)parsedUserId).AddRoleAsync(role);

                // Creat intro room
                RestTextChannel introRoom = await channel.Guild.CreateTextChannelAsync($"intro-{parsedUserId}");

                await Task.Run(async() =>
                {
                    // Make room only visible to new user, staff, and Luna
                    await introRoom.AddPermissionOverwriteAsync(discordUser, Permissions.userPerm);

                    // Start interaction with user. Sleeps are for humanizing the bot.
                    await introRoom.SendMessageAsync("Welcome to the server! Lets get you settled, alright?");
                    Thread.Sleep(1000);
                    await introRoom.SendMessageAsync("Firstly, what should we call you?\n" +
                                                     "If you'd rather not change your nick just type `none`");
                }).ConfigureAwait(false);

                db.SaveChanges();

                await BotReporting.ReportAsync(ReportColors.modCommand,
                                               (SocketTextChannel)Context.Channel,
                                               $"Forcetut by {Context.User.Username}",
                                               $"<@{Context.User.Id}> has placed <@{requestedUser.Id}> in a tutorial room.",
                                               Context.User,
                                               (SocketUser)requestedUser).ConfigureAwait(false);
            }
        }