Ejemplo n.º 1
0
 public ArtistViewModel()
 {
     PlayTracksCommand  = new StaticCommand <IEnumerable>(ExecutePlayTracks);
     QueueTracksCommand = new StaticCommand <IEnumerable>(ExecuteQueueTracks);
     GoToAlbumCommand   = new StaticCommand <TrackContainer>(ExecuteGoToAlbum);
     CommandBar         = new CommandBar();
 }
Ejemplo n.º 2
0
 public StaticCommandItem(StaticCommand staticCommand)
 {
     Name              = staticCommand.Name;
     Category          = staticCommand.Category.Name;
     StaticCommandType = staticCommand.GetType();
     OfflineAvailable  = StaticCommandType.GetCustomAttribute <OfflineAvailableAttribute>() != null;
 }
Ejemplo n.º 3
0
        public async Task <bool> ExecuteCommand(StaticCommand staticCommand, TransmissionEvent transmissionEvent,
                                                ExecutionEvent executionEvent, StopEvent stopEvent, List <Condition> conditions, CommandTarget target)
        {
            if (conditions != null && conditions.Count == 0)
            {
                conditions = null;
            }

            var plugin = StaticCommands[staticCommand.GetType()];

            if (plugin != null)
            {
                if (!await UploadPluginToServer(plugin))
                {
                    return(false);
                }
            }

            _connectionManager.SendCommand(new DynamicCommand
            {
                CommandId         = staticCommand.CommandId,
                Target            = target,
                Conditions        = conditions,
                TransmissionEvent = transmissionEvent,
                ExecutionEvent    = executionEvent,
                CommandParameter  = staticCommand.GetCommandParameter().Data,
                PluginHash        = plugin?.PluginHash,
                StopEvent         = stopEvent
            });

            return(true);
        }
Ejemplo n.º 4
0
        public TagsTabViewModel()
        {
            HeaderInfo = new HeaderInfo
            {
                Title            = "Tags",
                IsSelectedAction = isSelected =>
                {
                    if (!Tags.Any() && isSelected)
                    {
                        GetTags();
                    }
                }
            };

            _mixes                     = new ObservableCollection <Mix>();
            _tags                      = new ObservableCollection <Tag>();
            _selectedTags              = new ObservableCollection <Tag>();
            _ui                        = TaskScheduler.FromCurrentSynchronizationContext();
            ToggleTagCommand           = new StaticCommand <Tag>(ExecuteToggleTag);
            ToggleTagFilterCommand     = new StaticCommand <string>(ExecuteToggleTagFilter);
            GoToNextPageCommand        = new ManualCommand(ExecuteGoToNextPage, CanExecuteGoToNextPage);
            GoToPreviousPageCommand    = new ManualCommand(ExecuteGoToPreviousPage, CanExecuteGoToPreviousPage);
            GoToNextTagPageCommand     = new ManualCommand(ExecutGoToNextTagPage, CanExecuteGoToNextTagPage);
            GoToPreviousTagPageCommand = new ManualCommand(ExecuteGoToPreviousTagPage, CanExecuteGoToPreviousTagPage);
            PlayMixCommand             = new StaticCommand <Mix>(ExecutePlayMix);
            QueueMixCommand            = new StaticCommand <Mix>(ExecuteQueueMix);
        }
Ejemplo n.º 5
0
 public AppCommandsHandler()
 {
     _addTrackStreamDataToFavoritesCommand = new StaticCommand <object>(ExecuteAddTrackStreamDataToFavorites);
     _addTrackStreamToFavoritesCommand     = new StaticCommand <object>(ExecuteAddTrackStreamToFavorites);
     _addTrackToFavoritesCommand           = new StaticCommand <object>(ExecuteAddTrackToFavorites);
     _addTrackContainerToFavoritesCommand  = new StaticCommand <object>(ExecuteAddTrackContainerToFavorites);
     _addTrackToLikesCommand = new StaticCommand <object>(ExecuteAddTrackToLikes);
 }
