Ejemplo n.º 1
0
        /// <summary>
        /// Selects the appropriate cs go container to open, user replies with a number corrosponding to the case
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static PaginatedMessage ShowPossibleCases(SocketCommandContext context)
        {
            string botCommandPrefix = CommandGuildPrefixManager.GetGuildCommandPrefix(context);

            //Create pagination entries
            List <string> leftCounter        = new List <string>();
            List <string> filteredContainers = new List <string>();

            //Find containers whose name is not null
            filteredContainers = CsgoUnboxingHandler.csgoContiners.Containers.Where(c => c.Name != null).Select(c => c.Name).ToList();
            //Create a list of ascending numbers to reference each container
            for (int i = 0; i < filteredContainers.Count(); i++)
            {
                leftCounter.Add(i.ToString());
            }

            //Generate pagination
            PaginationConfig paginationConfig = new PaginationConfig
            {
                AuthorName = "CS:GO Containers",
                AuthorURL  = "https://csgostash.com/img/containers/c259.png",

                Description = $"Select a container by typing the appropriate number on the left\nThen use `{botCommandPrefix} cs open` to open cases",

                Field1Header = "Number",
                Field2Header = "Case",
            };

            PaginationManager paginationManager = new PaginationManager();
            var pager = paginationManager.GeneratePaginatedMessage(leftCounter, filteredContainers, paginationConfig);

            return(pager);
        }
Ejemplo n.º 2
0
        public static async Task DisplayModerationHelpMenu(SocketCommandContext context)
        {
            string botCommandPrefix = CommandGuildPrefixManager.GetGuildCommandPrefix(context);

            var embedBuilder = new EmbedBuilder()
                               .WithDescription(" For a detailed guide on the usage of Duck, please check the [wiki](https://github.com/jaihysc/Discord-DuckBot/wiki/Main). \n \n Prefix: `.d elevated` \n Requires permission `Administrator`")
                               .WithColor(new Color(252, 144, 0))
                               .WithFooter(footer =>
            {
                footer
                .WithText($"To check command usage, type `{botCommandPrefix}` @help <command> // Use `{botCommandPrefix}` help for standard commands // Sent by " + context.Message.Author.ToString())
                .WithIconUrl(context.Message.Author.GetAvatarUrl());
            })
                               .WithAuthor(author =>
            {
                author
                .WithName("Duck Moderation Help")
                .WithIconUrl("https://ubisafe.org/images/duck-transparent-jpeg-5.png");
            })
                               .AddField("Channel Commands", "`clean`")
                               .AddField("Role Commands", "`Prefix: role` | `add` `remove`");

            var embed = embedBuilder.Build();

            await context.Message.Channel.SendMessageAsync(" ", embed : embed).ConfigureAwait(false);
        }
