コード例 #1
0
ファイル: FoldCommand.cs プロジェクト: telmengedar/StreamRC
        public override void ExecuteCommand(IChatChannel channel, StreamCommand command)
        {
            long       userid = playermodule.GetPlayer(command.Service, command.User).UserID;
            HoldemGame game   = casino.GetGame(userid);

            if (game == null)
            {
                SendMessage(channel, command.User, "You have no active holdem game. Use !holdem to start a new game.");
                return;
            }

            casino.RemoveGame(userid);

            RPGMessageBuilder message          = messagemodule.Create().User(userid).Text(" folds the hand. ");
            HandEvaluation    dealerevaluation = HandEvaluator.Evaluate(game.Board + game.DealerHand);
            HandEvaluation    playerevaluation = HandEvaluator.Evaluate(game.Board + game.PlayerHand);

            if (dealerevaluation < playerevaluation || dealerevaluation.Rank < HandRank.Pair || (dealerevaluation.Rank == HandRank.Pair && dealerevaluation.HighCard < CardRank.Four))
            {
                message.ShopKeeper().Text(" laughs and shows ");
                foreach (Card card in game.DealerHand)
                {
                    message.Image(cardimages.GetCardUrl(card), $"{card} ");
                }
                message.Text("while grabbing ").Gold(game.Pot);
            }
            else
            {
                message.ShopKeeper().Text(" gladly rakes in ").Gold(game.Pot);
            }
            message.Send();
        }
コード例 #2
0
        public override void ExecuteCommand(IChatChannel channel, StreamCommand command)
        {
            if (command.Arguments.Length != 1)
            {
                throw new StreamCommandException("Invalid command syntax");
            }

            string pollname = command.Arguments[0];

            Poll poll = module.GetPoll(pollname);

            if (poll == null)
            {
                throw new StreamCommandException($"There is no active poll named '{pollname}'");
            }

            PollOption[]  options = module.GetOptions(pollname);
            StringBuilder message = new StringBuilder(poll.Description).Append(": ");

            if (options.Length == 0)
            {
                message.Append("This is an unrestricted poll, so please vote for 'penis' when you're out of ideas");
            }
            else
            {
                message.Append(string.Join(", ", options.Select(o => $"{o.Key} - {o.Description}")));
                message.Append(". Usually there is more info available by typing !info <option>");
            }

            SendMessage(channel, command.User, message.ToString());
        }
