Esempio n. 1
0
 /// <summary>
 /// Attempt to execute a specified Task, catching any errors that occur.
 /// </summary>
 public static async Task TryExecute(ISocketMessageChannel channel, Task task)
 {
     try
     {
         await Task.Run(() => task);
     }
     catch (Exception exception)
     {
         await channel.CatchAsync(exception);
     }
 }
Esempio n. 2
0
        public async Task RunBlackJackAsync(ArcadeUser invoker, ISocketMessageChannel channel, Wager wager)
        {
            if (!invoker.CanGamble)
            {
                return;
            }

            if (wager.Value < 0)
            {
                await channel.SendMessageAsync($"> 👁️ You can't specify a **negative** value.\n> *\"I know what you were trying to do.\"*");

                return;
            }

            if (wager.Value == 0)
            {
                await channel.SendMessageAsync($"> ⚠️ You need to specify a positive amount of **Chips** to bet.");

                return;
            }

            if (wager.Value > invoker.ChipBalance)
            {
                await channel.SendMessageAsync($"> ⚠️ You don't have enough **Chips** to bet with.");

                return;
            }

            invoker.CanGamble = false;
            var session = new BlackJackSession(invoker, channel, wager.Value);

            try
            {
                var options = new SessionOptions
                {
                    ResetTimeoutOnAttempt = true,
                    Timeout = TimeSpan.FromSeconds(15),
                    Session = session
                };

                bool Filter(SocketMessage message, int index)
                {
                    return(message.Author.Id == invoker.Id && message.Channel.Id == channel.Id);
                }

                await _collector.MatchAsync(Filter, options);
            }
            catch (Exception e)
            {
                await channel.CatchAsync(e);
            }

            invoker.CanGamble = true;
        }