/// <summary> /// Initiates and loads the chat settings /// </summary> public void LoadSettings() { //Creates the container _settings = new Settings(); _settings.LoadSettings(_bot); //Load the chat bot _bot = new ChatBot.ChatBot(_settings.Channel); _bot.SetBotAccountInfo(_settings.BotUsername, _settings.PlaintextPassword); _bot.PermaModerators = _settings.PermaMods; }
/// <summary> /// Sets up a new configuration dialogue and configures the new bot /// </summary> /// <param name="firstTime">Indicating the first configuration</param> /// <param name="bot">The chat bot to be configured</param> public void NewSettings(bool firstTime, ChatBot.ChatBot bot) { //Configure new settings var configForm = new Configure(); if (configForm.ShowDialog() == DialogResult.OK) { //Generate new password entropy and hash _pwEntropy = NewPasswordEntropy(); //Load the info _channel = configForm.ChannelBox.Text; _botUsername = configForm.UsernameBox.Text; _botPassword = EncryptPassword(configForm.PasswordBox.Text, _pwEntropy); if (firstTime) { bot = new ChatBot.ChatBot(_channel); } else { bot.Channel = _channel; } bot.SetBotAccountInfo(_botUsername, PlaintextPassword); WriteSettings(); } else { if (firstTime) { MessageBox.Show("Unable to configure the settings. Exiting", "BuddhaBot Error", MessageBoxButtons.OK, MessageBoxIcon.Error); throw new Exception("Cancelled configure dialogue"); } } }
/// <summary> /// Sets up a new configuration dialogue and configures the new bot /// </summary> /// <param name="firstTime">Indicating the first configuration</param> /// <param name="bot">The chat bot to be configured</param> public void NewSettings(bool firstTime, ChatBot.ChatBot bot) { //Configure new settings var configForm = new Configure(); if (configForm.ShowDialog() == DialogResult.OK) { //Generate new password entropy and hash _pwEntropy = NewPasswordEntropy(); //Load the info _channel = configForm.ChannelBox.Text; _botUsername = configForm.UsernameBox.Text; _botPassword = EncryptPassword(configForm.PasswordBox.Text, _pwEntropy); if (firstTime) bot = new ChatBot.ChatBot(_channel); else bot.Channel = _channel; bot.SetBotAccountInfo(_botUsername, PlaintextPassword); WriteSettings(); } else { if (firstTime) { MessageBox.Show("Unable to configure the settings. Exiting", "BuddhaBot Error", MessageBoxButtons.OK, MessageBoxIcon.Error); throw new Exception("Cancelled configure dialogue"); } } }
/// <summary> /// Loads the settings from the settings file /// </summary> /// <param name="bot">The chat bot to be configured</param> public void LoadSettings(ChatBot.ChatBot bot) { //Check that the settings file exists if (!File.Exists(SettingsFile)) { //Notify user of the issue MessageBox.Show(string.Format("Unable to find settings file ({0}). Exiting.", SettingsFile), "BuddhaBot Error", MessageBoxButtons.OK, MessageBoxIcon.Error); throw new Exception("Unable to find settings file"); } //Load file into string var settingsContent = File.ReadAllText(SettingsFile); //Load string into json format dynamic settingsJson = JObject.Parse(settingsContent); //Set up variables _channel = settingsJson.channel.ToString(); _botUsername = settingsJson.botusername.ToString(); _botPassword = settingsJson.botpassword.ToString(); _pwEntropy = settingsJson.pwentropy.ToString(); //First time running the program if (string.IsNullOrEmpty(_channel) || string.IsNullOrEmpty(_botUsername) || string.IsNullOrEmpty(_botPassword) || string.IsNullOrEmpty(_pwEntropy)) { //Configure new settings NewSettings(true, bot); } else { try { //Test Decrypt base-64 strings DecryptPassword(_botPassword, _pwEntropy); } catch (Exception) //Catch any exceptions - this means there was an error loading the password { NewSettings(true, bot); } } //Load the censors foreach (var censor in settingsJson.censored) { var action = ToCensorAction(censor.action.ToString()); //If the action was successfully loaded if (action != CommandResponse.ResponseAction.None) { var message = censor.response; //There is no custom message Commands.Censored.Add(censor.search.ToString(), message == null ? new CommandResponse(action) : new CommandResponse(message.ToString(), action)); } } //Load the commands foreach (var command in settingsJson.commands) { //Load the variables var name = command.name.ToString(); var response = command.response.ToString(); Commands.TextCommands.Add(name.ToUpper(), response); } //Load the perma-mods foreach (var moderator in settingsJson.permamods) { //Add to the list _permaMods.Add(moderator.ToString().ToUpper()); } }