public static async Task <bool> BuyItem(ulong userid, int shopSlot, int quantity) { if (shopSlot > Shop.Count || shopSlot < 0) { return(false); } SocketGuildUser user = BotUtils.GetGUser(userid); UserDataNode customer = UserDataManager.GetUserData(user); ShopNode item = Shop[shopSlot]; if (quantity > 0 && customer.Kamtrokens >= item.Price * quantity) { customer.Kamtrokens -= item.Price * quantity; customer.KamtrokensSpent += item.Price * quantity; UserInventoryManager.GetInventory(userid).AddItem(item.ItemID, quantity); await AchievementManager.OnBuy(user); UserDataManager.SaveUserData(); UserInventoryManager.SaveInventories(); return(true); } return(false); }
/// <summary> /// Adds to the score of the specified user. /// -C /// </summary> /// <param name="user">The user who will have their score added to</param> /// <param name="score">The score that will be added to the user</param> public static async Task AddScore(SocketGuildUser user, int score) { AddUserIfNotExists(user); UserDataNode data = GetUserData(user); data.Score += score; // Add to the score if (data.KamtrokensEarned < 10) { data.KamtrokenEarnProgress += score; } if (data.KamtrokenEarnProgress >= 100 && data.KamtrokensEarned < 10) { data.KamtrokenEarnProgress -= 100; data.Kamtrokens++; data.KamtrokensEarned++; SaveUserData(); } data.WeeklyScore += score; await AchievementManager.OnScore(user); SaveUserData(); // Save the updated data. }
public ShopEmbed(SocketCommandContext ctx) { SetCtx(ctx); Customer = UserDataManager.GetUserData(BotUtils.GetGUser(ctx)); AddMenuOptions(ReactionHandler.SELECT, ReactionHandler.UP, ReactionHandler.DOWN, ReactionHandler.BACK); }
/// <summary> /// Method that checks for titles related to rep. Called whenever a user reps another user. /// </summary> /// <remarks> /// This method has a lot of checks, they are all there without return statements for a reason. /// It will make sure to fill in any missing titles the user should have gotten. /// </remarks> /// <param name="from">The user doing the repping</param> /// <param name="to">The user who has been repped</param> /// <returns></returns> public static async Task OnRep(SocketGuildUser from, SocketGuildUser to) { UserDataNode f = UserDataManager.GetUserData(from); UserDataNode t = UserDataManager.GetUserData(to); // rep given if (f.RepGiven >= 1) { await AddTitle(from, TitleIDs.WARM_WELCOMER); } if (f.RepGiven >= 10) { await AddTitle(from, TitleIDs.DECAREPPER); } if (f.RepGiven >= 50) { await AddTitle(from, TitleIDs.CHARITABLE); } if (f.RepGiven >= 100) { await AddTitle(from, TitleIDs.HUNDRED_REP_GIVEN); } if (f.RepGiven >= 500) { await AddTitle(from, TitleIDs.REPPER_OF_D); } // rep recieved if (t.Reputation >= 1) { await AddTitle(to, TitleIDs.WARMLY_WELCOMED); } if (t.Reputation >= 10) { await AddTitle(to, TitleIDs.TEN_REP); } if (t.Reputation >= 30) { await AddTitle(to, TitleIDs.COOL_KID); } if (t.Reputation >= 100) { await AddTitle(to, TitleIDs.POPULAR); } if (t.Reputation >= 1000) { await AddTitle(to, TitleIDs.MILLENIAL_MEMBER); } }
public CoinFlipEmbed(SocketCommandContext ctx) { SetCtx(ctx); User = BotUtils.GetGUser(ctx); Data = UserDataManager.GetUserData(User); AddMenuOptions(new MenuOptionNode(HEADS, "Heads"), new MenuOptionNode(TAILS, "Tails")); }
public InventoryEmbed(SocketCommandContext ctx) { SetCtx(ctx); User = BotUtils.GetGUser(ctx); UserData = UserDataManager.GetUserData(User); Inventory = UserInventoryManager.GetInventory(User.Id); List <uint> Items = Inventory.Items.Keys.ToList(); Items.Sort(); if (Items.Count != 0) { SelectedItem = Items[0]; } AddMenuOptions(ReactionHandler.SELECT, ReactionHandler.BACK, ReactionHandler.UP, ReactionHandler.DOWN); }
public override Embed GetEmbed() { EmbedBuilder eb = new EmbedBuilder(); eb.WithTitle(Header); eb.WithColor(Title.GetColor()); eb.AddField("Title", Title.Name); eb.AddField("Description", Title.Description); eb.AddField("Kamtroken Reward", Title.KamtrokenReward, true); eb.AddField("Temporary Rep Point Reward", Title.TempRepReward, true); if (Title.PermRepReward > 0) { UserDataNode u = UserDataManager.GetUserData(User); eb.AddField("Other Rewards:", $"This title has granted you +{Title.PermRepReward} to your weekly max reputation balance! This means that at the end of each week, the number of reputation points you have left to give will be set to {u.MaxReputation} if it isn't already above that number."); } return(eb.Build()); }
public static Tuple <UserDataNode, UserSettingsNode> AddUser(ulong id, string username, string nickname = null) { UserDataNode dNode = null; UserSettingsNode sNode = null; if (!UserData.ContainsKey(id)) { dNode = new UserDataNode(username, nickname ?? ""); UserData.Add(id, dNode); } if (!UserSettings.ContainsKey(id)) { sNode = new UserSettingsNode(username); UserSettings.Add(id, sNode); } SaveUserData(); return(new Tuple <UserDataNode, UserSettingsNode>(dNode, sNode)); }
/// <summary> /// Adds a user to the Database. /// </summary> /// <remarks> /// This method saves every time because there aren't going to be too many new users past a certain point /// </remarks> /// <param name="user">The User to add</param> /// <returns>The data node that was added</returns> public static Tuple <UserDataNode, UserSettingsNode> AddUser(SocketGuildUser user) { if (!UserData.ContainsKey(user.Id)) { UserDataNode node = new UserDataNode(user.Username, user.Nickname ?? ""); UserData.Add(user.Id, node); GetUserData(user).Inventory = new UserInventoryNode(); SaveUserData(); } if (!UserSettings.ContainsKey(user.Id)) { UserSettingsNode node = new UserSettingsNode(BotUtils.GetFullUsername(user)); UserSettings.Add(user.Id, node); SaveUserSettings(); } Tuple <UserDataNode, UserSettingsNode> value = new Tuple <UserDataNode, UserSettingsNode>(GetUserData(user), GetUserSettings(user)); return(value); }
public static async Task AddTitle(SocketGuildUser user, int titleid) { if (!NodeMap.ContainsKey(titleid)) { KLog.Error($"Attempted to give user {BotUtils.GetFullUsername(user)} invalid title ID #{titleid}"); return; } TitleNode node = NodeMap[titleid]; if (node == null) { KLog.Error($"Attempted to give user {BotUtils.GetFullUsername(user)} null title with ID #{titleid}"); return; } UserDataNode u = UserDataManager.GetUserData(user); if (u.Titles == null) { u.Titles = new List <int>(); } if (u.Titles.Contains(titleid)) { return; // Don't give duplicate titles } u.Titles.Add(titleid); node.OnComplete(user); KLog.Important($"User {BotUtils.GetFullUsername(user)} has earned title {node.Name}"); UserDataManager.SaveUserData(); await AnnounceAchievement(user, node); }
public ProfileEmbed(UserDataNode data, SocketUser user) { Data = data; User = user; }
public override async Task ButtonAction(SocketReaction action) { switch (action.Emote.ToString()) { case ReactionHandler.CHECK_STR: // verify inputs int k, t, p; // kamtrokens, temp rep, and perm rep respectively if (!(int.TryParse(KamtrokenReward, out k) && int.TryParse(TempRepReward, out t) && int.TryParse(PermRepReward, out p))) { InvalidNumberWarning = true; await UpdateEmbed(); return; } // Color string c = EmbedColor.Replace("#", "").Replace("0x", "").Replace("x", ""); uint cc; if (!uint.TryParse(c, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out cc)) { InvalidNumberWarning = true; await UpdateEmbed(); return; } Color ec = new Color(cc); // Add the stats UserDataNode data = UserDataManager.GetUserData(Winner); data.Kamtrokens += k; data.ReputationToGive += t; data.MaxReputation += p; UserDataManager.SaveUserData(); // Send the gift string wins = ""; if (k > 0) { wins += $"{k} Kamtroken{(k == 1 ? "":"s")}"; } if (t > 0) { if (wins.Length != 0) { wins += ", "; } wins += $"{t} Temporary Reputation Point{(t == 1 ? "" : "s")}"; } wins.TrimEnd(',', ' '); if (k == 0 && t == 0) { wins = ""; } if (p > 0) { wins += $"\n\nIn addition, the amount of repuation you get per week has been increaced by {p}"; } await BotUtils.DMUserAsync(Winner, new BasicEmbed("Congradulations!", $"You have won {(string.IsNullOrWhiteSpace(wins) ? "my appreciation!":wins)}", "Winnings", ec, "", MessageText).GetEmbed()); // Update the embed GiftSent = true; await UpdateEmbed(); EventQueueManager.RemoveMessageEvent(this); break; case ReactionHandler.DECLINE_STR: EventQueueManager.RemoveMessageEvent(this); await Message.DeleteAsync(); await Context.Channel.SendMessageAsync(BotUtils.KamtroText("Reward Sending Canceled.")); break; } }