private async Task QuarentineUser(ulong userId) { User_Flow_control userFlow = new User_Flow_control(Context.Client); if (await userFlow.AddUser(userId, "Quarantined")) { await ReplyAsync($"Successfully added <@!{userId}> as Quarantined"); } else { await userFlow.UpdateUser(userId, "Quarantined"); await ReplyAsync($"Successfully updated <@!{userId}> as Quarantined"); } SocketGuildUser user = Context.Guild.GetUser(userId); if (user == null) { return; } // Now remove all other roles and add quarantined role foreach (IRole role in user.Roles) { if (role.Name == "@everyone") { continue; } await user.RemoveRoleAsync(role); } await user.AddRoleAsync(Context.Guild.GetRole(645413078405611540)); }
private async Task AddUser(ulong userId, string status) { User_Flow_control userFlow = new User_Flow_control(Context.Client); // Format the status correctly status = status.ToLower(); bool caps = true; string formattedStatus = ""; foreach (char c in status) { if (caps) { formattedStatus += char.ToUpper(c); } else { formattedStatus += c; } caps = false; if (c == ' ') { caps = true; } } // Ensure it's valid switch (formattedStatus) { case "Whitelisted": case "Blacklisted": case "Quarantined": case "New User": break; default: await ReplyAsync(status + "is not a valid status"); return; } await ReplyAsync($"Adding user <@!{userId}> with the id of {userId} as {formattedStatus}"); if (await userFlow.AddUser(userId, status)) { await ReplyAsync($"Successfully added <@!{userId}> as {status}"); } else { await ReplyAsync("A database entry for " + Context.Client.Rest.GetUserAsync(userId).Result.Mention + " already exists, updating user entry..."); await userFlow.UpdateUser(userId, status); await ReplyAsync($"Successfully updated <@!{userId}> as {status}"); } }
private async Task WhitelistUser(ulong userId) { User_Flow_control userFlow = new User_Flow_control(Context.Client); if (await userFlow.AddUser(userId, "Whitelisted")) { await ReplyAsync($"Successfully added <@!{userId}> as Whitelisted"); } else { await userFlow.UpdateUser(userId, "Whitelisted"); await ReplyAsync($"Successfully updated <@!{userId}> as Whitelisted"); } // Remove ban if banned try { await Context.Guild.RemoveBanAsync(userId); await ReplyAsync($"Unbanned <@!{userId}>"); } catch (Exception e) { if (e.HResult != -2146233088) { Console.WriteLine(e.HResult); await ReplyAsync("A problem occurred while attempting to unban this user"); } } // Remove quarantine if quarantined and give I just returned role SocketGuildUser guildUser = Context.Guild.GetUser(userId); if (guildUser != null) { await guildUser.RemoveRoleAsync(Context.Guild.GetRole(645413078405611540)); await guildUser.AddRoleAsync(Context.Guild.GetRole(665758685464625153)); await ReplyAsync($"Updated roles for <@!{userId}>"); } }
private async Task BlacklistUser(ulong userId, string reason) { User_Flow_control userFlow = new User_Flow_control(Context.Client); if (await Context.Client.Rest.GetUserAsync(userId) == null) { await ReplyAsync("I could not find the user you were looking for."); } if (await userFlow.AddUser(userId, "Blacklisted")) { await ReplyAsync($"Successfully added <@!{userId}> as Blacklisted"); } else { await userFlow.UpdateUser(userId, "Blacklisted"); await ReplyAsync($"Successfully updated <@!{userId}> as Blacklisted"); } //Now ban the user await Context.Guild.AddBanAsync(Context.Client.Rest.GetUserAsync(userId).Result, reason : reason == ""? "Blacklisted" : reason); }
public async Task InstallCommandsAsync() { // Hook the MessageReceived event into our command handler _client.MessageReceived += HandleCommandAsync; // Here we discover all of the command modules in the entry // assembly and load them. Starting from Discord.NET 2.0, a // service provider is required to be passed into the // module registration method to inject the // required dependencies. // // If you do not use Dependency Injection, pass null. // See Dependency Injection guide for more information. await _commands.AddModulesAsync(assembly : Assembly.GetEntryAssembly(), services : null); User_Flow_control userFlow = new User_Flow_control(_client); _client.UserJoined += userFlow.Client_UserJoined; _client.UserLeft += Client_UserLeft; _client.UserUpdated += userFlow.Client_UserUpdated; _client.RoleUpdated += userFlow.Client_RoleUpdated; }