private void OnHelpCommand(IChatService chatService, GiveawayGameCommand cmd, StateMachine <GiveawayGameState, GiveawayGameTrigger> .Transition transition)
        {
            // Cheer 731 devlead 28/3/19

            if (!(cmd.ChatUser.IsModerator || cmd.ChatUser.IsBroadcaster))
            {
                chatService.WhisperMessage(cmd.ChatUser.Username, "You don't have access to this command");
                return;
            }

            switch (_machine.State)
            {
            case GiveawayGameState.Idle:
                chatService.WhisperMessage(cmd.ChatUser.Username, "You can open the raffle for entries by using the open verb like this:  !giveaway open.  Hide the animation, ending the game with !giveaway end");
                break;

            case GiveawayGameState.Open:
                if (cmd.ChatUser.IsModerator)
                {
                    chatService.WhisperMessage(cmd.ChatUser.Username, "The broadcaster can start the raffle by using the start verb like this: !giveaway start, moderators and the broadcaster can exclude chatters from the giveaway with !giveaway exclude viewername, you can clear the raffle entrants with !giveaway clear, you can end the raffle without starting using !giveaway end");
                }
                else
                {
                    chatService.WhisperMessage(cmd.ChatUser.Username, "You can start the raffle by using the start verb like this: !giveaway start, you can clear the raffle entrants with !giveaway clear, you can end the raffle without starting using !giveaway end");
                }
                break;

            case GiveawayGameState.Running:
                chatService.WhisperMessage(cmd.ChatUser.Username, "I will announce a winner shortly");
                break;
            }
        }
        public void Open(IChatService twitch, GiveawayGameCommand cmd)
        {
            if (State == GiveawayGameState.Reward || State == GiveawayGameState.Running)
            {
                twitch.WhisperMessage(cmd.ChatUser.Username, "Game is not ready to be re-opened.  Wait for the winner to be announced before executing !giveaway open");
                return;
            }

            _machine.Fire(_setOpenTrigger, twitch, cmd);
        }
Esempio n. 3
0
        private GiveawayGameState WhenOpenFromIdle(IChatService twitch, GiveawayGameCommand cmd)
        {
            twitch.BroadcastMessageOnChannel("Now taking entries for the raffle...  please enter any text in chat to participate");

            if (_entrants.Any())
            {
                using (var client = _ClientFactory.CreateClient("giveaway")) {
                    client.PutAsJsonAsync(_Config.RelayUrl + "?id=1", _entrants.ToArray()).GetAwaiter().GetResult();
                }
            }

            return(GiveawayGameState.Open);
        }
Esempio n. 4
0
        public GivenOpenState()
        {
            TwitchChat = new Mock <IChatService>();

            _MockClientFactory = _MockHandler.CreateClientFactory();

            _Game = new CORE.GiveawayGame(_MockClientFactory, Options.Create(Config));
            _Cmd  = new GiveawayGameCommand(_Game, new Mock <IConfiguration>().Object)
            {
                ChatUser = new ChatUser {
                    IsBroadcaster = true
                }
            };
        }
        public GivenOpenState()
        {
            TwitchChat = new Mock <IChatService>();

            _MockClientFactory = new Mock <IHttpClientFactory>();
            _MockClient        = new Mock <HttpClient>();
            _MockClientFactory.Setup(_ => _.CreateClient(It.IsAny <string>())).Returns(_MockClient.Object);

            _Game = new CORE.GiveawayGame(_MockClientFactory.Object, Options.Create(Config));
            _Cmd  = new GiveawayGameCommand(_Game, new Mock <IConfiguration>().Object)
            {
                ChatUser = new ChatUser {
                    IsBroadcaster = true
                }
            };
        }
        public void Exclude(IChatService twitch, GiveawayGameCommand cmd)
        {
            // Cheer 100 nicklarsen 05/4/19
            // Cheer 300 Mike_from_PlayrGG 05/4/19

            if (State != GiveawayGameState.Open)
            {
                return;
            }

            if (!(cmd.ChatUser.IsBroadcaster || cmd.ChatUser.IsModerator))
            {
                return;
            }

            // NOTE: May want to persist this group to disk

            _entrants.Remove(cmd.Arguments.Skip(1).First());
            _ExcludeChatters.Add(cmd.Arguments.Skip(1).First());
        }
        public void Start(IChatService twitch, GiveawayGameCommand cmd, int countdownSeconds = 5)
        {
            if (State == GiveawayGameState.Reward || State == GiveawayGameState.Running)
            {
                twitch.WhisperMessage(cmd.ChatUser.Username, "Game is not ready to be re-started.  Wait for the winner to be announced before executing !giveaway start");
                return;
            }

            if (EnableCountdownTimer)
            {
                for (var i = countdownSeconds; i > 0; i--)
                {
                    Task.Delay(1000).GetAwaiter().GetResult();
                    twitch.BroadcastMessageOnChannel($"Giveaway starting in {i} seconds...");
                }
            }


            _machine.FireAsync(_setStartTrigger, twitch, cmd);
        }
 public void Help(IChatService twitch, GiveawayGameCommand cmd)
 {
     _machine.Fire(_setHelpTrigger, twitch, cmd);
 }
 private GiveawayGameState WhenStarting(IChatService twitch, GiveawayGameCommand cmd)
 {
     _Twitch = twitch;
     return(GiveawayGameState.Running);
 }
Esempio n. 10
0
 private bool CanRestart(IChatService twitch, GiveawayGameCommand cmd)
 {
     return(cmd.ChatUser.IsBroadcaster && _entrants.Any());
 }
Esempio n. 11
0
 private bool CanStart(IChatService twitch, GiveawayGameCommand cmd)
 {
     return(cmd.ChatUser.IsBroadcaster);
 }
Esempio n. 12
0
 private bool CanOpen(IChatService twitch, GiveawayGameCommand cmd)
 {
     return(cmd.ChatUser.IsBroadcaster || cmd.ChatUser.IsModerator);
 }