RenameUsernameAsync(string _username, [Remainder] SocketGuildUser _user) { //On user on database. if (CoreModule.UserExistsServerDB(Context.Guild.Id, _user.Id)) { //Execute query. CoreModule.ExecuteQuery(Context.Guild.Id, $"UPDATE users SET name = '{_username}'" + $" where id = {_user.Id};"); //Set embed object var embed = CoreModule.SimpleEmbed(Color.Green, "Update completed", $"The **update** of the user {_user.Mention}" + $" is **completed**."); //Reply embed. await ReplyAsync("", false, embed.Build()); //Send notification. CoreModule.SendNotification(Context.Guild.Id, "User username updated", $"{Context.User.Mention} **updated** the user" + $" {_user.Mention} database username to" + $" **`{_username}`**."); } //On user not on database. else { //Create and set embed content. var embed = CoreModule.SimpleEmbed(Color.Red, "User not found", $"{_user.Mention} doesn't exist on the database," + $" **`update aborted`**."); //Reply embed. await ReplyAsync("", false, embed.Build()); } }
DeleteAsync([Remainder] SocketGuildUser _user) { //On user on database. if (CoreModule.UserExistsServerDB(Context.Guild.Id, _user.Id)) { //Execute query. CoreModule.ExecuteQuery(Context.Guild.Id, $"DELETE FROM users WHERE id = {_user.Id};"); //Create and set embed object. var embed = CoreModule.SimpleEmbed(Color.Green, "Delete completed", $"The **delete** of the user" + $" {_user.Mention} is **completed**."); //Reply embed. await ReplyAsync("", false, embed.Build()); //Send notification. CoreModule.SendNotification(Context.Guild.Id, "User deleted", $"{Context.User.Mention} **deleted** the user" + $" {_user.Mention} from the database."); } //On user not on database. else { //Create and set embed object. var embed = CoreModule.SimpleEmbed(Color.Red, "User not found", $"{_user.Mention} doesn't exist on the database," + $" **`delete aborted`**."); //Reply embed. await ReplyAsync("", false, embed.Build()); } }
SignupAsync(string _username, string _region) { //Create and set socket guild user. SocketGuildUser user = Context.User as SocketGuildUser; //Create and set role. SocketRole role = CoreModule.GetRole(Context.Guild.Id, Context); //On socket guild user contains guild member role. if (user.Roles.Contains(role)) { //On user not on database. if (!CoreModule.UserExistsServerDB(Context.Guild.Id, user.Id)) { //Execute query. CoreModule.ExecuteQuery(Context.Guild.Id, "INSERT INTO users (id,name,region,actualXP,lastXP)" + $" VALUES ({user.Id},'{_username}','{_region}',0,0);"); //Create and set embed object. var embed = CoreModule.SimpleEmbed(Color.Green, "Sign up completed", $"Your **sign up** is **completed**."); //Reply embed. await ReplyAsync("", false, embed.Build()); //Send notification CoreModule.SendNotification(Context.Guild.Id, "User registered", $"{user.Mention} **registered** to the database."); } //On user in database. else { //Create and set embed object. var embed = CoreModule.SimpleEmbed(Color.Red, "User found", "You're already on the database," + " **`sign up aborted`**."); //Reply embed. await ReplyAsync("", false, embed.Build()); } } //On socket guild user not contains role. else { //Create embed object. EmbedBuilder embed; //On role exist. if (role != null) { //Set embed object. embed = CoreModule.SimpleEmbed(Color.Red, "Not a member", $"{user.Mention} you're not allowed to use this" + $" command, only {role.Mention} is allowed" + $" to use it."); } //Otherwise role don't exist. else { //Set embed object. embed = CoreModule.SimpleEmbed(Color.Red, "Role not set", "The **role** to use the commands has" + " **not been set**, please use `~setrole` to set" + " the role, **`sign up aborted`**."); } //Reply embed. await ReplyAsync("", false, embed.Build()); } }
GetStatsAsync() { //Create and set socket guild user. SocketGuildUser user = Context.User as SocketGuildUser; //Create and get the server member role. SocketRole role = CoreModule.GetRole(Context.Guild.Id, Context); //On socket guild user contains member role. if (user.Roles.Contains(role)) { //On user on database. if (CoreModule.UserExistsServerDB(Context.Guild.Id, user.Id)) { //Create and set the database connection. using (SQLiteConnection dbConnection = new SQLiteConnection($"Data Source = Databases/{Context.Guild.Id}.db;" + $" Version = 3;")) { //Open the connection. dbConnection.Open(); //Create and set query. using (SQLiteCommand dbCommand = new SQLiteCommand("SELECT name, region," + " actualXP, lastXP," + " (actualXP - lastXP) as" + " totalXP FROM users " + $"WHERE id = {user.Id};", dbConnection)) { //Create and set the database reader from the command query. using (SQLiteDataReader dbDataReader = dbCommand.ExecuteReader()) { //Read user stats info. dbDataReader.Read(); //Create and set embed object. var embed = CoreModule.SimpleEmbed(Color.Blue, $"{user.Username} stats", null); //Add embed fields. embed.AddField("Vainglory username", $"**`{dbDataReader["name"]}`**", true). AddField("Region", $"**`{dbDataReader["region"]}`**", true). AddField("Last XP fame", $"**`{dbDataReader["lastXP"]}`**", true). AddField("Actual XP fame", $"**`{dbDataReader["actualXP"]}`**", true). AddField("Total XP fame", $"**`{dbDataReader["totalXP"]}`**", true); //Add user profile. embed.WithThumbnailUrl(user.GetAvatarUrl()); //Reply embed. await ReplyAsync("", false, embed.Build()); } } } } //On user not on database. else { //Create and set embed content. var embed = CoreModule.SimpleEmbed(Color.Red, "User not found", $"{user.Mention} doesn't exist on the" + $" database, **`stats aborted`**."); //Reply embed. await ReplyAsync("", false, embed.Build()); } } //On socket guild user not contains role. else { //Create embed object. EmbedBuilder embed; //On role exist. if (role != null) { //Set embed object. embed = CoreModule.SimpleEmbed(Color.Red, "Not a member", $"{user.Mention} you're not allowed to use" + $" this command, only {role.Mention} is allowed" + $" to use it."); } //Otherwise role don't exist. else { //Set embed object. embed = CoreModule.SimpleEmbed(Color.Red, "Role not set", "The **role** to use the commands has" + " **not been set**, please use `~setrole`" + " to set the role, **`stats aborted`**."); } //Reply embed. await ReplyAsync("", false, embed.Build()); } }
GetStatsAsync([Remainder] SocketGuildUser _user) { //Create and get server member role. SocketRole role = CoreModule.GetRole(Context.Guild.Id, Context); //On user on database. if (CoreModule.UserExistsServerDB(Context.Guild.Id, _user.Id)) { //Create and set the database connection. using (SQLiteConnection dbConnection = new SQLiteConnection($"Data Source = Databases/{Context.Guild.Id}.db;" + $" Version = 3;")) { //Open the connection. dbConnection.Open(); //Create and set query. using (SQLiteCommand dbCommand = new SQLiteCommand("SELECT name, region," + " actualXP, lastXP," + " (actualXP - lastXP) as" + " totalXP FROM users " + $"WHERE id = {_user.Id};", dbConnection)) { //Create and set the database reader from the command query. using (SQLiteDataReader dbDataReader = dbCommand.ExecuteReader()) { //Read user stats info. dbDataReader.Read(); //Create and set embed object. var embed = CoreModule.SimpleEmbed(Color.Blue, $"{_user.Username} stats", null); //Add embed fields. embed.AddField("Vainglory username", $"**`{dbDataReader["name"]}`**", true). AddField("Region", $"**`{dbDataReader["region"]}`**", true). AddField("Last XP fame", $"**`{dbDataReader["lastXP"]}`**", true). AddField("Actual XP fame", $"**`{dbDataReader["actualXP"]}`**", true). AddField("Total XP fame", $"**`{dbDataReader["totalXP"]}`**", true); //Add user profile. embed.WithThumbnailUrl(_user.GetAvatarUrl()); //Reply embed. await ReplyAsync("", false, embed.Build()); } } } } //On user not on database. else { //Create & set embed content. var embed = CoreModule.SimpleEmbed(Color.Red, "User not found", $"{_user.Mention} doesn't exist on the" + $" database, **`stats aborted`**."); //Reply embed. await ReplyAsync("", false, embed.Build()); } }