Пример #1
0
        public static async void BidTimerCallBack(object state)
        {
            var posts = MarketPost.GetAllPosts();
            List <MarketPost> expired      = new List <MarketPost>();
            List <MarketPost> expiringSoon = new List <MarketPost>();

            foreach (var post in posts)
            {
                var expiryDate = post.DatePosted + new TimeSpan(14, 0, 0, 0);
                if (expiryDate - Var.CurrentDate() < new TimeSpan(0))
                {
                    expired.Add(post);
                }
                else if (expiryDate - Var.CurrentDate() < new TimeSpan(1, 0, 0, 0))
                {
                    string id = post.ID;
                    if (Properties.Settings.Default.warnedFMs == null)
                    {
                        Properties.Settings.Default.warnedFMs = new System.Collections.Specialized.StringCollection();
                    }
                    if (!Properties.Settings.Default.warnedFMs.Contains(id))
                    {
                        Properties.Settings.Default.warnedFMs.Add(id);
                        Properties.Settings.Default.Save();
                        expiringSoon.Add(post);
                    }
                }
            }

            foreach (MarketPost warn in expiringSoon)
            {
                var    user     = warn.User;
                string postID   = warn.ID;
                int    count    = warn.Amount;
                string itemName = DBFunctions.GetItemName(warn.Item_ID);
                int    price    = warn.Price;
                await user.SendMessageAsync("", embed : new InfoEmbed("WARNING: FREE MARKET POSTING EXPIRATION", "This is your one warning that your Free Market posting of " +
                                                                      $"{count} {itemName} for {price} coins will be expiring in 24 hours. You may remove this posting for a 25% fee, or it will " +
                                                                      $"be auctioned off and the coins will go towards slots.").Build());
            }

            bool removed = false;
            List <MarketPost> newBids = new List <MarketPost>();

            foreach (var expiry in expired)
            {
                var    user     = expiry.User;
                string postID   = expiry.ID;
                int    count    = expiry.Amount;
                string itemName = DBFunctions.GetItemName(expiry.Item_ID);
                int    price    = expiry.Price;
                await user.SendMessageAsync("", embed : new InfoEmbed("FREE MARKET POSTING EXPIRATION", "This message is to inform you that your Free Market posting of " +
                                                                      $"{count} {itemName} for {price} coins has expired. You have not removed it, and now it will " +
                                                                      $"be auctioned off and the coins will go towards slots.").Build());


                var notifyUsers = DBFunctions.GetUsersWhere("Notify_Bid", "1");

                foreach (IUser u in notifyUsers)
                {
                    await u.SendMessageAsync("", embed : new InfoEmbed("New Bid Alert", $"There is a new bid for {count} {itemName}(s)! Get it with the ID: {postID}.\n*You are receiving this message because you have opted in to new bid notifications.*").Build());
                }
                newBids.Add(expiry);

                MarketPost.DeletePost(postID);
            }

            if (removed)
            {
                foreach (var bid in newBids)
                {
                    new Bid(bid.Item_ID, bid.Amount);
                }
            }

            var bids = Bid.GetAllBids();

            for (int i = 0; i < bids.Count(); i++)
            {
                var endDate = bids[i].EndDate;
                var endTime = endDate - Var.CurrentDate();
                if (endTime <= new TimeSpan(0))
                {
                    var itemID     = bids[i].Item_ID;
                    var amount     = bids[i].Amount;
                    var bidder     = bids[i].CurrentBidder;
                    var currentBid = bids[i].CurrentBid;
                    if (bidder != null)
                    {
                        await bidder.SendMessageAsync($"Congratulations! You've won the bid for {DBFunctions.GetItemEmote(itemID)} {amount} {DBFunctions.GetItemName(itemID)}(s).");

                        var user = Functions.GetUser(bidder);
                        Properties.Settings.Default.jackpot += currentBid;
                        Properties.Settings.Default.Save();
                        for (int j = 0; j < amount; j++)
                        {
                            user.GiveItem(itemID);
                        }
                    }
                    Bid.DeleteBid(bids[i].ID);
                }
            }

            if ((Var.CurrentDate().DayOfWeek == DayOfWeek.Friday || Var.CurrentDate().DayOfWeek == DayOfWeek.Wednesday) && Properties.Settings.Default.lastBid.DayOfYear != Var.CurrentDate().DayOfYear)
            {
                Properties.Settings.Default.lastBid = Var.CurrentDate();
                Properties.Settings.Default.Save();

                var bidItems = new string[] { "key", "unicorn", "key2", "package", "santa", "gift", "calling" };
                int amount   = rdm.Next(10) + 3;

                string item   = bidItems[rdm.Next(bidItems.Count())];
                var    itemID = DBFunctions.GetItemID(item);

                var newBid = new Bid(itemID, amount);

                var notifyUsers = DBFunctions.GetUsersWhere("Notify_Bid", "1");
                foreach (IUser u in notifyUsers)
                {
                    await u.SendMessageAsync("", embed : new InfoEmbed("Bi-Weekly Bid Alert", $"The bi-weekly bid is on! This time: {amount} {item}(s)! Get it with the ID: {newBid.ID}.\n*You are receiving this message because you have opted in to new bid notifications.*").Build());
                }
            }
        }
