public override void ExecuteCommand(EvtChatCommandArgs e) { List <string> args = e.Command.ArgumentsAsList; //See the virtual controller if (args.Count == 0) { BotProgram.MsgHandler.QueueMessage($"The current virtual controller is {InputGlobals.CurVControllerType}. To set the virtual controller, add one as an argument: {GetValidControllerStr()}"); return; } string vControllerStr = args[0]; if (Enum.TryParse <InputGlobals.VControllerTypes>(vControllerStr, true, out InputGlobals.VControllerTypes vCType) == false) { BotProgram.MsgHandler.QueueMessage($"Please enter a valid virtual controller: {GetValidControllerStr()}"); return; } if (vCType == InputGlobals.CurVControllerType) { BotProgram.MsgHandler.QueueMessage($"The current virtual controller is already {InputGlobals.CurVControllerType}!"); return; } if (InputGlobals.IsVControllerSupported(vCType) == false) { BotProgram.MsgHandler.QueueMessage($"{vCType} virtual controllers are not supported on your operating system."); return; } InputHandler.CancelRunningInputs(); //Wait until no inputs are running while (InputHandler.CurrentRunningInputs > 0) { } //Change virtual controller InputGlobals.SetVirtualController(vCType); //Resume inputs InputHandler.ResumeRunningInputs(); BotProgram.MsgHandler.QueueMessage($"Set virtual controller to {InputGlobals.CurVControllerType} and reset all running inputs!"); }
public void Initialize() { if (Initialized == true) { return; } //Kimimaru: Use invariant culture Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; //Load all the necessary data; if something doesn't exist, save out an empty object so it can be filled in manually string loginText = Globals.ReadFromTextFileOrCreate(Globals.LoginInfoFilename); LoginInformation = JsonConvert.DeserializeObject <LoginInfo>(loginText); if (LoginInformation == null) { Console.WriteLine("No login information found; attempting to create file template. If created, please manually fill out the information."); LoginInformation = new LoginInfo(); string text = JsonConvert.SerializeObject(LoginInformation, Formatting.Indented); Globals.SaveToTextFile(Globals.LoginInfoFilename, text); } LoadSettingsAndBotData(); //Kimimaru: If the bot itself isn't in the bot data, add it as an admin! if (string.IsNullOrEmpty(LoginInformation.BotName) == false) { string botName = LoginInformation.BotName.ToLowerInvariant(); User botUser = null; if (BotData.Users.TryGetValue(botName, out botUser) == false) { botUser = new User(); botUser.Name = botName; botUser.Level = (int)AccessLevels.Levels.Admin; BotData.Users.TryAdd(botName, botUser); SaveBotData(); } } try { Credentials = new ConnectionCredentials(LoginInformation.BotName, LoginInformation.Password); } catch (Exception exception) { Console.WriteLine($"Invalid credentials: {exception.Message}"); Console.WriteLine("Cannot proceed. Please double check the login information in the data folder"); return; } //Set up client service ClientService = new TwitchClientService(Credentials, LoginInformation.ChannelName, Globals.CommandIdentifier, Globals.CommandIdentifier, true); ClientService.Initialize(); UnsubscribeEvents(); SubscribeEvents(); //Set up message handler MsgHandler = new BotMessageHandler(ClientService, LoginInformation.ChannelName, BotSettings.MessageCooldown); RoutineHandler = new BotRoutineHandler(ClientService); RoutineHandler.AddRoutine(new PeriodicMessageRoutine()); RoutineHandler.AddRoutine(new CreditsGiveRoutine()); RoutineHandler.AddRoutine(new ReconnectRoutine()); RoutineHandler.AddRoutine(new ChatBotResponseRoutine()); //Initialize controller input - validate the controller type first if (InputGlobals.IsVControllerSupported((InputGlobals.VControllerTypes)BotData.LastVControllerType) == false) { BotData.LastVControllerType = (int)InputGlobals.GetDefaultSupportedVControllerType(); } InputGlobals.VControllerTypes vCType = (InputGlobals.VControllerTypes)BotData.LastVControllerType; Console.WriteLine($"Setting up virtual controller {vCType}"); InputGlobals.SetVirtualController(vCType); Initialized = true; }