Ejemplo n.º 3
0
        public static async Task DisplayHelpMenu(SocketCommandContext context)
        {
            string botCommandPrefix = CommandGuildPrefixManager.GetGuildCommandPrefix(context);

            //https://leovoel.github.io/embed-visualizer/
            var embedBuilder = new EmbedBuilder()
                               .WithDescription($" For a detailed guide on the usage of Duck, please check the [wiki](https://github.com/jaihysc/Discord-DuckBot/wiki). \n \n Prefix: `{botCommandPrefix}`")
                               .WithColor(new Color(253, 184, 20))
                               .WithFooter(footer =>
            {
                footer
                .WithText("To check command usage, type .d help <command> // Use .d @help for moderation commands // Sent by " + context.Message.Author.ToString())
                .WithIconUrl(context.Message.Author.GetAvatarUrl());
            })
                               .WithAuthor(author =>
            {
                author
                .WithName("Duck Help")
                .WithIconUrl("https://ubisafe.org/images/duck-transparent-jpeg-5.png");
            })
                               .AddField("Currency Commands", "`balance` `daily` `debt` `borrow` `return` `moneyTransfer` `bankruptcy` ")
                               .AddField("Game Commands", "`Prefix: game` | `slot`")
                               .AddField("Stock Commands", "`Prefix: stock` | `portfolio` `market` `buy` `sell`")
                               .AddField("Case Commands", "`Prefix: cs` | `open` `drop` `case` `inventory` `market` `buy` `sell` `info` ")
                               .AddField("Role Commands", "`Prefix: role` | `list` `add` `remove`");

            var embed = embedBuilder.Build();

            await context.Message.Channel.SendMessageAsync(" ", embed : embed).ConfigureAwait(false);
        }
        public static PaginatedMessage DisplayUserCsgoInventory(SocketCommandContext context)
        {
            string botCommandPrefix = CommandGuildPrefixManager.GetGuildCommandPrefix(context);

            //Reset fields
            embedFieldsMaster      = new List <string>();
            embedPriceFieldsMaster = new List <string>();

            //Get user skins from xml file
            UserSkinStorageRootobject userSkin = new UserSkinStorageRootobject();

            try
            {
                userSkin = XmlManager.FromXmlFile <UserSkinStorageRootobject>(CoreMethod.GetFileLocation("UserSkinStorage.xml"));
            }
            catch (Exception)
            {
            }

            List <UserSkinEntry> foundUserSkins = new List <UserSkinEntry>();

            //Filter userSkinEntries xml file down to skins belonging to sender
            foreach (var userSkinEntry in userSkin.UserSkinEntries)
            {
                //Filter skin search to those owned by user
                if (userSkinEntry.OwnerID == context.Message.Author.Id)
                {
                    foundUserSkins.Add(new UserSkinEntry {
                        OwnerID = context.Message.Author.Id, ClassId = userSkinEntry.ClassId, UnboxDate = userSkinEntry.UnboxDate
                    });
                }
            }

            //Generate fields
            AddSkinFieldEntry(foundUserSkins);

            //Configurate paginated message
            var paginationConfig = new PaginationConfig
            {
                AuthorName = context.Message.Author.ToString().Substring(0, context.Message.Author.ToString().Length - 5) + " Inventory",
                AuthorURL  = context.Message.Author.GetAvatarUrl(),

                Description = $"To sell items, use `{botCommandPrefix} cs sell [name]` \n To sell all items matching filter, use `{botCommandPrefix} cs sellall [name]`",

                DefaultFieldHeader      = "You do not have any skins",
                DefaultFieldDescription = $"Go unbox some with `{botCommandPrefix} case open`",

                Field1Header = "Item Name",
                Field2Header = "Market Value",
            };

            var paginationManager = new PaginationManager();

            //Generate paginated message
            var pager = paginationManager.GeneratePaginatedMessage(embedFieldsMaster, embedPriceFieldsMaster, paginationConfig);

            return(pager);
        }
        public async Task OpenCaseAsync()
        {
            //See if user has opened a case before, if not, send a help tip
            if (!CsgoCaseSelectionHandler.GetHasUserSelectedCase(Context))
            {
                await ReplyAndDeleteAsync($"Tip: Use `{CommandGuildPrefixManager.GetGuildCommandPrefix(Context)} cs case` to select different cases to open", timeout : TimeSpan.FromSeconds(60));
            }

            await CsgoUnboxingHandler.OpenCase(Context);
        }