Пример #2
0
        public async Task HandleCommand(SocketMessage messageParam)
        {
            SocketUserMessage message = messageParam as SocketUserMessage;
            bool isDM = await Functions.isDM(message as IMessage);

            if (isDM && Var.LockDM)
            {
                Console.WriteLine(message.Author.Username + " [" + message.Author.Id + "] attempted to use a command in DM's:\n'" + message.Content + "'"); return;
            }
            if (message == null)
            {
                return;
            }
            if (message.Author.Id == client.CurrentUser.Id)
            {
                return;                                             //doesn't allow the bot to respond to itself
            }
            if (Var.DebugMode && message.Author.Id != Constants.Users.BRADY && Var.DebugUsers.Where(x => x.Id == message.Author.Id).Count() <= 0)
            {
                return;
            }

            if (!Var.DebugMode && message.Channel.Id == Constants.Channels.DEBUG)
            {
                return;
            }
            var user = Functions.GetUser(message.Author);

            #region Pre-Command Functions

            if (lastDay.DayOfYear < Var.CurrentDate().DayOfYear)
            {
                int strikeCount = (Var.CurrentDate() - Constants.Dates.STRIKE_END).Days;
                await client.SetGameAsync(strikeCount + " days since last strike", type : ActivityType.Watching);
            }

            //checks if message contains any blocked words
            if (!isDM && (message.Channel as IGuildChannel).Guild.Id == Constants.Guilds.YORK_UNIVERSITY && Functions.Filter(message.Content))
            {
                await message.DeleteAsync();

                return;
            }

            if (Var.blockedUsers.Where(x => x.Id == message.Author.Id).Count() > 0)
            {
                return;                                                                   //prevents "blocked" users from using the bot
            }
            ulong[] blockedChannels = { Constants.Channels.GENERAL_SLOW, Constants.Channels.GENERAL_TRUSTED, Constants.Channels.NEWS_DEBATE, Constants.Channels.LIFESTYLE };
            if (!isDM && (message.Channel as IGuildChannel).Guild.Id == Constants.Guilds.YORK_UNIVERSITY && (blockedChannels.Contains(message.Channel.Id)) && !(message.Author as IGuildUser).RoleIds.Contains(Constants.Roles.MOD) && !(message.Author as IGuildUser).RoleIds.Contains(Constants.Roles.BOOSTER))
            {
                return;
            }

            if (message.Author.IsBot && message.Author.Id != Constants.Users.FORKPY)
            {
                return;
            }

            //present stuff
            if (Var.presentWaiting && message.Content == Convert.ToString(Var.presentNum))
            {
                Var.presentWaiting = false;
                var presents = DBFunctions.GetItemIDList();
                int presID;
                do
                {
                    var presIndex = rdm.Next(presents.Count());
                    presID = presents[presIndex];
                } while (!DBFunctions.ItemIsPresentable(presID));
                Var.present  = DBFunctions.GetItemName(presID);
                Var.rPresent = Var.present;
                var presentName = Var.present;
                var pMessage    = DBFunctions.GetItemDescription(presID);
                var msg         = $"{message.Author.Username}! You got...\nA {Func.ToTitleCase(presentName.Replace('_', ' '))}! {DBFunctions.GetItemEmote(presID)} {pMessage}";
                user.GiveItem(Var.present);

                if (Var.replaceable)
                {
                    msg                += $"\nDon't like this gift? Press {Var.presentNum} again to replace it once!";
                    Var.replacing       = true;
                    Var.presentReplacer = message.Author;
                }
                await message.Channel.SendMessageAsync(msg);
            }
            else if (Var.replaceable && Var.replacing && message.Content == Convert.ToString(Var.presentNum) && message.Author == Var.presentReplacer)
            {
                if (user.HasItem(Var.present))
                {
                    user.RemoveItem(Var.present);
                    await message.Channel.SendMessageAsync($":convenience_store: {DBFunctions.GetItemEmote(Var.present)} :runner: \nA **new** present appears! :gift: Press {Var.presentNum} to open it!");

                    Var.presentWaiting = true;
                    Var.replacing      = false;
                    Var.replaceable    = false;
                }
                else
                {
                    await message.Channel.SendMessageAsync("You no longer have the present, so you cannot replace it!");

                    Var.replacing   = false;
                    Var.replaceable = false;
                }
            }

            //detects invites for unwanted servers (in yorku server) and deletes them
            if (!isDM && (message.Channel as IGuildChannel).Guild.Id == Constants.Guilds.YORK_UNIVERSITY && message.Content.ToLower().Contains("discord.gg") || message.Content.ToLower().Contains("discordapp.com/invite"))
            {
                var words = message.Content.Split(' ');
                foreach (string word in words)
                {
                    if (word.Contains("discord"))
                    {
                        string  id  = word.Split('/')[word.Split('/').Count() - 1];
                        IInvite inv = await client.GetInviteAsync(id);

                        if (inv.GuildId == Constants.Guilds.FORKU)
                        {
                            await messageParam.DeleteAsync();
                        }
                        return;
                    }
                }
            }

            #endregion

            int argPos = 0;
            //detect and execute commands
            if (message.HasCharPrefix(';', ref argPos))
            {
                // new user prevention
                var userCreationDate = message.Author.CreatedAt;
                var existenceTime    = DateTime.UtcNow.Subtract(userCreationDate.DateTime);
                var week             = new TimeSpan(7, 0, 0, 0);
                if (existenceTime < week)
                {
                    if (!newUsers.Contains(message.Author.Id))
                    {
                        newUsers.Add(message.Author.Id);
                        await message.Author.SendMessageAsync("Hi there! Welcome to Discord. In order to avoid bot abuse, your account must be older than a few days.\n" +
                                                              "If you don't understand, just message <@108312797162541056> about it.\nThanks!");
                    }
                    return;
                }

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

                if (!result.IsSuccess)
                {
                    if (result.Error != CommandError.UnknownCommand)
                    {
                        Console.WriteLine(result.ErrorReason);
                        var emb = new InfoEmbed("ERROR:", result.ErrorReason).Build();
                        await message.Channel.SendMessageAsync("", embed : emb);
                    }
                    else
                    {
                        if (user.HasItem(message.Content.Replace(";", "")))
                        {
                            await message.Channel.SendMessageAsync("Nothing happens... *Use `;suggest [suggestion]` if you have an idea for this item!*");
                        }
                    }
                }
                else
                {
                    //give user a chance at a lootbox
                    bool inLM = false;
                    //go through users last command time
                    foreach (var u in Var.lastMessage)
                    {
                        //ensure user is in dictionary
                        if (u.Key == context.User.Id)
                        {
                            inLM = true; break;
                        }
                    }
                    if (inLM == false)
                    {
                        Var.lastMessage.Add(context.User.Id, Var.CurrentDate() - new TimeSpan(1, 0, 1));
                    }
                    //if chance of lootbox
                    if (Var.lastMessage[context.User.Id] <= Var.CurrentDate() - new TimeSpan(1, 0, 0))
                    {
                        //10% chance at lootbox
                        if (rdm.Next(100) + 1 < 10)
                        {
                            await context.Channel.SendMessageAsync(":package: `A lootbox appears in your inventory! (package)`");

                            Functions.GetUser(context.User).GiveItem("package");
                        }
                    }
                    //set last message time to now
                    Var.lastMessage[context.User.Id] = Var.CurrentDate();
                }
            }
            else if (message.MentionedUsers.First().Id == client.CurrentUser.Id && message.Author.Id != client.CurrentUser.Id && Var.responding && ((message.Channel as IGuildChannel).Guild.Id != Constants.Guilds.YORK_UNIVERSITY || message.Channel.Id == Constants.Channels.COMMANDS || message.Channel.Id == 265998661606047744))
            {
                Functions.Respond(message);
            }
            else if ((message.Channel as IGuildChannel).Guild.Id != Constants.Guilds.YORK_UNIVERSITY && !Var.responding)
            {
                Functions.Respond(message);
            }
            else
            {
                return;
            }
        }