Ejemplo n.º 6
0
        public MainStationViewModel(
            ILoadingIndicatorService loadingIndicatorService,
            IRadio radio,
            IToastService toastService,
            ILoggerFacade logger,
            IDocumentStore documentStore)
        {
            _loadingIndicatorService = loadingIndicatorService;
            _radio                            = radio;
            _toastService                     = toastService;
            _logger                           = logger;
            _documentStore                    = documentStore;
            _fetchPreviewTimer                = new Timer(1000);
            _fetchPreviewTimer.Elapsed       += FetchPreviewTimerTick;
            _scheduler                        = TaskScheduler.FromCurrentSynchronizationContext();
            _styles                           = new ObservableCollection <TermModel>();
            _moods                            = new ObservableCollection <TermModel>();
            _selectedMoods                    = new ObservableCollection <TermModel>();
            _selectedMoods.CollectionChanged += (sender, args) =>
            {
                RaisePropertyChanged("SelectedMoodsText");
                _fetchPreviewTimer.Stop();
                _fetchPreviewTimer.Start();
            };

            _selectedStyles = new ObservableCollection <TermModel>();
            _selectedStyles.CollectionChanged += (sender, args) =>
            {
                RaisePropertyChanged("SelectedStylesText");
                _fetchPreviewTimer.Stop();
                _fetchPreviewTimer.Start();
            };

            ToggleStyleCommand   = new StaticCommand <TermModel>(ExecuteToggleStyle);
            ToggleMoodCommand    = new StaticCommand <TermModel>(ExecuteToggleMood);
            StartRadioCommand    = new AutomaticCommand(ExecuteStartRadio, CanExecuteStartRadio);
            IncreaseBoostCommand = new StaticCommand <TermModel>(ExecuteIncreaseBoost);
            DecreaseBoostCommand = new StaticCommand <TermModel>(ExecuteDecreaseBoost);
            RequireTermCommand   = new StaticCommand <TermModel>(ExecuteRequireTerm);
            BanTermCommand       = new StaticCommand <TermModel>(ExecuteBanTerm);
            Tempo                           = new Range();
            Tempo.Rounding                  = MidpointRounding.ToEven;
            Tempo.RangeChanged             += MetricChanged;
            Loudness                        = new Range();
            Loudness.RangeChanged          += MetricChanged;
            Energy                          = new Range();
            Energy.RangeChanged            += MetricChanged;
            ArtistFamiliarity               = new Range();
            ArtistFamiliarity.RangeChanged += MetricChanged;
            ArtistHotness                   = new Range();
            ArtistHotness.RangeChanged     += MetricChanged;
            SongHotness                     = new Range();
            SongHotness.RangeChanged       += MetricChanged;
            Danceability                    = new Range();
            Danceability.RangeChanged      += MetricChanged;
        }
        public FavoritesViewModel()
        {
            HeaderInfo = new HeaderInfo
            {
                Title = "Favorites"
            };

            CommandBar             = new CommandBar();
            PlayFavoritesCommand   = new StaticCommand <IEnumerable>(ExecutePlayFavorite);
            QueueFavoritesCommand  = new StaticCommand <IEnumerable>(ExecuteQueueFavorite);
            DeleteFavoritesCommand = new StaticCommand <IEnumerable>(ExecuteDeleteFavorite);
        }
        public RecentViewModel()
        {
            _recentArtists = new ObservableCollection <SimilarArtistModel>();

            HeaderInfo                    = new HeaderInfo();
            HeaderInfo.Title              = "Recent";
            HeaderInfo.IsSelectedAction   = IsSelectedAction;
            PlayArtistCommand             = new StaticCommand <SimilarArtistModel>(ExecutePlayArtist);
            QueueArtistCommand            = new StaticCommand <SimilarArtistModel>(ExecuteQueueSimilarArtist);
            AddFavoriteArtistCommand      = new StaticCommand <SimilarArtistModel>(ExecuteAddFavoriteArtist);
            SearchForSimilarArtistCommand = new StaticCommand <SimilarArtistModel>(ExecuteSearchForSimilarArtist);
        }
