Ejemplo n.º 1
0
        public async Task RemoveUserCredits(IGuildUser us, float credits)
        {
            SandwichUser u = await FindUser(us.Id);

            u.Credits -= credits;
            await SaveChangesAsync();
        }
Ejemplo n.º 2
0
        public async Task UpdateCreditDate(SandwichUser us)
        {
            SandwichUser u = await FindUser(us.Id);

            u.lastDailyCredits = DateTime.Now;
            await SaveChangesAsync();
        }
Ejemplo n.º 3
0
        public async Task Daily()
        {
            SandwichUser u = await udb.FindUser(Context.User.Id);

            if (u.lastDailyCredits.AddHours(12) < DateTime.Now)
            {
                var r    = new Random();
                var rand = r.Next(2, 15);
                if (u.IsPatron)
                {
                    await udb.GiveUserCredits(u, rand * 3);

                    await udb.UpdateCreditDate(u);
                    await ReplyAsync($"You have earned {rand * 3} credits! Come back tomorrow for more, Patron. :wink:");
                }
                else
                {
                    await udb.GiveUserCredits(u, rand);

                    await udb.UpdateCreditDate(u);
                    await ReplyAsync($"You have earned {rand} credits! Come back tomorrow for more.");
                }
            }
            else
            {
                await ReplyAsync("Come back later for more!");
            }
        }
Ejemplo n.º 4
0
        public async Task CreateNewUser(IGuildUser us)
        {
            Console.WriteLine($"Creating a new user profile for {us.Username}.");
            SandwichUser u = new SandwichUser(us);
            await Users.AddAsync(u);

            await SaveChangesAsync();
        }
Ejemplo n.º 5
0
        public async Task ChangeOrders(ulong id, int c)
        {
            SandwichUser us = await FindUser(id);

            if (us != null)
            {
                us.Orders = c;
                await SaveChangesAsync();
            }
        }
