public async Task SetAgeAsync(int age) { if (age < 0) { await ReplyAsync("You can't be unborn, no matter how much you try... Age cannot be less than `0`"); 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.Verbose(author.Username, $"Setting {userId} description to {age}"); user.Age = age; db.SaveChanges(); await ReplyAsync($"Changed <@{userId}> age to `{user.Age}` years old."); return; } Logger.Verbose(author.Username, $"Failed to find user: {userId}"); await ReplyAsync($"Failed to find user: `{author.Username}`"); } }
public static bool manualRegister(SocketGuildUser user) { using (DiscordContext db = new DiscordContext()) { ulong userId = user.Id; if (db.Users.Where(x => x.DiscordId == userId).Count() != 0) { Logger.Verbose("System", $"User {user.Username} already registered"); return(false); } Logger.Verbose("System", $"Creating User {user.Username} Data"); User newUser = new User(); newUser.Nickname = ""; newUser.DiscordId = userId; newUser.Level = 1; newUser.LastMessage = DateTime.UtcNow; newUser.Privilege = 0; newUser.TutorialFinished = false; newUser.Gender = User.Genders.Null; newUser.SnugG = 0; newUser.SnugR = 0; db.Users.Add(newUser); db.SaveChanges(); Logger.Verbose("System", $"Created user {user.Username} successfully"); return(true); } }
public static DiscordServerMember GetServerMember(DiscordUser discordUser) { DiscordServerMember returnMember; using (DiscordContext discordContext = DiscordRepository.GetDiscordContext()) { // Channel search returnMember = discordContext.DiscordServerMembers.FirstOrDefault(member => member.DiscordId == discordUser.Id); // Can't found the channel in Database -> create if (returnMember == null) { returnMember = discordContext.DiscordServerMembers.Add(new DiscordServerMember { DiscordId = discordUser.Id, Username = discordUser.Username, Nickalert = discordUser.Mention }); discordContext.SaveChanges(); } } return(returnMember); }
/// <summary> /// Gets or creates the bot Channel /// </summary> /// <param name="discordUser"></param> /// <param name="discordChannel"></param> /// <returns></returns> public DiscordBotChannel GetBotChannel(DiscordUser discordUser, DiscordChannel discordChannel) { DiscordBotChannel returnChannel; Console.WriteLine("Test1"); using (DiscordContext discordContext = _discordRepository.GetDiscordContext()) { Console.WriteLine("Test12"); // Channel search returnChannel = discordContext.DiscordBotChannels.FirstOrDefault(channel => channel.ChannelId == discordChannel.Id); // Can't found the channel in Database -> create if (returnChannel == null) { returnChannel = discordContext.DiscordBotChannels.Add(new DiscordBotChannel { DiscordBotId = discordContext.DiscordBots.First(bot => bot.DiscordId == discordUser.Id).Id, ChannelId = discordChannel.Id, ChannelName = discordChannel.Name }); discordContext.SaveChanges(); } } return(returnChannel); }
public async Task SetDescAsync([Remainder] string parameter) { 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.Verbose(author.Username, $"Setting description for {userId} to: {parameter}"); user.Description = parameter; db.SaveChanges(); await ReplyAsync($"Changed <@{userId}>'s description to: {user.Description}"); return; } Logger.Verbose(author.Username, $"Failed to find user: {userId}"); await ReplyAsync($"Failed to find user: `{author.Username}`"); } }
/// <summary> /// Serializes json dumps from redis caches /// </summary> /// <param name="guild"></param> public static void json(SocketGuild guild) { string json = System.IO.File.ReadAllText(@"C:\Users\Javier\Downloads\data.json"); Dictionary <string, object> toplevel = JsonConvert.DeserializeObject <Dictionary <string, object> >(json); List <SocketGuildUser> users = guild.Users.ToList(); using (DiscordContext db = new DiscordContext()) { foreach (SocketGuildUser u in users) { if (toplevel.ContainsKey(u.Id.ToString())) { User user = db.Users.Where(x => x.DiscordId == u.Id).FirstOrDefault(); JObject secondLevel = (JObject)toplevel[u.Id.ToString()]; JToken thirdLevel = secondLevel.Last; JToken fourthLevel = thirdLevel.First(); foreach (JProperty attribute in fourthLevel) { string value; switch (attribute.Name) { case "age": user.Age = int.Parse(attribute.Value.ToString()); break; case "sex": value = attribute.Value.ToString(); break; case "level": user.Level = int.Parse(attribute.Value.ToString()); break; case "fur": user.Fur = attribute.Value.ToString(); break; case "ref": user.Ref = attribute.Value.ToString(); break; case "desc": user.Description = attribute.Value.ToString(); break; } } } } db.SaveChanges(); } }
public async Task SnugAsync(IUser requestedUser) { // return if used in the lobby if (Context.Channel.Id == 308306400717832192) { return; } using (DiscordContext db = new DiscordContext()) { SocketUser author = Context.User; ulong userId = author.Id; ulong userId2 = requestedUser.Id; Random random = new Random(); int rand = random.Next(0, 2); User user = db.Users.FirstOrDefault(x => x.DiscordId == userId); User user2 = db.Users.FirstOrDefault(x => x.DiscordId == userId2); if (requestedUser.IsBot) { await ReplyAsync("Can't snug a bot, how about a firm handshake?"); return; } Logger.Info(author.Username, " is snugging."); if (userId == userId2) { await ReplyAsync($"<@{userId}> is now snuggling by themselves. A bit lonely but no-one is judging."); } else { user.SnugG = user.SnugG + 1; user2.SnugR = user.SnugR + 1; db.SaveChanges(); if (rand == 0) { await ReplyAsync($"<@{userId}> is now snuggling with <@{userId2}>!"); } else if (rand == 1) { await ReplyAsync($"Aww, look at <@{userId}> and <@{userId2}> snuggling!"); } else if (rand == 2) { await ReplyAsync($"*<@{userId}> grabs <@{userId2}> and they start to snuggle.*"); } else { Logger.Warning(author.Username, "Tried to snug with someone and it failed somehow."); } } } }
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}`"); } } }
public BotManagment(DiscordRepository discordRepository) { bool anyDiscordBotCreated = false; // Any existing Bots in Database? using (DiscordContext discordContext = discordRepository.GetDiscordContext()) { anyDiscordBotCreated = discordContext.DiscordBots.Any(); } // Currently no existing DiscordBot -> Ask to create one if (!anyDiscordBotCreated) { ConsoleOutput.WriteLine(ConsoleType.Debug, "Currently no existing DiscordBot. Enter custom Token or default used? (Y/N)"); string botToken = "MzE1MTkxNDI0NDgyMDE3Mjgx.DMTmbA.mj6lvnSnk1JJkxIDNgO4RMOe2m4"; if (Console.ReadLine()?.ToLower() == "y") { ConsoleOutput.WriteLine(ConsoleType.Config, "Please enter the Bot Token:"); // read and check bot token botToken = Console.ReadLine(); } if (botToken != null) { // Create bot and save to database DiscordBot discordBot = new DiscordBot { Token = botToken }; using (DiscordContext discordContext = discordRepository.GetDiscordContext()) { discordContext.DiscordBots.Add(discordBot); discordContext.SaveChanges(); } anyDiscordBotCreated = true; } } // Discord Bots found -> Start them all if (anyDiscordBotCreated) { using (DiscordContext discordContext = discordRepository.GetDiscordContext()) { foreach (DiscordBot discordBot in discordContext.DiscordBots) { DiscordClient newDiscordClient = Initialization.Setup(discordBot); Initialization.Connect(newDiscordClient); Initialization.BindEvents(newDiscordClient); } } } }
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); } }
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); } }
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(); } }
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}"); } }
public async Task SetFurAsync([Remainder] string parameter) { 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.Warning(author.Username, $"user <@{userId}>'s fur set to: {parameter}"); user.Fur = parameter; db.SaveChanges(); await ReplyAsync($"<@{userId}> fur set to {parameter}"); return; } Logger.Verbose(author.Username, $"Failed to find user: {userId}"); await ReplyAsync($"Failed to find user: `{author.Username}`"); } }
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); } }
/// <summary> /// Initializes a new instance of the <see cref="Ban"/> class. /// </summary> /// <param name="outcome"> /// The outcome. /// </param> /// <param name="settings"> /// The settings. /// </param> public Ban(SlaveReportsExtension.Outcome outcome, UserSettings settings, DiscordContext context) : base(outcome, settings, context) { if (settings.WheelTaskPreference == null) { settings.WheelTaskPreference = (int)SlaveReportsExtension.WheelTaskPreferenceSetting.Default; context.SaveChanges(); } if (settings.WheelTaskPreference != null && ((SlaveReportsExtension.WheelTaskPreferenceSetting)settings.WheelTaskPreference).HasFlag(SlaveReportsExtension.WheelTaskPreferenceSetting.Task)) { this.Chance *= 6; } DiscordEmbedBuilder builder = new DiscordEmbedBuilder(); int time = Helpers.RandomGenerator.RandomInt(this.minBanTime, this.maxBanTime); settings.WheelDifficulty = settings.WheelDifficulty ?? 2; if (Helpers.RandomGenerator.RandomInt(0, 2) == 0) { builder.Title = "Content ban!"; builder.Description = $"You are banned from {bans[Helpers.RandomGenerator.RandomInt(0, bans.Length)]} for {time} days! If you already had the same ban, consider it reset."; builder.Footer = new DiscordEmbedBuilder.EmbedFooter() { Text = "Now reroll!" }; } else { int edgeAmount = Helpers.RandomGenerator.RandomInt(this.minEdgeAmount, this.maxEdgeAmount) * 2; switch ((SlaveReportsExtension.WheelDifficultyPreference)settings.WheelDifficulty) { case SlaveReportsExtension.WheelDifficultyPreference.Baby: edgeAmount = edgeAmount / 4; break; case SlaveReportsExtension.WheelDifficultyPreference.Easy: edgeAmount = edgeAmount / 2; break; case SlaveReportsExtension.WheelDifficultyPreference.Hard: edgeAmount = edgeAmount * 2; break; case SlaveReportsExtension.WheelDifficultyPreference.Masterbater: edgeAmount = edgeAmount * 4; break; } builder.Title = "Edging Task!"; builder.Description = $"You'll have to Edge {edgeAmount} times a Day, for {time} days! If you already had the same task, consider it reset."; builder.Footer = new DiscordEmbedBuilder.EmbedFooter() { Text = "Now reroll!" }; } this.Embed = builder.Build(); this.Outcome = SlaveReportsExtension.Outcome.Task; }
public async Task SetGenderAsync(string parameter) { User.Genders gender = EnumParsers.StringToGender(parameter); if (gender == User.Genders.Null) { await ReplyAsync("Couldn't understand that gender... it can either be\n" + "```\n" + "- Male\n" + "- Female\n" + "- Trans-Female\n" + "- Trans-Male\n" + "- Other\n" + "- None \n" + "- Fluid \n" + "```"); 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.Warning("AdminSetCmd", $"Setting @<{userId}>'s gender to {gender.ToString()}."); SocketGuildChannel guildChannel = Context.Channel as SocketGuildChannel; List <SocketRole> roles = guildChannel.Guild.Roles.ToList(); // Remove old role Predicate <SocketRole> genderFinder = (SocketRole sr) => { return(sr.Name == user.Gender.ToString().ToLower()); }; SocketRole genderRole = roles.Find(genderFinder); genderRole = roles.Find(genderFinder); if (genderRole != null) { await guildChannel.GetUser((ulong)userId).RemoveRoleAsync(genderRole); Logger.Verbose("System", $"found role {genderRole.Name} and removed it."); } else { Logger.Warning("System", $"Couldn't find role {user.Gender.ToString().ToLower()}."); } // Add new role genderFinder = (SocketRole sr) => { return(sr.Name == gender.ToString().ToLower()); }; genderRole = roles.Find(genderFinder); await guildChannel.GetUser((ulong)userId).AddRoleAsync(genderRole); user.Gender = gender; db.SaveChanges(); await ReplyAsync($"Changed <@{userId}>'s gender to {gender.ToString().ToLower()}"); return; } Logger.Verbose(author.Username, $"Failed to find user: {userId}"); await ReplyAsync($"Failed to find user: `{author.Username}`"); } }
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}`"); } }
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}"); } }
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); } }