public Program() { var builder = new ConfigurationBuilder().SetBasePath(AppContext.BaseDirectory).AddJsonFile(path: "config.json"); this.config = builder.Build(); #region Read users from file // The path to the file to read from DataScanner <User> scanner = new DataScanner <User> (@"\Data\Users\STB.UP"); List <User> users = new List <User> (); // Add each user to the list of users foreach (DataContainer item in scanner.ReadFromFile(':')) { users.Add(new User(ulong.Parse(item [0]), item [1], item [2], item [3], item [4])); } // Set list of users UserManager.SetUserList(users); #endregion #region Read events from file // The path to the file to read from DataScanner <Event> eventScanner = new DataScanner <Event> (@"\Data\Events\STB.EP"); List <Event> events = new List <Event> (); // Add each event to the list of events foreach (DataContainer item in eventScanner.ReadFromFile(':')) { events.Add(new Event(item [0], new DateTime().Parse(item [3]), new DateTime().Parse(item [4]), item [1], item [2], new DateTime().Parse(item [5]), item [6])); } // Set event list EventManager.SetEventsList(events); #endregion #region Read Vacation DataScanner <Vacation> vacScanner = new DataScanner <Vacation> (@"\Data\Events\STB.VP"); DataContainer? container = vacScanner.ReadFromFile(0); DiscordHandler.Instance.Vacation = (container != null ? Vacation.Parse(container.Value [0]) : Vacation.SetInvalidVacation()); #endregion }
public async Task VacationMode(string _value) { // The user to check for priviliges IGuildUser user = Context.User as IGuildUser; // Scanner for reading and writing from/to file DataScanner <Vacation> scanner = new DataScanner <Vacation> (@"\Data\Events\STB.VP"); // If the user is an admin set Sonnie in vacation mode if (user.IsAdmin()) { if (_value == "?") { string vacString = ((DiscordHandler.Instance.Vacation.ToString() == null) ? ("Jeg er ikke på ferie!") : ($"Jeg er på ferie fra: {DiscordHandler.Instance.Vacation.ToString ()}")); await Context.Channel.SendMessageAsync(vacString); return; } if (_value.ToLower() == "annuller") { await Context.Channel.SendMessageAsync("Ferien er annulleret"); DiscordHandler.Instance.Vacation = Vacation.SetInvalidVacation(); await scanner.WriteToFile(string.Empty); return; } DiscordHandler.Instance.Vacation = Vacation.Parse(_value); await Context.Channel.SendMessageAsync($"Jeg går på ferie fra: {DiscordHandler.Instance.Vacation.ToString ()}"); await scanner.WriteToFile(_value); return; } await Context.Channel.SendMessageAsync("Ups... Du er vidst ikke admin"); }