Ejemplo n.º 6
0
        public async Task AcceptOrder(string id)
        {
            using (Context.Channel.EnterTypingState())
            {
                try
                {
                    Artist a = await _ADB.FindArtist(Context.User.Id);

                    Sandwich o = await _DB.FindOrder(id);

                    SandwichUser user = await _UDB.FindUser(o.UserId);

                    if (o == null)
                    {
                        await ReplyAsync("That id isn't correct bud."); return;
                    }
                    ;
                    if (o.Status != OrderStatus.Waiting)
                    {
                        await ReplyAsync("This order is not available. :angry: "); return;
                    }

                    IGuild s = await Context.Client.GetGuildAsync(o.GuildId);

                    ITextChannel ch = await s.GetTextChannelAsync(o.ChannelId);

                    IGuildUser u = await s.GetUserAsync(o.UserId);

                    IDMChannel dm = await u.GetOrCreateDMChannelAsync();

                    _QS.AcceptOrder();
                    o.Status   = OrderStatus.ReadyToDeliver;
                    o.ArtistId = Context.User.Id;
                    await _ADB.ChangeAcceptCount(a, ArtistStatChange.Increase);

                    await ch.SendMessageAsync($"{u.Mention}, a Sandwich Artist has accepted your sandwich. It will be delivered soon.");
                    await ReplyAsync($":thumbsup:");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
        }
Ejemplo n.º 7
0
        public async Task Tip(IGuildUser us, float a)
        {
            SandwichUser u = await udb.FindUser(Context.User.Id);

            if (u != null)
            {
                if (a > 0.0f)
                {
                    IUser  userr = us as IUser;
                    IGuild USR   = await Context.Client.GetGuildAsync(ss.USRGuildId);

                    ITextChannel log = await USR.GetTextChannelAsync(ss.TipId);

                    SandwichUser tipper = await udb.FindUser(Context.User.Id);

                    if (tipper.Credits < a)
                    {
                        await ReplyAsync("You have no more credits left to tip!"); return;
                    }
                    ;
                    if (userr == Context.User)
                    {
                        await ReplyAsync("You can't tip yourself. That is cheating!"); await log.SendMessageAsync($"**{Context.User.Username}#{Context.User.Discriminator}** just tried to tip themselves..."); return;
                    }
                    SandwichUser recsu = await udb.FindUser(us.Id);

                    recsu.Credits += a;
                    u.Credits     -= a;
                    await udb.SaveChangesAsync();

                    await log.SendMessageAsync($"**{Context.User.Username}#{Context.User.Discriminator}** just tipped **{us.Username}#{us.Discriminator}** {a} credits..");
                    await ReplyAsync($"Thank you for tipping, you now have **{u.Credits}** credits left.");
                }
                else
                {
                    await ReplyAsync("You can only tip a minimum of 1 credit.");
                }
            }
            else
            {
                Console.WriteLine("cant find user in db");
            }
        }
Ejemplo n.º 8
0
 public async Task RemoveUserCredits(SandwichUser u, float credits)
 {
     u.Credits -= credits;
     await SaveChangesAsync();
 }
Ejemplo n.º 9
0
        public async Task DenyOrder(string id, [Remainder] string reason)
        {
            try
            {
                Sandwich order = await _DB.FindOrder(id);

                if (order == null)
                {
                    await ReplyAsync("No order has that id."); return;
                }
                order.Status = OrderStatus.Delivered;
                await _DB.DelOrder(id);

                _QS.Skip();
                await ReplyAsync($"{Context.User.Mention} has deleted order {order.Id}.");

                IGuild s = await Context.Client.GetGuildAsync(order.GuildId);

                ITextChannel ch = await s.GetTextChannelAsync(order.ChannelId);

                IGuildUser u = await s.GetUserAsync(order.UserId);

                IDMChannel dm = await u.GetOrCreateDMChannelAsync();

                Artist a = await _ADB.FindArtist(Context.User.Id);

                await _ADB.ChangeAcceptCount(a, ArtistStatChange.Decrease);

                await _ADB.ChangeDenyCount(a);

                SandwichUser user = await _UDB.FindUser(order.UserId);

                await _UDB.UpDenials(user.Id);

                await dm.SendMessageAsync($"Your sandwich order has been deleted! ", embed : new EmbedBuilder()
                                          .WithThumbnailUrl(Context.User.GetAvatarUrl())
                                          .WithUrl("https://discord.gg/DmGh9FT")
                                          .AddField(builder =>
                {
                    builder.Name = "Order:";
                    builder.Value = order.Desc;
                    builder.IsInline = true;
                })
                                          .AddField(builder =>
                {
                    builder.Name = "Denied By:";
                    builder.Value = string.Join("#", Context.User.Username, Context.User.Discriminator);
                    builder.IsInline = true;
                })
                                          .AddField(builder =>
                {
                    builder.Name = "Denied because:";
                    builder.Value = reason;
                    builder.IsInline = true;
                })
                                          .AddField(builder =>
                {
                    builder.Name = "Order Id:";
                    builder.Value = order.Id;
                    builder.IsInline = true;
                })
                                          .WithCurrentTimestamp()
                                          .WithTitle("Denied order:"));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Ejemplo n.º 10
0
        public async Task Deliver(string id)
        {
            _SS.Save();
            using (Context.Channel.EnterTypingState())
            {
                Sandwich o = await _DB.FindOrder(id);

                if (o.ArtistId == Context.User.Id)
                {
                    if (o.Status == OrderStatus.ReadyToDeliver)
                    {
                        Artist a = await _ADB.FindArtist(Context.User.Id);

                        //Collect variables
                        await ReplyAsync($"{Context.User.Mention} DMing you an invite! Go deliver it! Remember to be nice and ask for `;feedback`.");

                        IGuild s = await Context.Client.GetGuildAsync(o.GuildId);

                        SandwichUser user = await _UDB.FindUser(o.UserId);

                        await _UDB.UpOrders(user.Id);

                        ITextChannel ch = await s.GetTextChannelAsync(o.ChannelId);

                        IGuildUser u = await s.GetUserAsync(o.UserId);

                        IDMChannel dm = await u.GetOrCreateDMChannelAsync();

                        //Create Invite
                        IInvite inv = await ch.CreateInviteAsync(1800, 1, false, true);

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

                        //Build embed
                        var builder = new EmbedBuilder();
                        builder.ThumbnailUrl = o.AvatarUrl;
                        builder.Title        = $"Your order is being delivered by {Context.User.Username}#{Context.User.Discriminator}!";
                        var desc = $"```{o.Desc}```\n" +
                                   $"**Incoming sandwich! Watch {o.GuildName}!**";
                        builder.Description = desc;
                        builder.Color       = new Color(255, 181, 10);
                        builder.WithFooter(x =>
                        {
                            x.IconUrl = u.GetAvatarUrl();
                            x.Text    = $"Ordered at: {o.date}.";
                        });
                        builder.Timestamp = DateTime.UtcNow;
                        await dm.SendMessageAsync($"Your sandwich is being delivered soon! Watch out!", embed : builder);

                        //Finish up
                        await artistdm.SendMessageAsync("Invite: " + inv.ToString() + " \r\n Name: " + o.UserName);

                        o.Status = OrderStatus.Delivered;
                        await _ADB.UpdateMostRecentOrder(a);

                        await _UDB.GiveUserCredits(Context.User as IGuildUser, 5.0f);

                        await _DB.DelOrder(id);
                    }
                    else
                    {
                        await ReplyAsync("This order is not ready to be delivered yet.");
                    }
                }
                else
                {
                    await ReplyAsync("You have not claimed this order!");
                }
            }
        }
Ejemplo n.º 11
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.");
                }
            }
        }