Exemplo n.º 1
0
        public async Task SetupShopCommand(string shopId, string displayName, string description = null, string thumbnailUrl = null)
        {
            StringUtils.CheckAndLowerStringId(ref shopId);
            MopBot.CheckForNullOrEmpty(displayName, nameof(displayName));

            var context           = Context;
            var cmdShopServerData = context.server.GetMemory().GetData <CommandShopSystem, CommandShopServerData>();
            var shops             = cmdShopServerData.Shops;

            if (!shops.TryGetValue(shopId, out Shop shop))
            {
                shops[shopId] = shop = new Shop();
            }

            shop.displayName  = displayName;
            shop.description  = description;
            shop.thumbnailUrl = thumbnailUrl;
        }
Exemplo n.º 2
0
        public async Task AddItemCommand(string shopId, string itemName, string itemPrice, string itemCommand)
        {
            MopBot.CheckForNullOrEmpty(itemName, nameof(itemName));
            MopBot.CheckForNullOrEmpty(itemCommand, nameof(itemCommand));

            var serverMemory      = Context.server.GetMemory();
            var cmdShopServerData = serverMemory.GetData <CommandShopSystem, CommandShopServerData>();
            var shops             = cmdShopServerData.Shops;

            if (!shops.TryGetValue(shopId, out Shop shop))
            {
                throw new BotError($"No such shop: `{shopId}`.");
            }

            var item = new ShopItem(itemName, CurrencyAmount.ParseMultiple(itemPrice, serverMemory), new SudoCommand(itemCommand, Context.user.Id));

            lock (shop) {
                shop.Items = shop.Items?.Append(item)?.ToArray() ?? new[] { item };
            }
        }