Ejemplo n.º 9
0
        public void SendCommand(StaticCommand staticCommand)
        {
            var parameter = staticCommand.GetCommandParameter().Data;

            ConnectionInfo.UnsafeSendCommand(this, parameter.Length + 17, writer =>
            {
                writer.Write((byte)ClientCommandsCommunication.SendCommand);
                writer.Write(staticCommand.CommandId.ToByteArray());
                writer.Write(parameter);
            });
            LogService.Send(string.Format((string)Application.Current.Resources["ExecuteStaticCommand"],
                                          staticCommand.Name));
        }
 protected MixListViewModel()
 {
     _ui                           = TaskScheduler.FromCurrentSynchronizationContext();
     _mixes                        = new ObservableCollection <Mix>();
     _tagFilterList                = new ObservableCollection <string>();
     _tags                         = new ObservableCollection <string>();
     _deferredSearchTimer          = new Timer(750);
     _deferredSearchTimer.Elapsed += OnDeferredSearchTimerTick;
     ToggleTagFilterCommand        = new StaticCommand <string>(ExecuteToggleTagFilter);
     PlayMixCommand                = new StaticCommand <Mix>(ExecutePlayMix);
     QueueMixCommand               = new StaticCommand <Mix>(ExecuteQueueMix);
     GoToNextPageCommand           = new ManualCommand(ExecuteGoToNextPage, CanExecuteGoToNextPage);
     GoToPreviousPageCommand       = new ManualCommand(ExecuteGoToPreviousPage, CanExecuteGoToPreviousPage);
 }
        public SimilarViewModel()
        {
            _similarArtists = new ObservableCollection <SimilarArtistModel>();

            HeaderInfo = new HeaderInfo
            {
                Title = "Similar artists"
            };
            CommandBar               = new CommandBar();
            PlayArtistCommand        = new StaticCommand <SimilarArtistModel>(ExecutePlaySimilarArtist);
            QueueArtistCommand       = new StaticCommand <SimilarArtistModel>(ExecuteQueueSimilarArtist);
            AddFavoriteArtistCommand = new StaticCommand <SimilarArtistModel>(ExecuteAddFavoriteArtist);
            GoToArtistCommand        = new StaticCommand <SimilarArtistModel>(ExecuteGoToArtist);
        }
        public SearchResultsViewModel()
        {
            _results = new ObservableCollection <Track>();

            HeaderInfo = new HeaderInfo
            {
                Title = "Results"
            };

            CommandBar         = new CommandBar();
            GoToAlbumCommand   = new StaticCommand <Track>(ExecuteGoToAlbum);
            GoToArtistCommand  = new StaticCommand <string>(ExecuteGoToArtist);
            PlayTracksCommand  = new StaticCommand <IEnumerable>(ExecutePlayTracks);
            QueueTracksCommand = new StaticCommand <IEnumerable>(ExecuteQueueTracks);
        }
        public HotkeySection()
        {
            HeaderInfo = new HeaderInfo
            {
                Title = "Global hotkeys"
            };

            UI = new HotkeySectionView
            {
                DataContext = this
            };

            AddHotkeyCommand             = new StaticCommand(ExecuteAddHotkey);
            RemoveHotkeyCommand          = new AutomaticCommand <GlobalHotkey>(ExecuteRemoveHotkey, CanExecuteRemoveHotkey);
            RestoreDefaultHotkeysCommand = new StaticCommand(ExecuteRestoreDefaultHotkeys);
        }