コード例 #3
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,name,response,Mode,AutoInverval,streamID")] StreamCommand streamCommand)
        {
            if (id != streamCommand.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(streamCommand);

                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StreamCommandExists(streamCommand.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(streamCommand));
        }
コード例 #4
0
        void HeuristicVote(IChatChannel channel, StreamCommand command)
        {
            Logger.Info(this, $"Executing heuristic vote for '{command}'");


            PollOption[] options = module.FindOptions(command.Arguments);

            string optionname = string.Join(" ", command.Arguments);

            if (options.Length > 1)
            {
                throw new StreamCommandException($"Sadly there is more than one poll which contains an option '{optionname}' so you need to specify in which poll you want to vote ({string.Join(", ", options.Select(o => o.Poll))}).", false);
            }

            if (options.Length == 0)
            {
                Poll poll = module.GetPoll(optionname);
                if (poll == null)
                {
                    throw new StreamCommandException($"There is no poll and no option named '{optionname}' so i have no idea what you want to vote for.", false);
                }

                options = module.GetOptions(poll.Name);
                throw new StreamCommandException($"You need to specify the option to vote for. The following options are available. {string.Join(", ", options.Select(o => $"'{o.Key}' for '{o.Description}'"))}", false);
            }

            module.ExecuteVote(options[0].Poll, command.User, options[0].Key);
            SendMessage(channel, command.User, $"You voted successfully for '{options[0].Description}' in poll '{options[0].Poll}'.");
        }
コード例 #5
0
        public override void ExecuteCommand(IChatChannel channel, StreamCommand command)
        {
            if (command.Arguments.Length != 2)
            {
                HeuristicVote(channel, command);
                return;
            }

            string poll = command.Arguments[0].ToLower();

            if (!module.ExistsPoll(poll))
            {
                HeuristicVote(channel, command);
                return;
            }

            string vote = command.Arguments[1].ToLower();

            if (module.HasOptions(poll) && !module.ExistsOption(poll, vote))
            {
                HeuristicVote(channel, command);
                return;
            }

            module.ExecuteVote(poll, command.User, vote);

            SendMessage(channel, command.User, $"You voted successfully for {vote} in poll {poll}.");
        }
コード例 #6
0
        /// <summary>
        /// Creates a new <see cref="MainViewModel"/>.
        /// </summary>
        public MainViewModel(RuntimeConfiguration configuration)
        {
            Configuration = configuration;
            Configuration.ConsoleWriter = new SourceStream <string>();
            ConsoleList = new ObservableCollection <string>();
            Configuration.ConsoleWriter.BindResult(t => Dispatchers.RunOnUIThreadAsync(() => ConsoleList.Add(t)));

            FileList = new ObservableCollection <string>();

            var open = new StreamCommand(OpenCommand);

            open.BindResult(o => Dispatchers.RunOnUIThreadAsync(() => OpenFolder()));

            var select = new StreamCommand <string>(SelectCommand);

            select.BindResult(o => Dispatchers.RunOnUIThreadAsync(() => LoadFile(o)));

            var start = new StreamCommand(StartCommand);

            start.BindResult(b => Task.Run(StartProcess));

            Commands = new List <ICommand>()
            {
                open,
                select,
                start
            };
        }
コード例 #7
0
        public override void ExecuteCommand(IChatChannel channel, StreamCommand command)
        {
            GameRequest[] gamerequests = module.GetRequests();
            if (gamerequests.Length == 0)
            {
                SendMessage(channel, command.User, "No requests currently in queue.");
                return;
            }

            SendMessage(channel, command.User, $"Game Requests: {string.Join(", ", gamerequests.Select(r => $"{r.Game} ({r.Platform}{(string.IsNullOrEmpty(r.Conditions) ? "" : ", " + r.Conditions)})"))}");
        }
コード例 #8
0
        public async Task <IActionResult> Create([Bind("ID,name,response,Mode,AutoInverval,streamID")] StreamCommand streamCommand)
        {
            if (ModelState.IsValid)
            {
                _context.Add(streamCommand);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(streamCommand));
        }
コード例 #9
0
        public override void ExecuteCommand(IChatChannel channel, StreamCommand command)
        {
            PollVote[] votes;
            if (command.Arguments.Length == 0 || (command.Arguments.Length == 1 && command.Arguments[0] == "all"))
            {
                votes = module.GetUserVotes(command.User).ToArray();
                if (votes.Length == 0)
                {
                    throw new StreamCommandException("You haven't voted for anything, so revoking a vote doesn't make any sense.", false);
                }

                if (votes.Length > 1)
                {
                    if (command.Arguments.Length == 1 && command.Arguments[0] == "all")
                    {
                        foreach (PollVote vote in votes)
                        {
                            module.ExecuteRevoke(vote.Poll, command.User);
                        }
                        SendMessage(channel, command.User, $"You revoked your votes in polls '{string.Join(", ", votes.Select(v => v.Poll))}'");
                        return;
                    }
                    throw new StreamCommandException($"You have voted in more than one poll. Type !revoke all to remove all your votes. You voted in the following polls: {string.Join(", ", votes.Select(v => v.Poll))}");
                }

                module.ExecuteRevoke(votes[0].Poll, command.User);
                SendMessage(channel, command.User, $"You revoked your vote in poll '{votes[0].Poll}'");
                return;
            }

            string poll = command.Arguments[0].ToLower();

            if (module.RevokeVote(command.User, poll))
            {
                SendMessage(channel, command.User, $"You revoked your vote in poll '{poll}'");
                return;
            }

            PollOption[] options = module.FindOptions(command.Arguments);
            string[]     keys    = options.Select(o => o.Key).ToArray();
            votes = module.GetUserVotes(command.User, keys).ToArray();

            if (votes.Length == 0)
            {
                SendMessage(channel, command.User, "No votes match your arguments so no clue what you want to revoke.");
                return;
            }

            foreach (PollVote vote in votes)
            {
                module.ExecuteRevoke(vote.Poll, command.User);
            }
            SendMessage(channel, command.User, $"You revoked your votes in polls '{string.Join(", ", votes.Select(v => v.Poll))}'");
        }
コード例 #10
0
        public override void ExecuteCommand(IChatChannel channel, StreamCommand command)
        {
            BlackJackGame game = blackjack.GetGame(command.Service, command.User);

            if (game == null)
            {
                SendMessage(channel, command.User, "There is active black jack game. Start another one with !bj <bet>");
                return;
            }

            game.PlayerBoards[game.ActiveBoard].Board += game.Stack.Pop();

            int value = logic.Evaluate(game.PlayerBoards[game.ActiveBoard].Board);

            RPGMessageBuilder message = messages.Create();

            message.User(game.PlayerID).Text(" has ");
            foreach (Card card in game.PlayerBoards[game.ActiveBoard].Board)
            {
                message.Image(images.GetCardUrl(card), $"{card} ");
            }
            message.Text(". ");

            if (value > 21)
            {
                message.Text("Bust!");
                game.PlayerBoards.RemoveAt(game.ActiveBoard);
            }
            else
            {
                message.Text($"({value}). ");
                if (value == 21)
                {
                    ++game.ActiveBoard;
                }
            }


            if (game.PlayerBoards.Count == 0)
            {
                message.Text(" All hands are busted.").ShopKeeper().Text(" laughs at you.");
                blackjack.RemoveGame(game.PlayerID);
            }
            else
            {
                if (game.ActiveBoard >= game.PlayerBoards.Count)
                {
                    message.Text(" All hands have been played.");
                    logic.PlayoutDealer(game, message, playermodule, images);
                    blackjack.RemoveGame(game.PlayerID);
                }
            }
            message.Send();
        }
コード例 #11
0
        public override void ExecuteCommand(IChatChannel channel, StreamCommand command)
        {
            if (command.Arguments.Length != 1)
            {
                throw new StreamCommandException("Invalid command syntax. Expected syntax: !info <item>");
            }

            string key  = command.Arguments[0];
            Info   info = module.GetInfo(key);

            SendMessage(channel, command.User, info == null ? $"There is no info for '{key}'" : info.Text);
        }
コード例 #12
0
        public override void ExecuteCommand(IChatChannel channel, StreamCommand command)
        {
            PollVote[] votes = module.GetUserVotes(command.User, command.Arguments.Length > 0 ? command.Arguments[0] : null).ToArray();

            if (votes.Length == 0)
            {
                SendMessage(channel, command.User, $"You didn't vote for anything{(command.Arguments.Length > 0 ? $" in poll {command.Arguments[0]}" : "")}");
            }
            else
            {
                SendMessage(channel, command.User, $"You voted for: {string.Join(", ", votes.Select(v => $"'{v.Vote}' in poll '{v.Poll}'"))}");
            }
        }
コード例 #13
0
        /// <summary>
        /// executes a <see cref="StreamCommand"/>
        /// </summary>
        /// <param name="channel">channel from which command was received</param>
        /// <param name="command">command to execute</param>
        public override void ExecuteCommand(IChatChannel channel, StreamCommand command)
        {
            TimeSpan uptime = DateTime.Now - start;

            if (uptime.Days > 0)
            {
                channel.SendMessage($"This stream is going on for {uptime.Days} days, {uptime.Hours} hours and {uptime.Minutes} minutes now");
            }
            else
            {
                channel.SendMessage($"This stream is going on for {uptime.Hours} hours and {uptime.Minutes} minutes now");
            }
        }
コード例 #14
0
        public override void ExecuteCommand(IChatChannel channel, StreamCommand command)
        {
            Player player = module.GetExistingPlayer(command.Service, command.User);

            if (player == null)
            {
                SendMessage(channel, command.User, "No character data found for your user.");
                return;
            }

            PlayerAscension ascension = module.GetPlayerAscension(player.UserID);

            SendMessage(channel, command.User, $"You're level {player.Level} with {player.Experience.ToString("F0")}/{ascension?.NextLevel.ToString("F0")} experience. HP {player.CurrentHP}/{player.MaximumHP}, MP {player.CurrentMP}/{player.MaximumMP}. Strength {player.Strength}, Dexterity {player.Dexterity}, Fitness {player.Fitness}, Luck {player.Luck}. {player.Gold} Gold");
        }
コード例 #15
0
        public override void ExecuteCommand(IChatChannel channel, StreamCommand command)
        {
            string     collectionname = command.Arguments[0];
            Collection collection     = module.GetCollection(collectionname);

            if (collection == null)
            {
                throw new StreamCommandException($"There is no collection named '{collectionname}'");
            }

            string itemsperuser = collection.ItemsPerUser > 0 ? $"max {collection.ItemsPerUser} per user." : "unlimited items per user";

            SendMessage(channel, command.User, $"Collection {collectionname}: {collection.Description} - {itemsperuser}");
        }
コード例 #16
0
 public StreamCommandEditData(StreamCommand command, IEnumerable <Stream> Streamlist)
 {
     Name         = command.name;
     Response     = command.response;
     Mode         = command.Mode.ToString();
     AutoInterval = command.AutoInverval;
     StreamName   = command.stream.StreamName;
     StreamID     = command.stream.ID;
     Streams      = new List <StreamData>();
     foreach (Stream stream in Streamlist)
     {
         Streams.Add(new StreamData(stream.StreamName, stream.ID));
     }
 }
コード例 #17
0
        public override void ExecuteCommand(IChatChannel channel, StreamCommand command)
        {
            string message = string.Join(", ", module.GetCollectionNames());

            if (message.Length == 0)
            {
                message = "There are no open collections";
            }
            else
            {
                message = "Open collections: " + message;
            }

            SendMessage(channel, command.User, message);
        }
コード例 #18
0
        public void TestStartStream(bool passCreds, bool kitchenSink)
        {
            var           uuid             = "63f61863-4a51-4f6b-86e1-46edebcf9356";
            var           expectedUri      = $"{ApiUrl}/v1/calls/{uuid}/stream";
            var           expectedResponse = @"{
                  ""message"": ""Stream started"",
                  ""uuid"": ""63f61863-4a51-4f6b-86e1-46edebcf9356""
                }";
            string        expectedRequestContent;
            StreamCommand command;

            if (kitchenSink)
            {
                expectedRequestContent = @"{""stream_url"":[""https://example.com/waiting.mp3""],""loop"":0,""level"":""0.4""}";
                command = new StreamCommand
                {
                    StreamUrl = new[] { "https://example.com/waiting.mp3" },
                    Loop      = 0,
                    Level     = "0.4"
                };
            }
            else
            {
                expectedRequestContent = @"{""stream_url"":[""https://example.com/waiting.mp3""]}";
                command = new StreamCommand
                {
                    StreamUrl = new[] { "https://example.com/waiting.mp3" }
                };
            }
            Setup(expectedUri, expectedResponse, expectedRequestContent);

            var creds  = Request.Credentials.FromAppIdAndPrivateKey(AppId, PrivateKey);
            var client = new NexmoClient(creds);

            CallCommandResponse response;

            if (passCreds)
            {
                response = client.VoiceClient.StartStream(uuid, command, creds);
            }
            else
            {
                response = client.VoiceClient.StartStream(uuid, command);
            }
            Assert.Equal("Stream started", response.Message);
            Assert.Equal(uuid, response.Uuid);
        }
