Esempio n. 1
0
        public static bool AddToWaitingListPreset(string presetName, string display, string username, ulong id, bool sub, out string msg)
        {
            if (!IsQueueable(presetName, id, out var msge))
            {
                msg = $"@{username} - {msge}";
                return(false);
            }

            try
            {
                var             cfg = Globals.Bot.Config;
                VillagerRequest?vr  = null;

                // try get villager
                var result = VillagerOrderParser.ExtractVillagerName(presetName, out var res, out var san);
                if (result == VillagerOrderParser.VillagerRequestResult.InvalidVillagerRequested)
                {
                    msg = $"@{username} - {res} Order has not been accepted.";
                    return(false);
                }

                if (result == VillagerOrderParser.VillagerRequestResult.Success)
                {
                    if (!cfg.AllowVillagerInjection)
                    {
                        msg = $"@{username} - Villager injection is currently disabled.";
                        return(false);
                    }

                    presetName = san;
                    var replace = VillagerResources.GetVillager(res);
                    vr = new VillagerRequest(username, replace, 0, GameInfo.Strings.GetVillager(res));
                }

                presetName = presetName.Trim();
                var preset = PresetLoader.GetPreset(cfg.OrderConfig, presetName);
                if (preset == null)
                {
                    msg = $"{username} - {presetName} is not a valid preset.";
                    return(false);
                }

                return(InsertToQueue(preset, vr, display, username, id, sub, true, out msg));
            }
            catch (Exception e)
            {
                LogUtil.LogError($"{username}@Preset:{presetName}: {e.Message}", nameof(TwitchHelper));
                msg = $"@{username} {e.Message}";
                return(false);
            }
        }
Esempio n. 2
0
        // Helper functions for commands
        public static bool AddToWaitingList(string orderString, string display, string username, ulong id, bool sub, bool cat, out string msg)
        {
            if (!IsQueueable(orderString, id, out var msge))
            {
                msg = $"@{username} - {msge}";
                return(false);
            }

            try
            {
                var             cfg = Globals.Bot.Config;
                VillagerRequest?vr  = null;

                // try get villager
                var result = VillagerOrderParser.ExtractVillagerName(orderString, out var res, out var san);
                if (result == VillagerOrderParser.VillagerRequestResult.InvalidVillagerRequested)
                {
                    msg = $"@{username} - {res} Order has not been accepted.";
                    return(false);
                }

                if (result == VillagerOrderParser.VillagerRequestResult.Success)
                {
                    if (!cfg.AllowVillagerInjection)
                    {
                        msg = $"@{username} - Villager injection is currently disabled.";
                        return(false);
                    }

                    orderString = san;
                    var replace = VillagerResources.GetVillager(res);
                    vr = new VillagerRequest(username, replace, 0, GameInfo.Strings.GetVillager(res));
                }

                var items = string.IsNullOrWhiteSpace(orderString) ? new Item[1] {
                    new Item(Item.NONE)
                } : ItemParser.GetItemsFromUserInput(orderString, cfg.DropConfig, ItemDestination.FieldItemDropped);

                return(InsertToQueue(items, vr, display, username, id, sub, cat, out msg));
            }
            catch (Exception e)
            {
                LogUtil.LogError($"{username}@{orderString}: {e.Message}", nameof(TwitchHelper));
                msg = $"@{username} {e.Message}";
                return(false);
            }
        }