Пример #3
0
 public void RemoveItem(int itemID) => RemoveItem(DBFunctions.GetItemName(itemID));
Пример #4
0
        public JEmbed Build()
        {
            JEmbed emb = new JEmbed();

            if (!isBM)
            {
                emb.Title = "Shop";
            }
            else
            {
                emb.Title = ":spy: Black Market :spy:";
            }
            emb.ThumbnailUrl = Constants.Images.ForkBot;
            emb.ColorStripe  = Constants.Colours.YORK_RED;
            var restock = new TimeSpan(4, 0, 0).Add(openDate - Var.CurrentDate());

            if (!isBM)
            {
                emb.Description = $"The shop will restock in {restock.Hours} hours and {restock.Minutes} minutes.";
            }
            else
            {
                emb.Description = $"Welcome to the Black Market... Buy somethin and get out. We'll restock in {restock.Hours} hours and {restock.Minutes} minutes.";
            }
            for (int i = 0; i < 5; i++)
            {
                var    itemID = items[i];
                string emote  = DBFunctions.GetItemEmote(items[i]);
                string name   = DBFunctions.GetItemName(itemID);
                string desc;
                desc = DBFunctions.GetItemDescription(itemID, isBM);
                int stockAmt = stock[i];
                int price    = DBFunctions.GetItemPrice(itemID);
                if (price < 0)
                {
                    price = -price;
                }
                emb.Fields.Add(new JEmbedField(x =>
                {
                    x.Header = $"{emote} {name.Replace("_", " ")} - {price} coins [{stockAmt} left in stock]";
                    x.Text   = desc;
                }));
            }

            if (!isBM)
            {
                var count = DBFunctions.GetRelevantNewsCount();

                if (count > 0)
                {
                    emb.Fields.Add(new JEmbedField(x =>
                    {
                        var newsPrice = DBFunctions.GetItemPrice("newspaper");
                        x.Header      = $"📰 Newspaper -  { newsPrice } [({count}) current article(s)]";
                        x.Text        = "The Daily Fork! Get all the now information of what's going on around ForkBot!";
                    }));
                }
            }

            return(emb);
        }
Пример #5
0
 public bool GiveItem(int itemID)
 {
     return(GiveItem(DBFunctions.GetItemName(itemID)));
 }