コード例 #19
0
        /// <inheritdoc />
        public override void ExecuteCommand(IChatChannel channel, StreamCommand command)
        {
            if (!string.IsNullOrEmpty(customcommand.Permissions))
            {
                foreach (string permission in customcommand.Permissions.Split(','))
                {
                    if (!context.GetModule <UserPermissionModule>().HasPermission(command.Service, command.User, permission))
                    {
                        SendMessage(channel, command.User, $"Sorry, you don't have the permissions '{permission}' needed to execute that shit.");
                        return;
                    }
                }
            }

            context.ExecuteCommand(string.Format(customcommand.SystemCommand, command.Arguments.Cast <object>().ToArray()).Replace("$Service", command.Service));
            SendMessage(channel, command.User, "Command executed");
        }
コード例 #20
0
        public static int decodeStreamCommand(byte[] buffer, int offset, int length, StreamCommand c)
        {
            if (length < STREAM_CMD_MESSAGE_LENGTH)
            {
                return(0);
            }
            if ((buffer[offset + 0] == '!') && (buffer[offset + 1] == MSGID_STREAM_CMD))
            {
                if (!verifyChecksum(buffer, offset, STREAM_CMD_CHECKSUM_INDEX))
                {
                    return(0);
                }

                c.stream_type = buffer[offset + STREAM_CMD_STREAM_TYPE_INDEX];
                return(STREAM_CMD_MESSAGE_LENGTH);
            }
            return(0);
        }