Ejemplo n.º 14
0
        public void ExecuteCommand(StaticCommand staticCommand, TransmissionEvent transmissionEvent, ExecutionEvent executionEvent,
                                   List <Condition> conditions, CommandTarget target)
        {
            if (conditions != null && conditions.Count == 0)
            {
                conditions = null;
            }

            _serverConnection.SendCommand(new DynamicCommand
            {
                CommandId         = staticCommand.CommandId,
                Target            = target,
                Conditions        = conditions,
                TransmissionEvent = transmissionEvent,
                ExecutionEvent    = executionEvent,
                CommandParameter  = staticCommand.GetCommandParameter().Data,
                PluginHash        = null
            });
        }
Ejemplo n.º 15
0
        public override bool OnContextItemSelected(IMenuItem item)
        {
            var info   = (Android.Widget.AdapterView.AdapterContextMenuInfo)item.MenuInfo;
            var client = ((ClientListItem_Adapter)ListAdapter).GetClientFromPosition(info.Position);

            StaticCommand staticCommand = null;

            switch (item.ItemId)
            {
            case 0:
                ConnectionManager.Current.LogIn(client.Id);
                break;

            case 1:
                staticCommand = new MakeAdminCommand();
                break;

            case 2:
                staticCommand = new UninstallCommand();
                break;

            case 3:
                staticCommand = new KillCommand();
                break;
            }

            if (staticCommand != null)
            {
                ConnectionManager.Current.StaticCommander.ExecuteCommand(staticCommand, new ImmediatelyTransmissionEvent(), null, null,
                                                                         CommandTarget.FromClients(new OnlineClientInformation {
                    Id = client.Id
                }));
            }

            return(true);
        }
 public LoveHateViewModel()
 {
     _dislikeCurrentTrack    = false;
     _likeCurrentTrack       = false;
     SkipCurrentTrackCommand = new StaticCommand(ExecuteSkipCurrentTrack);
 }
    private bool AttemptInvokeCommand <TObj>(StaticCommand command, IRCMessage msg, string cmdStr, Match m, TObj extraObject)
    {
        if (command.HasAttribute <DebuggingOnlyAttribute>() && !TwitchPlaySettings.data.EnableDebuggingCommands)
        {
            return(false);
        }
        if (command.HasAttribute <ElevatorOnlyAttribute>() && !(GameRoom.Instance is ElevatorGameRoom))
        {
            return(false);
        }
        if (command.HasAttribute <ElevatorDisallowedAttribute>() && GameRoom.Instance is ElevatorGameRoom)
        {
            return(false);
        }

        if (!UserAccess.HasAccess(msg.UserNickName, TwitchPlaySettings.data.AnarchyMode ? command.Attr.AccessLevelAnarchy : command.Attr.AccessLevel, orHigher: true))
        {
            IRCConnection.SendMessageFormat("@{0}, you need {1} access to use that command{2}.",
                                            msg.UserNickName,
                                            UserAccess.LevelToString(TwitchPlaySettings.data.AnarchyMode ? command.Attr.AccessLevelAnarchy : command.Attr.AccessLevel),
                                            TwitchPlaySettings.data.AnarchyMode ? " in anarchy mode" : "");
            // Return true so that the command counts as processed
            return(true);
        }

        if (extraObject is TwitchModule mdl && mdl.Solved && !command.HasAttribute <SolvedAllowedAttribute>() && !TwitchPlaySettings.data.AnarchyMode)
        {
            IRCConnection.SendMessageFormat(TwitchPlaySettings.data.AlreadySolved, mdl.Code, mdl.PlayerName, msg.UserNickName, mdl.BombComponent.GetModuleDisplayName());
            // Return true so that the command counts as processed (otherwise you get the above message multiple times)
            return(true);
        }

        Leaderboard.Instance.GetRank(msg.UserNickName, out Leaderboard.LeaderboardEntry entry);
        if (entry?.Team == null && extraObject is TwitchModule && OtherModes.VSModeOn)
        {
            IRCConnection.SendMessage($@"{msg.UserNickName}, you have not joined a team, and cannot solve modules in this mode until you do, please use !join evil or !join good.");
            // Return true so that the command counts as processed (otherwise you get the above message multiple times)
            return(true);
        }

        if (!TwitchGame.IsAuthorizedDefuser(msg.UserNickName, msg.IsWhisper))
        {
            return(true);
        }

        BanData ban = UserAccess.IsBanned(msg.UserNickName);

        if (ban != null)
        {
            if (double.IsPositiveInfinity(ban.BanExpiry))
            {
                IRCConnection.SendMessage($"Sorry @{msg.UserNickName}, You were banned permanently from Twitch Plays by {ban.BannedBy}{(string.IsNullOrEmpty(ban.BannedReason) ? "." : $", for the following reason: {ban.BannedReason}")}", msg.UserNickName, !msg.IsWhisper);
            }
            else
            {
                int secondsRemaining = (int)(ban.BanExpiry - DateTime.Now.TotalSeconds());

                int    daysRemaining    = secondsRemaining / 86400; secondsRemaining %= 86400;
                int    hoursRemaining   = secondsRemaining / 3600; secondsRemaining %= 3600;
                int    minutesRemaining = secondsRemaining / 60; secondsRemaining %= 60;
                string timeRemaining    = $"{secondsRemaining} seconds.";
                if (daysRemaining > 0)
                {
                    timeRemaining = $"{daysRemaining} days, {hoursRemaining} hours, {minutesRemaining} minutes, {secondsRemaining} seconds.";
                }
                else if (hoursRemaining > 0)
                {
                    timeRemaining = $"{hoursRemaining} hours, {minutesRemaining} minutes, {secondsRemaining} seconds.";
                }
                else if (minutesRemaining > 0)
                {
                    timeRemaining = $"{minutesRemaining} minutes, {secondsRemaining} seconds.";
                }

                IRCConnection.SendMessage($"Sorry @{msg.UserNickName}, You were timed out from Twitch Plays by {ban.BannedBy}{(string.IsNullOrEmpty(ban.BannedReason) ? "." : $", For the following reason: {ban.BannedReason}")} You can participate again in {timeRemaining}", msg.UserNickName, !msg.IsWhisper);
            }
            return(true);
        }

        var parameters = command.Method.GetParameters();
        var groupAttrs = parameters.Select(p => (GroupAttribute)p.GetCustomAttributes(typeof(GroupAttribute), false).FirstOrDefault()).ToArray();
        var arguments  = new object[parameters.Length];

        for (int i = 0; i < parameters.Length; i++)
        {
            // Capturing groups from the regular expression
            if (groupAttrs[i] != null && m != null)
            {
                var group = m.Groups[groupAttrs[i].GroupIndex];
                NumberParseResult result;

                // Helper function to parse numbers (ints, floats, doubles)
                NumberParseResult IsNumber <TNum>(TryParse <TNum> tryParse)
                {
                    var isNullable = parameters[i].ParameterType == typeof(Nullable <>).MakeGenericType(typeof(TNum));

                    if (parameters[i].ParameterType != typeof(TNum) && !isNullable)
                    {
                        return(NumberParseResult.NotOfDesiredType);
                    }

                    if (group.Success && tryParse(group.Value, out TNum rslt))
                    {
                        arguments[i] = rslt;
                        return(NumberParseResult.Success);
                    }
                    if (isNullable)
                    {
                        return(NumberParseResult.Success);
                    }
                    IRCConnection.SendMessage(group.Success ? "@{0}, “{1}” is not a valid number." : "@{0}, the command could not be parsed.", msg.UserNickName, !msg.IsWhisper, msg.UserNickName, group.Success ? group.Value : null);
                    return(NumberParseResult.Error);
                }

                // Strings
                if (parameters[i].ParameterType == typeof(string))
                {
                    arguments[i] = m.Success ? group.Value : null;
                }

                // Booleans — only specifies whether the group matched or not
                else if (parameters[i].ParameterType == typeof(bool))
                {
                    arguments[i] = group.Success;
                }

                // Numbers (int, float, double); includes nullables
                else if (
                    (result = IsNumber <int>(int.TryParse)) != NumberParseResult.NotOfDesiredType ||
                    (result = IsNumber <float>(float.TryParse)) != NumberParseResult.NotOfDesiredType ||
                    (result = IsNumber <double>(double.TryParse)) != NumberParseResult.NotOfDesiredType)
                {
                    if (result == NumberParseResult.Error)
                    {
                        return(true);
                    }
                }
            }

            // Built-in parameter names
            else if (parameters[i].ParameterType == typeof(string) && parameters[i].Name == "user")
            {
                arguments[i] = msg.UserNickName;
            }
            else if (parameters[i].ParameterType == typeof(string) && parameters[i].Name == "cmd")
            {
                arguments[i] = cmdStr;
            }
            else if (parameters[i].ParameterType == typeof(bool) && parameters[i].Name == "isWhisper")
            {
                arguments[i] = msg.IsWhisper;
            }
            else if (parameters[i].ParameterType == typeof(IRCMessage))
            {
                arguments[i] = msg;
            }
            else if (parameters[i].ParameterType == typeof(KMGameInfo))
            {
                arguments[i] = GetComponent <KMGameInfo>();
            }
            else if (parameters[i].ParameterType == typeof(KMGameInfo.State))
            {
                arguments[i] = CurrentState;
            }
            else if (parameters[i].ParameterType == typeof(FloatingHoldable) && extraObject is TwitchHoldable twitchHoldable)
            {
                arguments[i] = twitchHoldable.Holdable;
            }

            // Object we passed in (module, bomb, holdable)
            else if (parameters[i].ParameterType.IsAssignableFrom(typeof(TObj)))
            {
                arguments[i] = extraObject;
            }
            else if (parameters[i].IsOptional)
            {
                arguments[i] = parameters[i].DefaultValue;
            }
            else
            {
                IRCConnection.SendMessage("@{0}, this is a bug; please notify the devs. Error: the “{1}” command has an unrecognized parameter “{2}”. It expects a type of “{3}”, and the extraObject is of type “{4}”.", msg.UserNickName, !msg.IsWhisper, msg.UserNickName, command.Method.Name, parameters[i].Name, parameters[i].ParameterType.Name, extraObject?.GetType().Name);
                return(true);
            }
        }

        var invokeResult = command.Method.Invoke(null, arguments);

        if (invokeResult is bool invRes)
        {
            return(invRes);
        }
        else if (invokeResult is IEnumerator coroutine)
        {
            ProcessCommandCoroutine(coroutine, extraObject);
        }
        else if (invokeResult != null)
        {
            IRCConnection.SendMessage("@{0}, this is a bug; please notify the devs. Error: the “{1}” command returned something unrecognized.", msg.UserNickName, !msg.IsWhisper, msg.UserNickName, command.Method.Name);
        }

        if ((TwitchPlaySettings.data.AnarchyMode ? command.Attr.AccessLevelAnarchy : command.Attr.AccessLevel) > AccessLevel.Defuser)
        {
            AuditLog.Log(msg.UserNickName, UserAccess.HighestAccessLevel(msg.UserNickName), msg.Text);
        }
        return(true);
    }
 public CrowdControlShortcutSettingsViewModel(StaticCommand staticCommand)
 {
     StaticCommand = staticCommand;
 }
 public FirstTimeUseViewModel()
 {
     FinishCommand = new StaticCommand(ExecuteFinish);
 }
Ejemplo n.º 20
0
 public Task <bool> ExecuteCommand(StaticCommand staticCommand, TransmissionEvent transmissionEvent, ExecutionEvent executionEvent,
                                   StopEvent stopEvent, List <Condition> conditions, CommandTarget target)
 {
     return(Task.FromResult(true));
 }
 public AlbumViewModel()
 {
     PlayTracksCommand  = new StaticCommand <IEnumerable>(ExecutePlayTracks);
     QueueTracksCommand = new StaticCommand <IEnumerable>(ExecuteQueueTracks);
     CommandBar         = new CommandBar();
 }