예제 #1
0
        public async Task HandleCommand(SocketMessage parameterMessage)
        {
            var message = parameterMessage as SocketUserMessage;

            if (message == null)
            {
                return;
            }
            if (message.Author.IsBot)
            {
                return;
            }
            int argPos = 0;

            if (!(message.HasMentionPrefix(client.CurrentUser, ref argPos) || message.HasCharPrefix(';', ref argPos)))
            {
                return;
            }


            var a = await _udb.FindUser(message.Author.Id);

            if (a == null)
            {
                await _udb.CreateNewUser(message.Author);
            }

            var context = new CommandContext(client, message);
            var result  = await commands.ExecuteAsync(context, argPos, _provider);

            if (!result.IsSuccess)
            {
                if (result.ErrorReason.ToLower() == "unknown command.")
                {
                    return;
                }
                else
                {
                    await message.Channel.SendMessageAsync($"**Error:** {result.ErrorReason}");
                }
            }
        }
예제 #2
0
        public async Task Order([Remainder] string order)
        {
            using (Context.Channel.EnterTypingState())
            {
                if (order.Length > 1)
                {
                    var outp = _DB.CheckForExistingOrders(Context.User.Id);
                    if (outp)
                    {
                        await ReplyAsync("You already have an order!"); return;
                    }

                    SandwichUser u = await _UDB.FindUser(Context.User.Id);

                    u.Level = u.Orders / 10;

                    if (u == null)
                    {
                        await _UDB.CreateNewUser((SocketUser)Context.User);
                        await ReplyAsync("You've been registered!");

                        u = await _UDB.FindUser(Context.User.Id);
                    }

                    if (u.Credits < 1.0)
                    {
                        await ReplyAsync("You will need atleast 1 credit for this."); return;
                    }

                    string orderid;

                    try
                    {
                        IGuild usr = await Context.Client.GetGuildAsync(_SS.USRGuildId); //Isn't there a better way to do these?

                        ITextChannel usrc = await usr.GetTextChannelAsync(_SS.KitchenId);

                        ITextChannel usrclog = await usr.GetTextChannelAsync(_SS.LogId);

                        orderid = _DB.GenerateId(3);
                        orderid = _DB.VerifyIdUniqueness(orderid);

                        var neworder = await _DB.NewOrder(order, orderid, DateTime.Now, OrderStatus.Waiting, Context);

                        _QS.AddOrder(neworder);
                        var builder = new EmbedBuilder();
                        builder.ThumbnailUrl = Context.User.GetAvatarUrl();
                        builder.Title        = $" New order from {Context.Guild.Name} (`{Context.Guild.Id}`)";
                        var desc = $"Ordered by: **{Context.User.Username}#{Context.User.Discriminator}** (`{Context.User.Id}`)\n" +
                                   $"Id: `{orderid}`\n" +
                                   $"```{order}```";
                        builder.Description = desc;
                        builder.Color       = new Color(71, 120, 198);
                        builder.WithFooter(x =>
                        {
                            x.Text = "Is this order abusive? Please ping @Artist Manager immediately!";
                        });
                        builder.Timestamp = DateTime.Now;
                        _SS.totalOrders  += 1;



                        var artist = usr.Roles.FirstOrDefault(x => x.Name.ToLower() == "sandwich artist"); //FIX
                        if (artist != null)
                        {
                            await usrc.SendMessageAsync($"{artist.Mention}", embed : builder);
                        }
                        else
                        {
                            await usrc.SendMessageAsync($" ", embed : builder);
                        }
                    }
                    catch (Exception e)
                    {
                        await ReplyAsync("This error should not happen! Contact Fires#1043 immediately!");

                        Console.WriteLine(e);
                        await ReplyAsync($"```{e}```");

                        return;
                    }

                    IDMChannel dm = await Context.User.GetOrCreateDMChannelAsync();

                    IUserMessage m = await ReplyAsync(":thumbsup:");

                    try
                    {
                        await dm.SendMessageAsync($"Thank you for ordering. Please wait while an artist accepts you. :slight_smile: - ID `{orderid}`");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        await m.ModifyAsync(msg =>
                        {
                            msg.Content = $":thumbsdown: {Context.User.Mention} We failed to dm you. You're order has been automatically deleted. Please enable DMs and re order. http://i.imgur.com/vY7tThf.png OR http://i.imgur.com/EtaA78Q.png";
                        });

                        IGuild usr = await Context.Client.GetGuildAsync(_SS.USRGuildId);

                        ITextChannel usrc = await usr.GetTextChannelAsync(_SS.KitchenId);

                        await usrc.SendMessageAsync($"**IGNORE ORDER {orderid} AS IT HAS BEEN REMOVED**");
                    }
                }
                else
                {
                    await ReplyAsync("Your order must be longer then 2 characters.");
                }
            }
        }