コード例 #21
0
        public Task ProcessStreamItem(StreamCommand command)
        {
            switch (command.Command)
            {
            case StreamCommandType.StartSnapshot:
                // TODO
                break;

            case StreamCommandType.EndSnapshot:
                // TODO
                break;

            case StreamCommandType.Clear:
                // TODO
                break;
            }
            return(Task.CompletedTask);
        }
コード例 #22
0
        public void Execute()
        {
            var VONAGE_APPLICATION_ID   = Environment.GetEnvironmentVariable("VONAGE_APPLICATION_ID") ?? "VONAGE_APPLICATION_ID";
            var VONAGE_PRIVATE_KEY_PATH = Environment.GetEnvironmentVariable("VONAGE_PRIVATE_KEY_PATH") ?? "VONAGE_PRIVATE_KEY_PATH";
            var UUID = Environment.GetEnvironmentVariable("UUID") ?? "UUID";
            var URL  = Environment.GetEnvironmentVariable("URL") ?? "URL";

            var credentials = Credentials.FromAppIdAndPrivateKeyPath(VONAGE_APPLICATION_ID, VONAGE_PRIVATE_KEY_PATH);
            var client      = new VonageClient(credentials);

            var command = new StreamCommand()
            {
                StreamUrl = new[] { URL }
            };

            var response = client.VoiceClient.StartStream(UUID, command);

            Console.WriteLine($"Play Stream complete, message: {response.Message}");
        }
