Exemple #1
0
        private void OnKeyPressed(object sender, ControllerEventArgs args)
        {
            var key   = args.Key;
            var state = args.State;

            if (state != InputEvent.State.Pressed)
            {
                return;
            }

            var server = _bot.FindServers(_options.Server).FirstOrDefault();

            if (null == server)
            {
                Logger.Error("Could not find server");
                return;
            }

            var user = server.FindUsers(_options.User).FirstOrDefault();

            if (user == null)
            {
                Logger.Error("Could not find user");
                return;
            }

            var channel = user.VoiceChannel;

            if (null == channel)
            {
                Logger.Error("Could not find voice channel");
                return;
            }

            var soundName = GetSound(key);

            if (null == soundName)
            {
                Logger.Error("Could not find sound");
                return;
            }

            var sound = _soundRepository.GetSoundFile(soundName);

            _player.PlayAsync(channel, sound.Path);
        }
        private void OnInputRecieved(object sender, InputEventArgs inputEventArgs)
        {
            var value = inputEventArgs.Event;

            if (false == IsButton(value))
            {
                return;
            }

            var buttonId = value.Number;
            var state    = (InputEvent.State)value.Value;

            ControllerEventArgs.KeyCode code;
            if (KeyMapping.TryGetValue(buttonId, out code))
            {
                var args = new ControllerEventArgs(code, state);
                RaiseKeyPressed(args);
            }
        }
 private void RaiseKeyPressed(ControllerEventArgs e)
 {
     KeyPressed?.Invoke(this, e);
 }