public EnigmaService(DiscordBotServiceContainer services, ConfigParserService configParser) : base(services) { letterSet = LetterSetIO.Read(LetterSetFile); steckering = PlugboardIO.Read(letterSet.Count, PlugboardFile); rotorKeys = RotorIO.Read(RotorKeysFile); this.configParser = configParser; Client.ReactionAdded += OnReactionAddedAsync; }
/// <summary> /// Runs the rotor keys randomizer. /// </summary> /// /// <exception cref="SaveFailedException"> /// Failed to save the new rotor keys. /// </exception> public void RandomizeRotorKeys(string input) { if (!int.TryParse(input, out int rotorCount)) { throw new FormatException("Input is not a valid integer!"); } if (rotorCount < 1) { throw new ArgumentOutOfRangeException("rotor count", "Input is less than 1!"); } try { RotorKeys newRotorKeys = RotorIO.Generate(rotorCount); SaveToFile(newRotorKeys, File); RotorKeys = newRotorKeys; } catch (Exception ex) { throw new SaveFailedException(ex); } }
public Task RandomKeysAsync(ICommandContext context, int count = 3) { return(context.Channel.SendMessageAsync("{" + string.Join(" ", RotorIO.Generate(count)) + "}")); }
/// <summary> /// Writes the input rotor count to the file. /// </summary> /// <param name="rotorKeys">The new number of rotors to save.</param> /// <param name="rotorKeysFile">The rotor count file to save the count to.</param> private void SaveToFile(RotorKeys rotorKeys, string rotorKeysFile) { Directory.CreateDirectory(Path.GetDirectoryName(rotorKeysFile)); RotorIO.Write(rotorKeys, rotorKeysFile); }
/// <summary> /// Reads the file and returns the sets up the rotor keys. /// </summary> /// <param name="rotorKeysFile">The file containing the rotor keys.</param> /// /// <exception cref="Exception"> /// A file has invalid formatting, a parsed letter was invalid, or mismatched characters. /// </exception> private void LoadFromFile(string rotorKeysFile) { RotorKeys = RotorIO.Read(rotorKeysFile); }