Exemple #1
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}");
            }
        }
Exemple #2
0
        public async Task SetOrientationAsync(string parameter)
        {
            User.Orientation orientation = EnumParsers.StringToOrientation(parameter);

            if (orientation == User.Orientation.None)
            {
                await ReplyAsync("Couldn't understand that orientation... it can either be\n" +
                                 "```\n" +
                                 "- Straight\n" +
                                 "- Gay\n" +
                                 "- Bisexual\n" +
                                 "- Asexual\n" +
                                 "- Pansexual\n" +
                                 "- Demisexual\n" +
                                 "- Other" +
                                 "```");

                return;
            }

            using (DiscordContext db = new DiscordContext())
            {
                SocketUser author = Context.User;
                ulong      userId = author.Id;

                User user = db.Users.FirstOrDefault(x => x.DiscordId == userId);
                if (user != null)
                {
                    Logger.Info(author.Username, $"Changing @<{userId}> orientation to {orientation.ToString()}.");

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

                    // Remove old role
                    Predicate <SocketRole> orientationFinder = (SocketRole sr) => { return(sr.Name == user.orientation.ToString().ToLower()); };
                    SocketRole             orientationRole   = roles.Find(orientationFinder);
                    if (orientationRole != null)
                    {
                        await guildChannel.GetUser(userId).RemoveRoleAsync(orientationRole);

                        Logger.Verbose("System", $"found role {orientationRole.Name} and removed it.");
                    }
                    else
                    {
                        Logger.Warning("System", $"Couldn't find role {user.orientation.ToString().ToLower()}.");
                    }

                    // Adding role to user
                    orientationFinder = (SocketRole sr) => { return(sr.Name == orientation.ToString().ToLower()); };
                    orientationRole   = roles.Find(orientationFinder);
                    await guildChannel.GetUser(userId).AddRoleAsync(orientationRole);


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

                    await ReplyAsync($"<@{userId}> orientation is now {user.orientation.ToString().ToLower()}");

                    return;
                }

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