コード例 #23
0
        void IStreamCommandHandler.ExecuteCommand(IChatChannel channel, StreamCommand command)
        {
            CommandAlias alias = context.Database.LoadEntities <CommandAlias>().Where(a => a.Alias == command.Command).Execute().FirstOrDefault();

            if (alias == null)
            {
                throw new StreamCommandException($"{command.Command} not handled by this module");
            }

            string[] split = alias.Command.Split(' ');
            context.GetModule <StreamModule>().ExecuteCommand(channel, new StreamCommand {
                Service     = command.Service,
                Channel     = command.Channel,
                User        = command.User,
                Command     = split[0],
                Arguments   = split.Skip(1).ToArray(),
                IsWhispered = command.IsWhispered
            });
        }
コード例 #24
0
 public async Task <bool> CreateCommand(string Name, string Response, StreamCommandMode Mode, int StreamID)
 {
     try
     {
         var command = new StreamCommand();
         command.name     = Name;
         command.response = Response;
         command.Mode     = Mode;
         command.streamID = StreamID;
         _context.StreamCommand.Add(command);
         _context.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
     }
     return(false);
 }
コード例 #25
0
        /// <inheritdoc />
        public override void ExecuteCommand(IChatChannel channel, StreamCommand command)
        {
            if (!permissionmodule.HasPermission(command.Service, command.User, "command:create"))
            {
                SendMessage(channel, command.User, "You don't have the required permissions to create custom commands.");
                return;
            }

            if (command.Arguments.Length < 2)
            {
                SendMessage(channel, command.User, "Syntax: command <name> <command> <permissions>");
                return;
            }

            CustomCommand customcommand = commandmodule.CreateCommand(command.Arguments[0],
                                                                      command.Arguments[1],
                                                                      command.Arguments.Length > 2 ? command.Arguments[2] : "");

            commandmodule.AddCommand(customcommand);
        }
