public async Task InjectVillagerAsync(int index, string internalName) { if (!Globals.Bot.Config.DodoModeConfig.LimitedDodoRestoreOnlyMode) { await ReplyAsync($"{Context.User.Mention} - Villagers cannot be injected in order mode."); return; } if (!Globals.Bot.Config.AllowVillagerInjection) { await ReplyAsync($"{Context.User.Mention} - Villager injection is currently disabled."); return; } var bot = Globals.Bot; var nameSearched = internalName; if (!VillagerResources.IsVillagerDataKnown(internalName)) { internalName = GameInfo.Strings.VillagerMap.FirstOrDefault(z => string.Equals(z.Value, internalName, StringComparison.InvariantCultureIgnoreCase)).Key; } if (internalName == default) { await ReplyAsync($"{Context.User.Mention} - {nameSearched} is not a valid internal villager name."); return; } if (index > byte.MaxValue || index < 0) { await ReplyAsync($"{Context.User.Mention} - {index} is not a valid index"); return; } int slot = index; var replace = VillagerResources.GetVillager(internalName); var user = Context.User; var mention = Context.User.Mention; var request = new VillagerRequest(Context.User.Username, replace, (byte)index, GameInfo.Strings.GetVillager(internalName)) { OnFinish = success => { var reply = success ? $"Villager has been injected by the bot at Index {slot}. Please go talk to them!" : "Failed to inject villager. Please tell the bot owner to look at the logs!"; Task.Run(async() => await ReplyAsync($"{mention}: {reply}").ConfigureAwait(false)); } }; bot.VillagerInjections.Enqueue(request); var msg = $"{mention}: Villager inject request has been added to the queue and will be injected momentarily. I will reply to you once this has completed."; await ReplyAsync(msg).ConfigureAwait(false); }
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); } }
// 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); } }
private async Task InjectVillagers(int startIndex, string[] villagerNames) { if (!Globals.Bot.Config.DodoModeConfig.LimitedDodoRestoreOnlyMode) { await ReplyAsync($"{Context.User.Mention} - Villagers cannot be injected in order mode.").ConfigureAwait(false); return; } if (!Globals.Bot.Config.AllowVillagerInjection) { await ReplyAsync($"{Context.User.Mention} - Villager injection is currently disabled.").ConfigureAwait(false); return; } var bot = Globals.Bot; int index = startIndex; int count = villagerNames.Length; if (count < 1) { await ReplyAsync($"{Context.User.Mention} - No villager names in command").ConfigureAwait(false); return; } foreach (var nameLookup in villagerNames) { var internalName = nameLookup; var nameSearched = internalName; if (!VillagerResources.IsVillagerDataKnown(internalName)) { internalName = GameInfo.Strings.VillagerMap.FirstOrDefault(z => string.Equals(z.Value, internalName, StringComparison.InvariantCultureIgnoreCase)).Key; } if (internalName == default) { await ReplyAsync($"{Context.User.Mention} - {nameSearched} is not a valid internal villager name."); return; } if (index > byte.MaxValue || index < 0) { await ReplyAsync($"{Context.User.Mention} - {index} is not a valid index"); return; } int slot = index; var replace = VillagerResources.GetVillager(internalName); var user = Context.User; var mention = Context.User.Mention; var extraMsg = string.Empty; if (VillagerOrderParser.IsUnadoptable(internalName)) { extraMsg += " Please note that you will not be able to adopt this villager."; } var request = new VillagerRequest(Context.User.Username, replace, (byte)index, GameInfo.Strings.GetVillager(internalName)) { OnFinish = success => { var reply = success ? $"{nameSearched} has been injected by the bot at Index {slot}. Please go talk to them!{extraMsg}" : "Failed to inject villager. Please tell the bot owner to look at the logs!"; Task.Run(async() => await ReplyAsync($"{mention}: {reply}").ConfigureAwait(false)); } }; bot.VillagerInjections.Enqueue(request); index = (index + 1) % 10; } var addMsg = count > 1 ? $"Villager inject request for {count} villagers have" : "Villager inject request has"; var msg = $"{Context.User.Mention}: {addMsg} been added to the queue and will be injected momentarily. I will reply to you once this has completed."; await ReplyAsync(msg).ConfigureAwait(false); }