Пример #1
0
        public TwitchBotConfigView()
        {
            InitializeComponent();
            MainViewModel.TwitchBot           = new TwitchBot(MainViewModel.ChatViewModel, MainViewModel.TwitchBotConfigModel);
            MainViewModel.SpeechToEmojiModule = new SpeechToTextModule();
            MainViewModel.SpeechToTextModule  = new SpeechToTextModule()
            {
                GrammarLoader = () => Task.FromResult((Grammar) new DictationGrammar())
            };

            MainViewModel.SpeechToTextModule.SpeechRecognized += _speechToTextModule_SpeechRecognized;
            MainViewModel.SpeechToEmojiModule.GrammarLoader    = async() =>
            {
                var choices = new Choices();
                if (!_emoteCache.ContainsKey(MainViewModel.TwitchBotConfigModel.Channel))
                {
                    _emoteCache.Add(MainViewModel.TwitchBotConfigModel.Channel, Task.Run(GetChannelEmotes));
                }

                choices.Add(await _emoteCache[MainViewModel.TwitchBotConfigModel.Channel]);

                var keyWordsGrammarBuilder = new GrammarBuilder(choices);

                var keyWordsGrammar = new Grammar(keyWordsGrammarBuilder);
                return(keyWordsGrammar);
            };
            MainViewModel.SpeechToEmojiModule.SpeechRecognized += _speechToEmojiModule_SpeechRecognized;

            MainViewModel.TwitchBotConfigModel.PropertyChanged += BotConfigModelPropertyChanged;
            MainViewModel.ChatViewModel.PropertyChanged        += ChatConfigModel_PropertyChanged;

            if (MainViewModel.ChatViewModel.IsSpeechToTextEnabled)
            {
                MainViewModel.SpeechToTextModule.Start();
            }
            if (MainViewModel.ChatViewModel.IsSpeechEmojiEnabled)
            {
                MainViewModel.SpeechToEmojiModule.Start();
            }

            MainViewModel.TwitchBotConfigModel.Commands.Add(
                new TwitchChatCommand(
                    "clap",
                    "Increases clap count and shows current clap count (optional: parameter for example '1', '2' or '-1')",
                    async(twitchBot, command) =>
            {
                int val = 1;
                if (!string.IsNullOrEmpty(command.ArgumentsAsString))
                {
                    int.TryParse(command.ArgumentsAsString, out val);
                }

                await twitchBot.SendMessage(command.ChatMessage.Channel, "Clap count: " + (_clapCount += val));
            }));

            MainViewModel.TwitchBotConfigModel.Commands.Add(
                new TwitchChatCommand(
                    new[] { "clapcount", "cc" },
                    "Shows current clap count",
                    async(twitchBot, command) =>
            {
                //if (command.ChatMessage.IsModerator || command.ChatMessage.)
                await twitchBot.SendMessage(command.ChatMessage.Channel, "Clap count: " + _clapCount);
            }));

            MainViewModel.TwitchBotConfigModel.Commands.Add(
                new TwitchChatCommand(
                    "code",
                    "Gives you a code which you can use to revert to with the 'recover' command",
                    async(twitchBot, command) =>
            {
                var chatter = MainViewModel.ChatViewModel.GetChatterFromUsername(command.ChatMessage.Username);
                if (chatter == null)
                {
                    await twitchBot.SendMessage(command.ChatMessage.Channel, "Sorry, who are you? peepoWTF");
                    return;
                }

                await twitchBot.SendMessage(command.ChatMessage.Channel, "Your code: " + chatter.GetCode());
            }));

            MainViewModel.TwitchBotConfigModel.Commands.Add(
                new TwitchChatCommand(
                    "recover",
                    "Recovers your lost voice, use the code you got from the 'code' command as parameter",
                    async(twitchBot, command) =>
            {
                var chatter = Chatter.FromCode(command.ArgumentsAsString);
                if (chatter.Name != command.ChatMessage.Username)
                {
                    await twitchBot.SendMessage(command.ChatMessage.Channel, "Sorry, that voice was never yours!");
                    return;
                }

                var existingChatter = MainViewModel.ChatViewModel.GetChatterFromUsername(chatter.Name);
                if (existingChatter != null)
                {
                    MainViewModel.ChatViewModel.RemoveChatter(chatter.Name);
                }

                MainViewModel.ChatViewModel.AddChatter(chatter);

                await twitchBot.SendMessage(command.ChatMessage.Channel, ":+1:");
            }));


            //MainViewModel.TwitchBotConfigModel.Commands.Add(
            //    new TwitchChatCommand(
            //        "fpv",
            //        "Toggles camera view between first person view and third person view",
            //        async (twitchBot, channel, commandParams) =>
            //        {
            //            CameraConfigModel.GameCameraProfile.CameraPlusConfig.IsThirdPersonView = !CameraConfigModel.GameCameraProfile.CameraPlusConfig.IsThirdPersonView;

            //            await twitchBot.SendMessage(channel, CameraConfigModel.GameCameraProfile.CameraPlusConfig.IsThirdPersonView ? "Switching to third person view" : "Switching to first person view");

            //            try
            //            {
            //                CameraConfigModel.GameCameraProfile.CameraPlusConfig.SaveToBeatSaber(AppConfigModel);
            //            }
            //            catch (Exception ex)
            //            {
            //                await twitchBot.SendMessage(channel, $"Error while trying to update camera config: '{ex.Message}'");
            //            }
            //        }));

            //MainViewModel.TwitchBotConfigModel.Commands.Add(
            //    new TwitchChatCommand(
            //        "tw",
            //        "Toggles walls transparency",
            //        async (twitchBot, channel, commandParams) =>
            //        {
            //            CameraConfigModel.GameCameraProfile.CameraPlusConfig.MakeWallsTransparent = !CameraConfigModel.GameCameraProfile.CameraPlusConfig.MakeWallsTransparent;

            //            await twitchBot.SendMessage(channel, CameraConfigModel.GameCameraProfile.CameraPlusConfig.MakeWallsTransparent ? "Making walls transparent" : "Reverting to original walls");

            //            try
            //            {
            //                CameraConfigModel.GameCameraProfile.CameraPlusConfig.SaveToBeatSaber(AppConfigModel);
            //            }
            //            catch (Exception ex)
            //            {
            //                await twitchBot.SendMessage(channel, $"Error while trying to update camera config: '{ex.Message}'");
            //            }
            //        }));

            MainViewModel.TwitchBotConfigModel.Commands.Add(
                new TwitchChatCommand(
                    new[] { "help", "commands" },
                    "Shows this help",
                    async(twitchBot, chatCommand) =>
            {
                await twitchBot.SendMessage(chatCommand.ChatMessage.Channel, $"This bot supports the following commands with prefixes '{string.Join("/", MainViewModel.TwitchBotConfigModel.CommandIdentifiers)}':");
                foreach (var command in MainViewModel.TwitchBotConfigModel.Commands.Where(x => x.IsVisibleInHelp))
                {
                    await twitchBot.SendMessage(chatCommand.ChatMessage.Channel, $"'{string.Join("/", command.Commands)}': {command.Description}");
                }
            },
                    false
                    ));

            MainViewModel.TwitchBotConfigModel.Commands.Add(
                new TwitchChatCommand(
                    new[] { "cp", "cam", "camera", "cameraProfiles" },
                    "Selects a camera profile (with parameter), or shows a list of camera profiles (no parameter)",
                    async(twitchBot, chatCommand) =>
            {
                if (chatCommand.ArgumentsAsString.IsNullOrEmpty())
                {
                    await twitchBot.SendMessage(chatCommand.ChatMessage.Channel, "This bot currently has following camera profiles:");
                    foreach (var profile in MainViewModel.CameraConfigModel.Profiles.Where(x => x.IsChoosableByViewers && x.Aliases.Count > 0))
                    {
                        await twitchBot.SendMessage(chatCommand.ChatMessage.Channel, $"'{string.Join("' / '", profile.Aliases.Select(x => x.Alias))}': {profile.Name}");
                    }

                    return;
                }

                foreach (var profile in MainViewModel.CameraConfigModel.Profiles.Where(x => x.IsChoosableByViewers))
                {
                    foreach (var profileAlias in profile.Aliases)
                    {
                        if (profileAlias.Alias.Equals(chatCommand.ArgumentsAsString, StringComparison.InvariantCultureIgnoreCase))
                        {
                            if (CameraConfigModel.GameCameraProfile == profile)
                            {
                                // TODO: find out why it sometimes doesn't work, do i save it but the game ignores it?
                                profile.CameraPlusConfig.SaveToBeatSaber(MainViewModel.AppConfigModel);
                                return;
                            }

                            profile.CameraPlusConfig.SaveToBeatSaber(MainViewModel.AppConfigModel);
                            CameraConfigModel.GameCameraProfile = profile;
                            await twitchBot.SendMessage(chatCommand.ChatMessage.Channel, $"Switching camera to '{profileAlias.Alias}' - {profile.Name}");
                            return;
                        }
                    }
                }
            },
                    false
                    ));
        }