コード例 #26
0
        public void ExecuteCommand(IChatChannel channel, StreamCommand command)
        {
            string helpcommand = "help";

            if (command.Arguments.Length > 0)
            {
                helpcommand = command.Arguments[0];
            }

            IStreamCommandHandler handler = manager[helpcommand];

            if (handler == null)
            {
                channel.SendMessage($"@{command.User}: Unknown command '{helpcommand}', try !commands for a list of commands.");
            }
            else
            {
                handler.ProvideHelp(channel, command.User);
            }
        }
コード例 #27
0
        public override void ExecuteCommand(IChatChannel channel, StreamCommand command)
        {
            BlackJackGame game = blackjack.GetGame(command.Service, command.User);

            if (game == null)
            {
                SendMessage(channel, command.User, "There is no active black jack game. Start another one with !bj <bet>");
                return;
            }

            ++game.ActiveBoard;

            RPGMessageBuilder message = messages.Create();

            message.User(game.PlayerID).Text(" is satisfied.");
            if (game.ActiveBoard >= game.PlayerBoards.Count)
            {
                message.Text(" All hands have been played.");
                logic.PlayoutDealer(game, message, playermodule, images);
                blackjack.RemoveGame(game.PlayerID);
            }
            else
            {
                if (game.PlayerBoards[game.ActiveBoard].Board.Count == 1)
                {
                    game.PlayerBoards[game.ActiveBoard].Board += game.Stack.Pop();
                }

                message.Text(" Next hand is ");
                foreach (Card card in game.PlayerBoards[game.ActiveBoard].Board)
                {
                    message.Image(images.GetCardUrl(card), $"{card} ");
                }

                int value = logic.Evaluate(game.PlayerBoards[game.ActiveBoard].Board);
                message.Text($"({value}). ");
                logic.CheckSplit(game.PlayerBoards[game.ActiveBoard].Board, message);
            }
            message.Send();
        }
コード例 #28
0
        public override void ExecuteCommand(IChatChannel channel, StreamCommand command)
        {
            string pollkey;

            if (command.Arguments.Length == 0)
            {
                Logger.Info(this, $"Starting heuristic poll result estimation for '{command.User}'");
                ActivePoll leadingpoll = module.GetMostActivePoll();
                if (leadingpoll == null)
                {
                    SendMessage(channel, command.User, "Since no one voted for anything i can't show you any poll.");
                    return;
                }

                SendMessage(channel, command.User, $"You seem to be too lazy to tell me which poll you want to know something about. I just guess you want to see poll '{leadingpoll.Name}' since it is the most active poll.");
                pollkey = leadingpoll.Name;
            }
            else
            {
                pollkey = command.Arguments[0];
            }

            Poll poll = module.GetPoll(pollkey);

            if (poll == null)
            {
                SendMessage(channel, command.User, $"There is no poll named '{pollkey}'");
                return;
            }

            PollDiagramData data = new PollDiagramData(module.GetWeightedVotes(pollkey));

            string message = $"Results for {pollkey}: {string.Join(", ", data.GetItems(100).Where(r => r.Count > 0).Select(r => $"{r.Item} [{r.Count}]"))}";

            SendMessage(channel, command.User, message);
        }
コード例 #29
0
 /// <summary>
 /// executes a <see cref="StreamCommand"/>
 /// </summary>
 /// <param name="channel">channel from which command was received</param>
 /// <param name="command">command to execute</param>
 public abstract void ExecuteCommand(IChatChannel channel, StreamCommand command);