Ejemplo n.º 6
0
            public async Task ChangeGuildCommandPrefixAsync([Remainder] string input)
            {
                //Find guild id
                var chnl = Context.Channel as SocketGuildChannel;

                //Make sure invoker is owner of guild
                if (chnl.Guild.OwnerId == Context.Message.Author.Id)
                {
                    CommandGuildPrefixManager.ChangeGuildCommandPrefix(Context, input);
                    await Context.Channel.SendMessageAsync(UserInteraction.BoldUserName(Context) + $", server prefix has successfully been changed to `{CommandGuildPrefixManager.GetGuildCommandPrefix(Context)}`");
                }
                //Otherwise send error
                else
                {
                    await Context.Channel.SendMessageAsync(UserInteraction.BoldUserName(Context) + ", only the server owner may invoke this command");
                }
            }
        public static PaginatedMessage GetCsgoMarketInventory(SocketCommandContext context, string filterString)
        {
            string botCommandPrefix = CommandGuildPrefixManager.GetGuildCommandPrefix(context);

            //Get skin data
            var rootWeaponSkin = CsgoDataHandler.GetRootWeaponSkin();

            List <string> filteredRootWeaponSkin      = new List <string>();
            List <string> filteredRootWeaponSkinPrice = new List <string>();

            try
            {
                //Filter rootWeaponSkin to those with a price found in rootWeaponSkinPrice
                foreach (var skin in rootWeaponSkin.ItemsList.Values)
                {
                    //If filter string is not null, filter market results by user filter string
                    if ((!string.IsNullOrEmpty(filterString) && skin.Name.ToLower().Contains(filterString.ToLower())) || (string.IsNullOrEmpty(filterString)))
                    {
                        string skinQualityEmote = GetEmoteBySkinRarity(skin.Rarity, skin.WeaponType);

                        //Add skin entry
                        try
                        {
                            Emote emote = Emote.Parse(skinQualityEmote);

                            //Add weapon skin
                            filteredRootWeaponSkin.Add(emote + " " + skin.Name);

                            //Add tax markup for market item
                            long weaponSkinValue = Convert.ToInt64(skin.Price.AllTime.Average);
                            weaponSkinValue += Convert.ToInt64(weaponSkinValue * float.Parse(SettingsManager.RetrieveFromConfigFile("taxRate")));

                            //Add weapon skin price
                            filteredRootWeaponSkinPrice.Add(emote + " " + weaponSkinValue.ToString());
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
            }
            catch (Exception)
            {
            }

            //Configurate paginated message
            var paginationConfig = new PaginationConfig
            {
                AuthorName = "CS:GO Market",
                AuthorURL  = context.Message.Author.GetAvatarUrl(),

                Description = $"Current skin market, to buy skins, use `{botCommandPrefix} cs buy [name]` \n use `{botCommandPrefix} cs market [name]` to filter skins by name \n use `{botCommandPrefix} cs info [name]` to preview skins",

                DefaultFieldHeader      = "Unable to find specified weapon skin!",
                DefaultFieldDescription = $"Broaden your search parameters and try again",

                Field1Header = "Item Name",
                Field2Header = "Price",
            };

            var paginationManager = new PaginationManager();

            //Generate paginated message
            var pager = paginationManager.GeneratePaginatedMessage(filteredRootWeaponSkin, filteredRootWeaponSkinPrice, paginationConfig);

            return(pager);
        }
Ejemplo n.º 8
0
        //Command Handler
        public async Task HandleCommandAsync(SocketMessage messageParam)
        {
            // Don't process the command if it was a system message, if sender is bot
            SocketUserMessage message = messageParam as SocketUserMessage;

            if (message == null)
            {
                return;
            }

            if (message.Author.IsBot)
            {
                return;
            }

            //integer to determine when commands start
            int argPos = 0;


            //Ignore commands that are not using the prefix
            var    context       = new SocketCommandContext(_client, message);
            string commandPrefix = CommandGuildPrefixManager.GetGuildCommandPrefix(context);

            if (!(message.HasStringPrefix(commandPrefix + " ", ref argPos) ||
                  message.Author.IsBot))
            {
                return;
            }

            var result = await _commands.ExecuteAsync(context : context, argPos : argPos, services : _services);


            //COMMAND LOGGING
            // Inform the user if the command fails
            if (!result.IsSuccess)
            {
                var guild   = _client.GetGuild(384492615745142784);
                var channel = guild.GetTextChannel(504375404547801138);

                if (result.Error == CommandError.UnknownCommand)
                {
                    //Find similar commands
                    var    commandHelpDefinitionStorage = XmlManager.FromXmlFile <HelpMenuCommands>(CoreMethod.GetFileLocation(@"CommandHelpDescription.xml"));
                    string similarItemsString           = UserHelpHandler.FindSimilarCommands(
                        commandHelpDefinitionStorage.CommandHelpEntry.Select(i => i.CommandName).ToList(),
                        message.ToString().Substring(CommandGuildPrefixManager.GetGuildCommandPrefix(context).Length + 1));

                    //If no similar matches are found, send nothing
                    if (string.IsNullOrEmpty(similarItemsString))
                    {
                        await context.Channel.SendMessageAsync("Invalid command, use `.d help` for a list of commands");
                    }
                    //If similar matches are found, send suggestions
                    else
                    {
                        await context.Channel.SendMessageAsync($"Invalid command, use `.d help` for a list of commands. Did you mean: \n {similarItemsString}");
                    }
                }
                else if (result.Error == CommandError.BadArgCount)
                {
                    await context.Channel.SendMessageAsync($"Invalid command usage, use `.d help <command>` for correct command usage");
                }
                else if (result.Error != CommandError.UnmetPrecondition)
                {
                    await channel.SendMessageAsync($"[ERROR] **{message.Author.ToString()}** `{message}`  >|  {result.ErrorReason}");
                }
            }
        }