public void TrannyLoop() { while (true) { var added = DateTime.UtcNow.AddDays(1); var dt = new DateTime(added.Year, added.Month, added.Day, 0, 0, 0); var wait = (dt - DateTime.UtcNow); Console.WriteLine("Sleeping until {0} for {1}", dt, wait); Thread.Sleep(wait); lock (Transactions) { Save(true); Transactions.Clear(); string filename = DateTime.Now.ToString("yyyy-MM-dd"); string yesterday_filename = DateTime.Now.AddDays(0).ToString("yyyy-MM-dd"); File.Move("./transactions", "./transaction-backups/transactions-" + filename); File.Move("./save", "./transaction-backups/save-" + filename); File.Move("./generator", Path.Combine(Config.GetString("generator.directory"), yesterday_filename + "-" + Program.Random.HashedName)); File.WriteAllText(Path.Combine(Config.GetString("generator.directory"), "latest.txt"), "http://hexafluoride.dryfish.net/audit-files/" + yesterday_filename + "-" + Program.Random.HashedName); File.Copy(Path.Combine(Config.GetString("generator.directory"), yesterday_filename + "-" + Program.Random.HashedName), Path.Combine(Config.GetString("generator.directory"), "latest"), true); File.WriteAllText(Path.Combine(Config.GetString("generator.directory"), "index.html"), IndexGenerator.FromDirectory(Config.GetString("generator.directory"))); Program.Random = GeneratorManager.Create(); Console.WriteLine("Cycled out transactions file"); } Thread.Sleep(5000); } }
static void Main(string[] args) { Name = "finance"; System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); Commands = new Dictionary <string, MessageHandler>() { //{"", CheckForExpression }, { ".give", Give }, { ".pokies", Bet }, { ".bene", GetPaid }, { ".mug", Mug }, { ".money", GetBalance }, { ".getsource", GetSource }, { "$donate", Donate }, { ".bet", Alias }, { "$getkey", GetKey }, { "$setkey", SetKey }, { "$resetstrs", ResetStrs }, { ".bot", SetBot }, { ".human", SetHuman }, { ".delete", Delete }, { "$stats", GetStats }, { ".stats", GetStats }, { "$writestats", WriteFile }, { "$writebots", WriteBots }, { "$botwealth", BotWealth }, { "$deletebots", RedistributeBotMoney }, { "$recalculate", RecalculateTable }, { ".rankcost", GetBalanceForRank }, { "$draw", DrawLottery }, { ".buytickets", BuyTickets }, { "$startlottery", StartLottery }, { ".chance", GetChance }, { "$distribute", DistributeAmount }, { ".rigreport", RigReport }, { "$addexpr", AddToExpression }, { "$execute", ExecuteExpression }, { "$startexpr", StartTyping }, { "$dumplist", DumpList }, { "$dumptranslations", DumpTranslations }, { ".fair", ProvablyFair }, { "$dumpgenerator", DumpGenerator }, { "$reindex", Reindex }, }; Manager.Load(); LotteryManager.Load(); new Thread(new ThreadStart(Manager.TrannyLoop)).Start(); StringManager.SetStrings(); string filename = "./generator"; if (File.Exists(filename)) { Random = RandomGenerator.FromFile(filename); } else { Random = GeneratorManager.Create(); } string query = ""; //while(true) //{ // string line = Console.ReadLine(); // if (string.IsNullOrWhiteSpace(line)) // { // IFilter filter = new FilterInstance<Transaction>(Manager.Transactions.ToList()); // object result = null; // foreach (var action in query.Split('\n')) // { // if (string.IsNullOrWhiteSpace(action)) // continue; // var pair = filter.Apply(new Clause(action.Split(' ')[0], string.Join(" ", action.Split(' ').Skip(1)))); // if (pair.Key == 0) // filter = (IFilter)pair.Value; // else if (pair.Key == 1) // result = pair.Value; // } // if (result is IEnumerable<object>) // { // foreach (var obj in (result as IEnumerable<object>)) // Console.WriteLine(obj); // } // else // Console.WriteLine(result.ToString()); // query = ""; // } // else // query += line + "\n"; //} Init(args, delegate { }); }