public async Task EditFooter(IUser user, [Remainder] string footer) { if (user == null || footer == null) { await ReplyAsync("**Syntax:** " + Guild.Load(Context.Guild.Id).Prefix + "editfooter [@User] [Footer]"); return; } List <(string, string)> queryParams = new List <(string, string)>() { ("@footerText", footer) }; DatabaseActivity.ExecuteNonQueryCommand( "UPDATE users SET footerText=@footerText WHERE id='" + user.Id + "';", queryParams); AdminLog.Log(Context.User.Id, Context.Message.Content, Context.Guild.Id, user.Id); var eb = new EmbedBuilder() .WithDescription(Context.User.Username + " updated " + user.Mention + "'s footer successfully.") .WithColor(Color.DarkGreen); var message = await ReplyAsync("", false, eb.Build()); Context.Message.DeleteAfter(10); message.DeleteAfter(10); }
public async Task ToggleChannelAwardingEXPStatus(SocketTextChannel channel = null) { SocketTextChannel workingWithChannel = channel ?? Context.Channel as SocketTextChannel; if (channel == null) { await ReplyAsync("Syntax: " + Guild.Load(Context.Guild.Id).Prefix + "toggleexpawarding [#channel]"); return; } bool value = !Channel.Load(workingWithChannel.Id).AwardingEXP; var queryParams = new List <(string, string)>() { ("@awardingEXP", value.ToOneOrZero().ToString()) }; DatabaseActivity.ExecuteNonQueryCommand("UPDATE channels SET awardingEXP=@awardingEXP WHERE channelID='" + workingWithChannel.Id + "';", queryParams); AdminLog.Log(Context.User.Id, Context.Message.Content, Context.Guild.Id); if (value) { await ReplyAsync(Context.User.Mention + ", this channel will award EXP to the users who's messages are typed here."); } else { await ReplyAsync(Context.User.Mention + ", this channel will no longer award EXP to the users who's messages are typed here."); } }
private static Task ReadyAddUsersToDatabase(SocketGuild g) { foreach (SocketGuildUser u in g.Users) { //Insert new users into the database by using INSERT IGNORE List <(string, string)> queryParams = new List <(string id, string value)>() { ("@username", u.Username), ("@avatarUrl", u.GetAvatarUrl()) }; int rowsUpdated = DatabaseActivity.ExecuteNonQueryCommand( "INSERT IGNORE INTO " + "users(id,username,avatarUrl) " + "VALUES (" + u.Id + ", @username, @avatarUrl);", queryParams); //end. if (rowsUpdated > 0) // If any rows were affected, add the user to the list to be dealt with later. { OfflineList.Add(new Tuple <SocketGuildUser, SocketGuild>(u, g)); } } return(Task.CompletedTask); }
public async Task SetPokemonGoFriendCode([Remainder] string friendCode) { if (friendCode.All(char.IsDigit)) { if (friendCode[4] != ' ') { friendCode = friendCode.Insert(4, " "); } if (friendCode[9] != ' ') { friendCode = friendCode.Insert(9, " "); } List <(string, string)> queryParams = new List <(string, string)> { ("@code", friendCode) }; DatabaseActivity.ExecuteNonQueryCommand("UPDATE users SET pokemonGoFriendCode=@code WHERE id='" + Context.User.Id + "';", queryParams); await ReplyAsync(Context.User.Mention + ", you have successfully updated your Pokemon Go Friend Code on your profile to \"" + friendCode + "\"!"); } else { await ReplyAsync(Context.User.Mention + ", your friend code must be all digits!"); } }
internal static List <RequestQuote> LoadAll() { var requests = new List <RequestQuote>(); (MySqlDataReader dr, MySqlConnection conn)reader = DatabaseActivity.ExecuteReader("SELECT * FROM requested_quotes;"); while (reader.dr.Read()) { var q = new RequestQuote { RequestId = reader.dr.GetInt32("requestQuoteId"), CreatedBy = reader.dr.GetUInt64("requestedBy"), QuoteText = reader.dr.GetString("quoteText"), QCreatedTimestamp = reader.dr.GetDateTime("dateCreated"), CreatedIn = reader.dr.GetUInt64("requestedIn") }; requests.Add(q); } reader.dr.Close(); reader.conn.Close(); return(requests); }
public static void UpdateGuild(ulong guildID, string prefix = null, string welcomeMessage = null, ulong?welcomeChannelID = null, ulong?logChannelID = null, ulong?botChannelID = null, bool?senpaiEnabled = null, bool?quotesEnabled = null, bool?nsfwCommandsEnabled = null, ulong?ruleGambleChannelID = null) { Guild g = Load(guildID); List <(string, string)> queryParams = new List <(string, string)>() { ("@guildID", guildID.ToString()), ("@guildPrefix", prefix ?? g.Prefix), ("@welcomeMessage", welcomeMessage ?? g.WelcomeMessage), ("@welcomeChannelID", (welcomeChannelID ?? g.WelcomeChannelID).ToString()), ("@logChannelID", (logChannelID ?? g.LogChannelID).ToString()), ("@botChannelID", (botChannelID ?? g.BotChannelID).ToString()), ("@senpaiEnabled", (senpaiEnabled ?? g.SenpaiEnabled).ToOneOrZero().ToString()), ("@quotesEnabled", (quotesEnabled ?? g.QuotesEnabled).ToOneOrZero().ToString()), ("@nsfwCommandsEnabled", (nsfwCommandsEnabled ?? g.NSFWCommandsEnabled).ToOneOrZero().ToString()), ("@ruleGambleChannelID", (ruleGambleChannelID ?? g.RuleGambleChannelID).ToString()) }; DatabaseActivity.ExecuteNonQueryCommand("UPDATE guilds SET " + "guildPrefix=@guildPrefix, " + "welcomeMessage=@welcomeMessage, " + "welcomeChannelID=@welcomeChannelID, " + "logChannelID=@logChannelID, " + "botChannelID=@botChannelID, " + "senpaiEnabled=@senpaiEnabled, " + "quotesEnabled=@quotesEnabled, " + "nsfwCommandsEnabled=@nsfwCommandsEnabled, " + "ruleGambleChannelID=@ruleGambleChannelID " + "WHERE guildID=@guildID;", queryParams); }
internal static bool ApproveRequestQuote(int quoteId, ulong approvedBy, ulong approvedIn) { (MySqlDataReader dr, MySqlConnection conn)reader = DatabaseActivity.ExecuteReader("SELECT * FROM requested_quotes WHERE requestQuoteId = " + quoteId + " LIMIT 1"); var quote = new RequestQuote(); while (reader.dr.Read()) { quote.RequestId = reader.dr.GetInt32("requestQuoteId"); quote.CreatedBy = reader.dr.GetUInt64("requestedBy"); quote.QuoteText = reader.dr.GetString("quoteText"); quote.QCreatedTimestamp = reader.dr.GetDateTime("dateCreated"); quote.CreatedIn = reader.dr.GetUInt64("requestedIn"); } reader.dr.Close(); reader.conn.Close(); var added = Quote.AddQuote(quote.QuoteText, quote.CreatedBy, quote.CreatedIn, approvedBy, approvedIn, quote.QCreatedTimestamp); RemoveRequestQuote(quote.RequestId); return(added); }
public static async void AwardEXPToUser(this IUser user, SocketGuild guild, int exp = 1) { if (user.IsBot) { return; } try { int updatedEXP = user.GetEXP() + exp; List <(string, string)> queryParams = new List <(string, string)>() { ("@exp", updatedEXP.ToString()) }; DatabaseActivity.ExecuteNonQueryCommand("UPDATE users SET exp=@exp WHERE id='" + user.Id + "';", queryParams); await user.AttemptLevelUp(guild); } catch (Exception e) { await new LogMessage(LogSeverity.Warning, "UserExtensions", e.Message).PrintToConsole(); } }
public static Task RemoveChannelFromDB(SocketGuildChannel c) { DatabaseActivity.ExecuteNonQueryCommand( "DELETE FROM channels WHERE channelID=" + c.Id + ";"); return(Task.CompletedTask); }
internal static bool RemoveRequestQuote(int quoteId) { RequestQuotes.Remove(RequestQuotes.Find(quote => quote.RequestId == quoteId)); var rowsAffected = DatabaseActivity.ExecuteNonQueryCommand( "DELETE FROM requested_quotes WHERE requestQuoteId=" + quoteId + ";"); return(rowsAffected == 1); }
internal static bool DeleteQuote(int quoteId) { Quotes.Remove(Quotes.Find(quote => quote.QId == quoteId)); var rowsAffected = DatabaseActivity.ExecuteNonQueryCommand( "DELETE FROM quotes WHERE quoteId=" + quoteId + ";"); return(rowsAffected == 1); }
internal static bool AddQuote(string quote, ulong creatorId, ulong createdIn, ulong acceptedBy = 0, ulong acceptedIn = 0, DateTime?createdTimestamp = null) { if (acceptedBy == 0) { acceptedBy = creatorId; } if (acceptedIn == 0) { acceptedIn = createdIn; } List <(string, string)> queryParams = new List <(string id, string value)> { ("@createdBy", creatorId.ToString()), ("@acceptedBy", acceptedBy.ToString()), ("@quoteText", quote), ("@createdIn", createdIn.ToString()), ("@acceptedIn", acceptedIn.ToString()) }; var rowsUpdated = DatabaseActivity.ExecuteNonQueryCommand( "INSERT IGNORE INTO " + "quotes(quoteId,createdBy,acceptedBy,quoteText,dateCreated,createdIn,acceptedIn) " + "VALUES (NULL, @createdBy, @acceptedBy, @quoteText, CURRENT_TIMESTAMP, @createdIn, @acceptedIn);", queryParams); // Add quote to the current loaded quote-list (MySqlDataReader dr, MySqlConnection conn)reader = DatabaseActivity.ExecuteReader("SELECT * FROM quotes ORDER BY quoteId DESC LIMIT 1"); var newId = 0; while (reader.dr.Read()) { newId = reader.dr.GetInt32("quoteId"); } reader.dr.Close(); reader.conn.Close(); Quotes.Add(new Quote { QId = newId, CreatorId = creatorId, AcceptedBy = acceptedBy, QuoteText = quote, QCreatedTimestamp = DateTime.Now, CreatedIn = createdIn, AcceptedIn = acceptedIn }); return(rowsUpdated == 1); }
public async Task SetGender([Remainder] string gender) { List <(string, string)> queryParams = new List <(string, string)> { ("@gender", gender) }; DatabaseActivity.ExecuteNonQueryCommand("UPDATE users SET gender=@gender WHERE id='" + Context.User.Id + "';", queryParams); await ReplyAsync(Context.User.Mention + ", you have successfully updated the gender on your profile to \"" + gender + "\"!"); }
public async Task SetName([Remainder] string name) { List <(string, string)> queryParams = new List <(string, string)> { ("@name", name) }; DatabaseActivity.ExecuteNonQueryCommand("UPDATE users SET name=@name WHERE id='" + Context.User.Id + "';", queryParams); await ReplyAsync(Context.User.Mention + ", you have successfully updated the name on your profile to \"" + name + "\"!"); }
public async Task SetWebsiteUrl([Remainder] string url) { List <(string, string)> queryParams = new List <(string, string)>() { ("@websiteUrl", url) }; DatabaseActivity.ExecuteNonQueryCommand("UPDATE users SET websiteURL=@websiteUrl WHERE id='" + Context.User.Id + "';", queryParams); await ReplyAsync(Context.User.Mention + ", you have successfully updated the website URL on your profile to \"" + url + "\"!"); }
public async Task SetUserAbout([Remainder] string aboutMessage) { List <(string, string)> queryParams = new List <(string, string)> { ("@aboutMessage", aboutMessage) }; DatabaseActivity.ExecuteNonQueryCommand("UPDATE users SET about=@aboutMessage WHERE id='" + Context.User.Id + "';", queryParams); await ReplyAsync(Context.User.Mention + ", you have successfully updated the about section on your profile!"); }
public async Task SetUserPronouns([Remainder] string pronouns) { List <(string, string)> queryParams = new List <(string, string)> { ("@pronouns", pronouns) }; DatabaseActivity.ExecuteNonQueryCommand("UPDATE users SET pronouns=@pronouns WHERE id='" + Context.User.Id + "';", queryParams); await ReplyAsync(Context.User.Mention + ", you have successfully updated the pronouns on your profile to \"" + pronouns + "\"!"); }
public static async Task UserUpdated(SocketUser cachedUser, SocketUser user) { if (user.Username != cachedUser.Username || user.GetAvatarUrl() != cachedUser.GetAvatarUrl()) // If user has updated username or avatar { List <(string, string)> queryParams = new List <(string, string)>() { ("@username", user.Username), ("@avatarUrl", user.GetAvatarUrl()) }; DatabaseActivity.ExecuteNonQueryCommand("UPDATE users SET username=@username, avatarUrl=@avatarUrl WHERE id='" + user.Id + "';", queryParams); } }
private static async Task UpdateChannelInDB(SocketGuildChannel updatedChannel) { List <(string, string)> queryParams = new List <(string id, string value)>() { ("@channelID", updatedChannel.Id.ToString()), ("@channelName", updatedChannel.Name), ("@channelType", updatedChannel.GetType().Name) }; DatabaseActivity.ExecuteNonQueryCommand( "UPDATE guilds SET channelName=@channelName, channelType=@channelType WHERE channelID=@channelID", queryParams); }
public async Task RemoveTeamMember(IUser user) { if (User.Load(user.Id).TeamMember) { DatabaseActivity.ExecuteNonQueryCommand("UPDATE users SET teamMember='N' WHERE id='" + user.Id + "';"); await ReplyAsync(user.Mention + " has been removed from the team by " + Context.User.Mention); } else { await ReplyAsync(user.Mention + " is not part of the team, " + Context.User.Mention + "!"); } }
public async Task AddTeamMember(IUser user) { if (!User.Load(user.Id).TeamMember) { DatabaseActivity.ExecuteNonQueryCommand("UPDATE users SET teamMember='Y' WHERE id='" + user.Id + "';"); await ReplyAsync(user.Mention + " has been added to the team by " + Context.User.Mention); } else { await ReplyAsync(user.Mention + " is already part of the team, " + Context.User.Mention + "!"); } }
public static async Task InsertChannelToDB(SocketGuildChannel c) { List <(string, string)> queryParams = new List <(string id, string value)>() { ("@channelName", c.Name), ("@channelType", c.GetType().Name) }; DatabaseActivity.ExecuteNonQueryCommand( "INSERT IGNORE INTO " + "channels(channelID,inGuildID,channelName,channelType) " + "VALUES (" + c.Id + ", " + c.Guild.Id + ", @channelName, @channelType);", queryParams); }
public async Task SetUserRgb(int r = -1, int g = -1, int b = -1) { if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) { await ReplyAsync(Context.User.Mention + ", you have entered an invalid value. You can use this website to help get your RGB values - <http://www.colorhexa.com/>\n\n" + "**Syntax:** " + Guild.Load(Context.Guild.Id).Prefix + "editprofile customrgb [R value] [G value] [B value]\n**Example:** " + Guild.Load(Context.Guild.Id).Prefix + "setcustomrgb 140 90 210"); return; } if (Context.User.GetLevel() >= Configuration.Load().RGBLevelRequirement) { byte rValue, gValue, bValue; try { byte.TryParse(r.ToString(), out rValue); byte.TryParse(g.ToString(), out gValue); byte.TryParse(b.ToString(), out bValue); } catch (Exception e) { ConsoleHandler.PrintExceptionToLog("ProfileModule/CustomRGB", e); await ReplyAsync("An unexpected error has happened. Please ensure that you have passed through a byte value! (A number between 0 and 255)"); return; } List <(string, string)> queryParams = new List <(string, string)>() { ("@aboutR", rValue.ToString()), ("@aboutG", gValue.ToString()), ("@aboutB", bValue.ToString()) }; DatabaseActivity.ExecuteNonQueryCommand("UPDATE users SET aboutR=@aboutR, aboutG=@aboutG, aboutB=@aboutB WHERE id='" + Context.User.Id + "';", queryParams); Color aboutColor = new Color(User.Load(Context.User.Id).AboutR, User.Load(Context.User.Id).AboutG, User.Load(Context.User.Id).AboutB); EmbedBuilder eb = new EmbedBuilder() .WithTitle("Sample Message") .WithDescription("<-- FYI, this is what you updated.") .WithColor(aboutColor); await ReplyAsync(Context.User.Mention + ", you have successfully updated your custom embed RGB!", false, eb.Build()); } else { await ReplyAsync(Context.User.Mention + ", this feature requires you to be level " + Configuration.Load().RGBLevelRequirement + "!"); } }
private static async Task UpdateGuildInDB(SocketGuild g) { List <(string, string)> queryParams = new List <(string id, string value)>() { ("@guildID", g.Id.ToString()), ("@guildName", g.Name), ("@guildIcon", g.IconUrl), ("@ownedBy", g.Owner.Id.ToString()) }; DatabaseActivity.ExecuteNonQueryCommand( "UPDATE guilds SET guildName=@guildName, guildIcon=@guildIcon, ownedBy=@ownedBy WHERE guildID=@guildID", queryParams); }
public static async Task AttemptLevelUp(this IUser user, SocketGuild guild) { double requiredEXP = user.EXPToLevelUp(); if (user.GetEXP() >= Math.Round(requiredEXP)) { try { int updatedLevel = user.GetLevel() + 1; List <(string, string)> queryParams = new List <(string, string)>() { ("@level", updatedLevel.ToString()) }; DatabaseActivity.ExecuteNonQueryCommand("UPDATE users SET level=@level WHERE id='" + user.Id + "';", queryParams); SocketTextChannel botChannel = Guild.Load(guild.Id).BotChannelID.GetTextChannel() ?? Guild.Load(guild.Id).WelcomeChannelID.GetTextChannel(); EmbedBuilder eb = new EmbedBuilder() { Title = "Level Up!", Color = user.GetCustomRGB() }.WithCurrentTimestamp(); if (Configuration.Load().AwardingEXPMentionUser) { eb.WithDescription("Well done " + user.Mention + "! You levelled up to level " + user.GetLevel() + "! Gain " + (Math.Round(EXPToLevelUp(user)) - user.GetEXP()) + " more EXP to level up again!"); } else { eb.WithDescription("Well done " + user.Username + "! You levelled up to level " + user.GetLevel() + "! Gain " + (Math.Round(EXPToLevelUp(user)) - user.GetEXP()) + " more EXP to level up again!"); } await botChannel.SendMessageAsync("", false, eb.Build()); } catch (Exception e) { await new LogMessage(LogSeverity.Warning, "UserExtensions", e.Message).PrintToConsole(); } } }
internal static bool UpdateQuote(int quoteId, string quoteText) { var quote = Quotes.Find(q => q.QId == quoteId); var index = Quotes.IndexOf(Quotes.Find(q => q.QId == quoteId)); quote.QuoteText = quoteText; Quotes[index] = quote; var formattedText = quoteText.Replace("\"", "\\\""); var rowsAffected = DatabaseActivity.ExecuteNonQueryCommand( "UPDATE quotes SET `quoteText`=\"" + formattedText + "\" WHERE `quoteId`=" + quoteId + ";"); return(rowsAffected == 1); }
private static async Task ReadyAddBansToDatabase(SocketGuild g) { if (g.GetUser(DiscordBot.Bot.CurrentUser.Id).IsGuildAdministrator() || g.GetUser(DiscordBot.Bot.CurrentUser.Id).GuildPermissions.BanMembers) { var bans = await g.GetBansAsync(); foreach (IBan b in bans) { var(dataReader, mysqlConnection) = DatabaseActivity.ExecuteReader("SELECT * FROM bans WHERE issuedTo=" + b.User.Id + " AND inGuild=" + g.Id + ";"); int count = 0; while (dataReader.Read()) { count++; } dataReader.Close(); mysqlConnection.Close(); if (count != 0) { continue; } //Insert banned users into the database by using INSERT IGNORE List <(string, string)> queryParams = new List <(string id, string value)>() { ("@issuedTo", b.User.Id.ToString()), ("@issuedBy", DiscordBot.Bot.CurrentUser.Id.ToString()), // unable to get the issuedBy user ID, so use the Bot ID instead. ("@inGuild", g.Id.ToString()), ("@reason", b.Reason), ("@date", DateTime.Now.ToString("u")) }; DatabaseActivity.ExecuteNonQueryCommand( "INSERT IGNORE INTO " + "bans(issuedTo,issuedBy,inGuild,banDescription,dateIssued) " + "VALUES (@issuedTo, @issuedBy, @inGuild, @reason, @date);", queryParams); //end. } } else { await new LogMessage(LogSeverity.Info, "Guild Bans", "Unable to get banned users - Bot doesn't have the required permission(s).").PrintToConsole(); } }
private void TestDatabaseValues() { InvalidateDbValidationLabel(); lblDatabaseSetup.ForeColor = Color.Black; lblDatabaseName.ForeColor = Color.Black; int port = 3306; try { int.TryParse(txtDbPort.Text, out port); } catch (Exception e) { new LogMessage(LogSeverity.Error, "DB Validation Error", e.Message).PrintToConsole().GetAwaiter(); return; } (bool validConnection, bool dbExists) = DatabaseActivity.TestDatabaseSettings(txtDbHost.Text, txtDbUser.Text, txtDbPass.Text, port, txtDbName.Text).GetAwaiter().GetResult(); if (!validConnection) { MessageBox.Show( @"Unable to connect to the database server specified. Please ensure the values are correct and your server is up and running!", @"Unable to connect to database", MessageBoxButtons.OK); return; } if (dbExists) { var result = MessageBox.Show(@"A database with the name specified already exists. Would you like to use that?", @"Database Exists", MessageBoxButtons.YesNo); if (result != DialogResult.Yes) { lblDatabaseName.ForeColor = Color.Red; return; } } MessageBox.Show(@"Database settings configured successfully!", @"Successful Database Connection", MessageBoxButtons.OK); Configuration.UpdateConfiguration(databaseHost: txtDbHost.Text, databasePort: port, databaseName: txtDbName.Text, databaseUser: txtDbUser.Text, databasePassword: txtDbPass.Text); _validDbSettings = true; tslblDbValidation.Text = @"Database Validated."; tslblDbValidation.ForeColor = Color.Green; }
public static User Load(ulong uId) { User user = new User(); (MySqlDataReader dr, MySqlConnection conn)reader = DatabaseActivity.ExecuteReader("SELECT * FROM users WHERE id=" + uId + ";"); while (reader.dr.Read()) { user.Level = reader.dr.GetInt32("level"); user.EXP = reader.dr.GetInt32("exp"); user.Name = reader.dr["name"].ToString(); user.Gender = reader.dr["gender"].ToString(); user.Pronouns = reader.dr["pronouns"].ToString(); user.About = reader.dr["about"].ToString(); user.CustomPrefix = reader.dr["customPrefix"].ToString(); user.AboutR = reader.dr.GetByte("aboutR"); user.AboutG = reader.dr.GetByte("aboutG"); user.AboutB = reader.dr.GetByte("aboutB"); if (reader.dr["teamMember"].ToString().ToUpper() == "Y") { user.TeamMember = true; } user.EmbedAuthorBuilderIconUrl = reader.dr["authorIconURL"].ToString(); user.EmbedFooterBuilderIconUrl = reader.dr["footerIconURL"].ToString(); user.FooterText = reader.dr["footerText"].ToString(); user.MinecraftUsername = reader.dr["minecraftUsername"].ToString(); user.SnapchatUsername = reader.dr["snapchatUsername"].ToString(); user.InstagramUsername = reader.dr["instagramUsername"].ToString(); user.GitHubUsername = reader.dr["githubUsername"].ToString(); user.PokemonGoFriendCode = reader.dr["pokemonGoFriendCode"].ToString(); user.WebsiteName = reader.dr["websiteName"].ToString(); user.WebsiteUrl = reader.dr["websiteURL"].ToString(); if (reader.dr["isBeingIgnored"].ToString().ToUpper() == "Y") { user.IsBotIgnoringUser = true; } } reader.dr.Close(); reader.conn.Close(); return(user); }
internal static void Log(ulong executedBy, string action, ulong executedIn, ulong?userMention = null) { List <(string, string)> queryParams = new List <(string id, string value)> { ("@executedBy", executedBy.ToString()), ("@action", action), ("@executedIn", executedIn.ToString()) }; queryParams.Add(userMention != null ? ("@mentionedUser", userMention.ToString()) : ("@mentionedUser", null)); DatabaseActivity.ExecuteNonQueryCommand( "INSERT IGNORE INTO " + "admin_log(logId,executedBy,action,executedAt,executedIn,userMentioned) " + "VALUES (NULL, @executedBy, @action, CURRENT_TIMESTAMP, @executedIn, @mentionedUser);", queryParams); }