public async Task ScamAsync([Remainder] string user = null) { //Aqui você substitui pelos seus dados var connString = "Server=192.168.1.141;Port=3306;Database=lebot;Uid=lebot;Pwd=;SslMode=none;"; var connection = new MySqlConnection(connString); var command = connection.CreateCommand(); if (user != null) { if (user.Contains("everyone")) { return; } // Getting user id from mention var charToRemove = new string[] { "<", "@", "!", ">" }; foreach (var c in charToRemove) { user = user.Replace(c, string.Empty); } if (user == "" + Context.Message.Author.Id) { await ReplyAsync("Burro do crl! Tás a tentar roubar-te a ti mesmo?"); } else { Random generateProbability = new Random(); int probability = generateProbability.Next(0, 101); int bonus = 0; var ownedItem = new Functions.OwnItem(); if (ownedItem.OwnedItem(Context.Message.Author.Id, 1)) { bonus = 15; } int probabilidade = 15 + bonus; if (probability >= probabilidade) { //The user was caught stealing! await FailedAsync("" + Context.Message.Author.Id, user); } else { //The user wasn't caught stealing! await SuccessfulAsync("" + Context.Message.Author.Id, user); await Context.Message.DeleteAsync(); } } } else { //The user was caught stealing! await FailedAsync("" + Context.Message.Author.Id); } }
public async Task InventoryAsync() { ulong userid = Context.Message.Author.Id; //Aqui você substitui pelos seus dados var connString = "Server=192.168.1.141;Port=3306;Database=lebot;Uid=lebot;Pwd=;SslMode=none;"; var connection = new MySqlConnection(connString); var command = connection.CreateCommand(); List <string[]> items = new List <string[]>(); List <string[]> userItems = new List <string[]>(); connection.Open(); command.CommandText = "SELECT * FROM store_prices"; MySqlDataReader itemReader; itemReader = command.ExecuteReader(); try { while (itemReader.Read()) { string itemId = itemReader["id"].ToString(); string itemName = itemReader["name"].ToString(); string itemPrice = itemReader["price"].ToString(); string itemDescription = itemReader["description"].ToString(); string[] thisItem = { itemId, itemName, itemPrice, itemDescription }; items.Add(thisItem); } itemReader.Close(); connection.Close(); var ownItem = new Functions.OwnItem(); foreach (var item in items) { if (ownItem.OwnedItem(userid, int.Parse("" + item.GetValue(0)))) { string[] thisUserItem = { "" + item.GetValue(0), "" + item.GetValue(1), "" + item.GetValue(2), "" + item.GetValue(3) }; userItems.Add(thisUserItem); } } EmbedBuilder inventoryDump = new EmbedBuilder(); var getColor = new Functions.RandomBuilderColor(); inventoryDump.WithTitle("Inventário de " + Context.Message.Author.Username + "#" + Context.Message.Author.Discriminator); inventoryDump.WithColor(getColor.MessageBuilderColor()); if (userItems.Count > 0) { foreach (var ownedItem in userItems) { inventoryDump.AddField("Id: " + ownedItem.GetValue(0) + " :arrow_right: " + ownedItem.GetValue(1), ownedItem.GetValue(3)); } } else { inventoryDump.WithDescription("Nada... Talvez usar a \\shop para encontrar algo?"); } await ReplyAsync("", false, inventoryDump); } catch (MySqlException ex) { Console.WriteLine(ex.Message); } finally { if (connection.State == System.Data.ConnectionState.Open) { connection.Close(); } } }
public async Task BuyAsync([Remainder] string id = null) { if (string.IsNullOrEmpty(id)) { await ReplyAsync("E dizeres o que é que queres comprar?"); return; } else { ulong.TryParse(id, out ulong itemId); if (itemId <= 0) { await ReplyAsync("Na minha terra um id são números..."); return; } else { int newitemId = int.Parse("" + itemId); //Aqui você substitui pelos seus dados var connString = "Server=192.168.1.141;Port=3306;Database=lebot;Uid=lebot;Pwd=;SslMode=none;"; var connection = new MySqlConnection(connString); var command = connection.CreateCommand(); connection.Open(); command.CommandText = "SELECT * FROM store_prices WHERE id='" + itemId + "' LIMIT 1"; MySqlDataReader itemReader; itemReader = command.ExecuteReader(); if (itemReader.Read()) { long price = itemReader.GetInt64(2); string itemName = itemReader.GetString(1); itemReader.Close(); command.CommandText = "SELECT coins FROM currency WHERE userid='" + Context.Message.Author.Id + "'"; MySqlDataReader coinsReader; coinsReader = command.ExecuteReader(); long userCoins; if (coinsReader.Read()) { userCoins = coinsReader.GetInt64(0); } else { userCoins = 10; } coinsReader.Close(); if (price > userCoins) { await ReplyAsync("Não tens fé suficiente :neutral_face:"); } else { var testItem = new Functions.OwnItem(); if (!testItem.OwnedItem(Context.Message.Author.Id, newitemId)) { long newTotal = userCoins - price; command.CommandText = "UPDATE currency SET coins='" + newTotal + "' WHERE userid='" + Context.Message.Author.Id + "'"; command.ExecuteNonQuery(); command.CommandText = "INSERT INTO user_inventory (userid, itemid) VALUES ('" + Context.Message.Author.Id + "', '" + newitemId + "')"; command.ExecuteNonQuery(); await ReplyAsync(Context.Message.Author.Mention + " adquiriste " + itemName + "!"); } else { await ReplyAsync("Já tens esse item no teu inventario " + Context.Message.Author.Mention + "! Usa \\inventario para ver os teus itens!"); } } connection.Close(); } else { itemReader.Close(); connection.Close(); await ReplyAsync("Esse item não existe :neutral_face:"); return; } } } }