コード例 #30
0
        public override void ExecuteCommand(IChatChannel channel, StreamCommand command) {
            VideoPokerGame game = pokermodule.GetGame(command.Service, command.User);
            long userid = playermodule.GetPlayer(command.Service, command.User).UserID;
            HandEvaluation evaluation;

            if (game == null) {
                if(command.Arguments.Length == 0) {
                    SendMessage(channel, command.User, "You have to specify a bet amount");
                    return;
                }

                int bet;
                int.TryParse(command.Arguments[0], out bet);
                if(bet <= 0) {
                    SendMessage(channel, command.User, $"{command.Arguments[0]} is no valid bet");
                    return;
                }

                if (bet > playermodule.GetPlayerGold(userid)) {
                    SendMessage(channel, command.User, "You can't bet more than you have.");
                    return;
                }

                int maxbet = playermodule.GetLevel(userid) * 10;
                if (bet > maxbet) {
                    SendMessage(channel, command.User, $"On your level you're only allowed to bet up to {maxbet} gold.");
                    return;
                }

                game = pokermodule.CreateGame(command.Service, command.User, bet);
                game.IsMaxBet = bet == maxbet;
                game.Deck.Shuffle();
                for(int i = 0; i < 5; ++i)
                    game.Hand += game.Deck.Pop();

                RPGMessageBuilder message = messagemodule.Create();
                message.User(userid).Text(" has ");
                foreach(Card card in game.Hand)
                    message.Image(imagemodule.GetCardUrl(card), $"{card} ");

                evaluation = HandEvaluator.Evaluate(game.Hand);
                message.Text($"({evaluation})").Send();
            }
            else {
                RPGMessageBuilder message = messagemodule.Create();

                if(command.Arguments.Length > 0) {
                    int redraw = 0;
                    foreach(string argument in command.Arguments) {
                        if(argument.All(c => char.IsDigit(c))) {
                            int index = int.Parse(argument);
                            if(index < 1 || index > 5) {
                                SendMessage(channel, command.User, $"{index} is not a valid slot to redraw");
                                return;
                            }
                            redraw |= 1 << (index - 1);
                        }
                        else if(argument.ToLower() == "all") {
                            redraw |= 31;
                        }
                        else {
                            int index = game.Hand.IndexOf(c => c.ToString().ToLower() == argument.ToLower());
                            if(index == -1) {
                                SendMessage(channel, command.User, $"{argument} points not to a card in your hand");
                                return;
                            }
                            redraw |= 1 << index;
                        }
                    }

                    int cards = 0;
                    for(int i = 0; i < 5; ++i) {
                        if((redraw & (1 << i)) != 0) {
                            game.Hand = game.Hand.ChangeCard(i, game.Deck.Pop());
                            ++cards;
                        }
                    }
                    message.User(userid).Text($" is redrawing {cards} cards. ");
                    foreach (Card card in game.Hand)
                        message.Image(imagemodule.GetCardUrl(card), $"{card} ");

                    evaluation = HandEvaluator.Evaluate(game.Hand);
                    message.Text($"({evaluation}).");
                }
                else {
                    evaluation = HandEvaluator.Evaluate(game.Hand);
                    message.User(userid).Text(" is satisfied with the hand.");
                }

                int multiplicator = GetMultiplicator(evaluation, game.IsMaxBet);
                if(multiplicator == 0)
                    message.Text(" ").ShopKeeper().Text(" laughs about that shitty hand.");
                else {
                    int payout = game.Bet * multiplicator;
                    playermodule.UpdateGold(userid, payout);
                    message.Text(" Payout is ").Gold(payout);
                }

                message.Send();
                pokermodule.RemoveGame(command.Service, command.User);
            }
        }
コード例 #31
0
ファイル: IMUProtocol.cs プロジェクト: chopshop-166/WPILib
        public static int decodeStreamCommand(byte[] buffer, int offset, int length, StreamCommand c)
        {
            if (length < STREAM_CMD_MESSAGE_LENGTH)
            {
                return 0;
            }
            if ((buffer[offset + 0] == '!') && (buffer[offset + 1] == MSGID_STREAM_CMD))
            {
                if (!verifyChecksum(buffer, offset, STREAM_CMD_CHECKSUM_INDEX))
                {
                    return 0;
                }

                c.stream_type = buffer[offset + STREAM_CMD_STREAM_TYPE_INDEX];
                return STREAM_CMD_MESSAGE_LENGTH;
            }
            return 0;
        }