public static bool NewDay(SocketTextChannel channel) { channel.SendMessageAsync("`Resetting user daily limits...`"); List <string> PLAYSTODAY_TYPES = new List <string>(); foreach (var keyValue in UnoSaveFields) { if (keyValue.Key.StartsWith("PLAYSTODAY")) { PLAYSTODAY_TYPES.Add(keyValue.Key); } } var directories = Directory.EnumerateDirectories(USER_SAVE_DIRECTORY); foreach (var user in directories) { foreach (var playsToday in PLAYSTODAY_TYPES) { try { SaveFiles_Mapped.ModifyFieldValue(playsToday, user + "\\" + UNO_SAVE_FILE_NAME, "0"); }catch { /*file did not exist, move on*/ } } } channel.SendMessageAsync("`Storing metadata statistics...`"); GuildCache.LogCMD(); channel.SendMessageAsync("`Complete.`"); return(true); }
public SavedLeaderboard(string key, string[] leaderboardFile, Scoring type = Scoring.Points, short fortnightNo = -1, ulong teamspecific = 0) { this.scoringType = type; this.KEY = key; string[] temp; string team, username; team = ""; username = ""; int score = 0; this.FORTNIGHT_NO = fortnightNo; RESULTS = new List <LBUser>(); this.teamspecific = teamspecific; try { foreach (string str in leaderboardFile) { temp = str.Split(':'); if (temp.Count() != 2) { throw new Exception(); } ulong ID = 0; ID = UInt64.Parse(temp[0]); if (ID == 447487261760552982) { //dummy account which defaults to null, shouldn't appear on lb continue; } team = GuildCache.GetTeam(ID) ?? "?"; if (team == "?") { team = SaveFiles_Mapped.SearchCachedTeam(ID) ?? "?"; } if (teamspecific != 0) { if (team != teamspecific.ToString()) { continue; } } username = GuildCache.GetUsername(ID) ?? "?"; score = Int32.Parse(temp[1]); RESULTS.Add(new LBUser(ID, username, team, score)); } } catch (Exception e) { throw e; } CalculateTeamScores(); if (key == "POINTS-SERVER" && fortnightNo == FORTNIGHT_NUMBER && teamspecific == 0) { GuildCache.SetTeamScore(RED_TEAM_SCORE, 1); GuildCache.SetTeamScore(YELLOW_TEAM_SCORE, 2); GuildCache.SetTeamScore(GREEN_TEAM_SCORE, 3); GuildCache.SetTeamScore(BLUE_TEAM_SCORE, 4); } SortLeaderboard(); }
public static string GetUserScore(string gameAbbreviation, ulong soughtID, string name = "ITER", string humanName = "", short fortnight = -1, bool local = false) { string key = name + "-" + gameAbbreviation; //ITER-UNO example SavedLeaderboard lb = SaveFiles_Mapped.CreateLeaderboardObject(key, fortnight); string result = lb.GetHumanReadableScore(soughtID, humanName, local); return(result); }
public static string GetLeaderboard(string gameAbbreviation, string name = "ITER", string humanName = "", short fortnight = -1, short startIndex = 0, byte noOfEntries = 10, ulong teamspecific = 0) { string key = name + "-" + gameAbbreviation; //ITER-UNO example SavedLeaderboard lb = SaveFiles_Mapped.CreateLeaderboardObject(key, fortnight, teamspecific); string result = lb.MakeHumanReadable(humanName, startIndex, noOfEntries); return(result); }
public static void AddLine(string path, string key, string val) { if (SaveFiles_Mapped.SearchValue(path, key) != null) { return; } File.AppendAllLines(path, new string[] { key + ":" + val }); return; }
public static string GetUsername(ulong id) { string username = Uno_Cache.GetUser(id)?.Username; if (username == null) { username = SaveFiles_Mapped.SearchCachedUsername(id); } return(username); }
private void GetPlacements() { foreach (KeyValuePair <string, string> field in desiredFields) { if (stats.ContainsKey(field.Key)) { int lineNo = SaveFiles_Mapped.GetKeyLineNumber(LEADERBOARD_DIRECTORY + "\\" + field.Key + ".txt", USER_ID.ToString()); if (lineNo != -1) { placement.Add(field.Key, lineNo + 1); //ex: on the 0th line of save file implies 1st place } } } }
public static void LogCMD() { string date = ""; if (DateTime.Now.TimeOfDay.TotalMinutes > 180) { date = SaveFiles_Sequences.GenerateDateHex().Substring(0, 3); } else { date = (Int32.Parse(SaveFiles_Sequences.GenerateDateHex().Substring(0, 3), NumberStyles.HexNumber) - 0x1).ToString(); } SaveFiles_Mapped.AddLine(COMMANDS_BY_DATE_DIRECTORY, date, cmdEx.ToString()); cmdEx = 0; GuildCache.IncrementCMD(0); }
public static Embed GetDailyLimitEmbed(ulong ID) { EmbedBuilder emb = new EmbedBuilder(); try { string filePath = USER_SAVE_DIRECTORY + "\\" + ID + "\\Unoprofile.txt"; var limitPairs = SaveFiles_Mapped.GetAllValues(filePath, "PLAYSTODAY-"); if (limitPairs != null && limitPairs.Count() != 0) { int alreadyPlayed, maxDaily, playsLeft, msknights; alreadyPlayed = maxDaily = playsLeft = 0; msknights = MINESWEEPER_DAILY_LIMIT; foreach (var tuple in limitPairs) { alreadyPlayed = Int32.Parse(tuple.Item2); maxDaily = Defs.GetDailyLimit(tuple.Item1.ToLower()); playsLeft = maxDaily - alreadyPlayed; playsLeft = (playsLeft < 0) ? 0 : playsLeft; if (tuple.Item1 == "MS" || tuple.Item1 == "KNIGHTS") { msknights -= alreadyPlayed; continue; } emb.AddField(tuple.Item1[0] + tuple.Item1.Substring(1).ToLower(), playsLeft.ToString() + " more game(s)", true); } emb.AddField("MS/Knights", ((msknights < 0) ? "0" : msknights.ToString()) + " more game(s)", true); emb.WithTitle("Your remaining games available today:"); emb.WithColor(Color.Purple); TimeSpan beforeReset = Defs.TimeUntilMidnight(); emb.WithFooter("Your daily limits reset in " + beforeReset.Hours + " hours and " + beforeReset.Minutes + " minutes"); emb.WithCurrentTimestamp(); return(emb.Build()); } return(emb.WithTitle("No information").Build()); } catch (FileNotFoundException) { return(emb.WithTitle("You don't have an Uno account!").Build()); } catch (Exception e) { throw e; } }
internal static bool HasUserHitDailyLimit(ulong id, string gameName) { int limit = GetDailyLimit(gameName); if (limit == 0) { throw new Exception("Non-existing game sought for in Daily Limit search."); } gameName = gameName.ToUpper().Trim(); string playsTodayStr = SaveFiles_Mapped.SearchValue(USER_SAVE_DIRECTORY + "\\" + id + "\\" + UNO_SAVE_FILE_NAME, "PLAYSTODAY-" + gameName) ?? ""; if (!Int32.TryParse(playsTodayStr, out int ignore)) { throw new Exception("Daily limiit string was not a number"); } int playsToday = Int32.Parse(playsTodayStr); if (playsToday >= limit) { return(true); } return(false); }