public TradeEntry(PokeTradeDetail <T> trade, ulong userID, PokeRoutineType type, string username) { Trade = trade; UserID = userID; Type = type; Username = username; }
private async Task PerformTrade(SAV8BS sav, PokeTradeDetail <PB8> detail, PokeRoutineType type, uint priority, CancellationToken token) { PokeTradeResult result; try { result = await PerformLinkCodeTrade(sav, detail, token).ConfigureAwait(false); if (result == PokeTradeResult.Success) { return; } } catch (SocketException socket) { Log(socket.Message); result = PokeTradeResult.ExceptionConnection; HandleAbortedTrade(detail, type, priority, result); throw; // let this interrupt the trade loop. re-entering the trade loop will recheck the connection. } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception e) #pragma warning restore CA1031 // Do not catch general exception types { Log(e.Message); result = PokeTradeResult.ExceptionInternal; } HandleAbortedTrade(detail, type, priority, result); }
public PokeTradeQueue <T> GetQueue(PokeRoutineType type) { return(type switch { PokeRoutineType.DuduBot => Dudu, _ => Queue, });
public bool Equals(ulong uid, PokeRoutineType type = 0) { if (UserID != uid) { return(false); } return(type == 0 || type == Type); }
public PokeTradeQueue <T> GetQueue(PokeRoutineType type) { return(type switch { PokeRoutineType.SeedCheck => Seed, PokeRoutineType.Clone => Clone, PokeRoutineType.Dump => Dump, _ => Trade, });
public PokeTradeQueue <T> GetQueue(PokeRoutineType type) { return(type switch { PokeRoutineType.DuduBot => Dudu, PokeRoutineType.Clone => Clone, PokeRoutineType.Dump => Dump, _ => Trade, });
protected virtual (PokeTradeDetail <PB8>?detail, uint priority) GetTradeData(PokeRoutineType type) { if (Hub.Queues.TryDequeue(type, out var detail, out var priority)) { return(detail, priority); } if (Hub.Queues.TryDequeueLedy(out detail)) { return(detail, PokeTradePriorities.TierFree); } return(null, PokeTradePriorities.TierFree); }
public async Task ChangeTaskAsync(string ip, [Summary("Routine enum name")] PokeRoutineType task) { var bot = SysCordInstance.Runner.GetBot(ip); if (bot == null) { await ReplyAsync($"No bot has that IP address ({ip}).").ConfigureAwait(false); return; } bot.Bot.Config.Initialize(task); await Context.Channel.EchoAndReply($"The bot at {ip} ({bot.Bot.Connection.Name}) has been commanded to do {task} as its next task.").ConfigureAwait(false); }
private void HandleAbortedTrade(PokeTradeDetail <PB8> detail, PokeRoutineType type, uint priority, PokeTradeResult result) { detail.IsProcessing = false; if (result.ShouldAttemptRetry() && detail.Type != PokeTradeType.Random && !detail.IsRetry) { detail.IsRetry = true; Hub.Queues.Enqueue(type, detail, Math.Min(priority, PokeTradePriorities.Tier2)); detail.SendNotification(this, "Oops! Something happened. I'll requeue you for another attempt."); } else { detail.SendNotification(this, $"Oops! Something happened. Canceling the trade: {result}."); detail.TradeCanceled(this, result); } }
public QueueCheckResult <T> CheckPosition(ulong uid, PokeRoutineType type = 0) { lock (_sync) { var index = UsersInQueue.FindIndex(z => z.Equals(uid, type)); if (index < 0) { return(QueueCheckResult <T> .None); } var entry = UsersInQueue[index]; var actualIndex = 1; for (int i = 0; i < index; i++) { if (UsersInQueue[i].Type == entry.Type) { actualIndex++; } } return(new QueueCheckResult <T>(true, entry, actualIndex)); } }
public void Initialize(PokeRoutineType type) { NextRoutineType = type; InitialRoutine = type; }
private bool AddToTradeQueue(PK8 pk8, int code, OnWhisperReceivedArgs e, bool sudo, PokeRoutineType type, out string msg) { // var user = e.WhisperMessage.UserId; var userID = ulong.Parse(e.WhisperMessage.UserId); var name = e.WhisperMessage.DisplayName; var trainer = new PokeTradeTrainerInfo(name); var notifier = new TwitchTradeNotifier <PK8>(pk8, trainer, code, e.WhisperMessage.Username, client, Channel); var detail = type == PokeRoutineType.DuduBot ? new PokeTradeDetail <PK8>(pk8, trainer, notifier, PokeTradeType.Dudu, code: code) : new PokeTradeDetail <PK8>(pk8, trainer, notifier, PokeTradeType.Specific, code: code); var trade = new TradeEntry <PK8>(detail, userID, type, name); var added = Info.AddToTradeQueue(trade, userID, sudo); if (added == QueueResultAdd.AlreadyInQueue) { msg = "Sorry, you are already in the queue."; return(false); } msg = $"Added {name} to the queue. Your current position is: {Info.CheckPosition(userID, type).Position}"; return(true); }
public static bool IsTradeBot(this PokeRoutineType type) => type is >= PokeRoutineType.FlexTrade and <= PokeRoutineType.Dump;
public void Resume() => NextRoutineType = InitialRoutine;
public static async Task AddToQueueAsync(SocketCommandContext context, int code, string trainer, RequestSignificance sig, T trade, PokeRoutineType routine, PokeTradeType type, SocketUser trader) { if ((uint)code > MaxTradeCode) { await context.Channel.SendMessageAsync("Trade code should be 00000000-99999999!").ConfigureAwait(false); return; } IUserMessage test; try { const string helper = "I've added you to the queue! I'll message you here when your trade is starting."; test = await trader.SendMessageAsync(helper).ConfigureAwait(false); } catch (HttpException ex) { await context.Channel.SendMessageAsync($"{ex.HttpCode}: {ex.Reason}!").ConfigureAwait(false); var noAccessMsg = context.User == trader ? "You must enable private messages in order to be queued!" : "The mentioned user must enable private messages in order for them to be queued!"; await context.Channel.SendMessageAsync(noAccessMsg).ConfigureAwait(false); return; } // Try adding var result = AddToTradeQueue(context, trade, code, trainer, sig, routine, type, trader, out var msg); // Notify in channel await context.Channel.SendMessageAsync(msg).ConfigureAwait(false); // Notify in PM to mirror what is said in the channel. await trader.SendMessageAsync($"{msg}\nYour trade code will be **{code:0000 0000}**.").ConfigureAwait(false); try { // Clean Up if (result) { // Delete the user's join message for privacy if (!context.IsPrivate) { await context.Message.DeleteAsync(RequestOptions.Default).ConfigureAwait(false); } } else { // Delete our "I'm adding you!", and send the same message that we sent to the general channel. await test.DeleteAsync().ConfigureAwait(false); } } catch (HttpException ex) { string message; // Check if the exception was raised due to missing "Manage Messages" permissions. Ping the bot host if so. var permissions = context.Guild.CurrentUser.GetPermissions(context.Channel as IGuildChannel); if (!permissions.ManageMessages) { var app = await context.Client.GetApplicationInfoAsync().ConfigureAwait(false); var owner = app.Owner.Id; message = $"<@{owner}> You must grant me \"Manage Messages\" permissions!"; } else { // Send a generic error message if we're not missing "Manage Messages" permissions. message = $"{ex.HttpCode}: {ex.Reason}!"; } await context.Channel.SendMessageAsync(message).ConfigureAwait(false); } }
public static async Task AddToQueueAsync(SocketCommandContext context, int code, string trainer, RequestSignificance sig, T trade, PokeRoutineType routine, PokeTradeType type, int catchID = 0) { await AddToQueueAsync(context, code, trainer, sig, trade, routine, type, context.User, catchID).ConfigureAwait(false); }
private bool AddToTradeQueue(PK8 pk8, int code, string trainerName, bool sudo, PokeRoutineType type, out string msg) { var user = Context.User; var userID = user.Id; var name = user.Username; var trainer = new PokeTradeTrainerInfo(trainerName); var notifier = new DiscordTradeNotifier <PK8>(pk8, trainer, code, Context); var detail = new PokeTradeDetail <PK8>(pk8, trainer, notifier, PokeTradeType.Dudu, code: code); var trade = new TradeEntry <PK8>(detail, userID, type, name); var added = Info.AddToTradeQueue(trade, userID, sudo); if (added == QueueResultAdd.AlreadyInQueue) { msg = "Sorry, you are already in the queue."; return(false); } msg = $"Added {user.Mention} to the queue for trade type: {type}. Your current position is: {Info.CheckPosition(userID, type).Position}"; return(true); }
private static bool AddToTradeQueue(this SocketCommandContext Context, PK8 pk8, int code, string trainerName, RequestSignificance sig, PokeRoutineType type, PokeTradeType t, SocketUser trader, out string msg) { var user = trader; var userID = user.Id; var name = user.Username; var trainer = new PokeTradeTrainerInfo(trainerName); var notifier = new DiscordTradeNotifier <PK8>(pk8, trainer, code, user); var detail = new PokeTradeDetail <PK8>(pk8, trainer, notifier, t, code: code, sig == RequestSignificance.Favored); var trade = new TradeEntry <PK8>(detail, userID, type, name); var hub = SysCordInstance.Self.Hub; var Info = hub.Queues.Info; var added = Info.AddToTradeQueue(trade, userID, sig == RequestSignificance.Sudo); if (added == QueueResultAdd.AlreadyInQueue) { msg = "Sorry, you are already in the queue."; return(false); } var position = Info.CheckPosition(userID, type); var ticketID = ""; if (TradeStartModule.IsStartChannel(Context.Channel.Id)) { ticketID = $", unique ID: {detail.ID}"; } var pokeName = ""; if (t == PokeTradeType.Specific && pk8.Species != 0) { pokeName = $" Receiving: {(Species)pk8.Species}."; } msg = $"{user.Mention} - Added to the {type} queue{ticketID}. Current Position: {position.Position}.{pokeName}"; var botct = Info.Hub.Bots.Count; if (position.Position > botct) { var eta = Info.Hub.Config.Queues.EstimateDelay(position.Position, botct); msg += $" Estimated: {eta:F1} minutes."; } return(true); }
public bool SupportsRoutine(PokeRoutineType t) => Factory.SupportsRoutine(t);
public static async Task AddToQueueAsync(this SocketCommandContext Context, int code, string trainer, RequestSignificance sig, PK8 trade, PokeRoutineType routine, PokeTradeType type) { await AddToQueueAsync(Context, code, trainer, sig, trade, routine, type, Context.User).ConfigureAwait(false); }
private bool AddToTradeQueue(PK8 pk8, int code, IUser user, RequestSignificance sig, PokeRoutineType type, out string msg) { // var user = e.WhisperMessage.UserId; var userID = (ulong)user.Id; var name = user.ScreenName; var trainer = new PokeTradeTrainerInfo(name); var notifier = new TwitterTradeNotifier <PK8>(pk8, trainer, code, name, client, user, Hub.Config.Twitter); var tt = type == PokeRoutineType.SeedCheck ? PokeTradeType.Seed : PokeTradeType.Specific; var detail = new PokeTradeDetail <PK8>(pk8, trainer, notifier, tt, code, sig == RequestSignificance.Favored); var trade = new TradeEntry <PK8>(detail, userID, type, name); var added = Info.AddToTradeQueue(trade, userID, sig == RequestSignificance.Sudo); if (added == QueueResultAdd.AlreadyInQueue) { msg = $"@{name}: Sorry, you are already in the queue."; return(false); } var position = Info.CheckPosition(userID, type); msg = $"@{name}: Added to the {type} queue, unique ID: {detail.ID}. Current Position: {position.Position}"; var botct = Info.Hub.Bots.Count; if (position.Position > botct) { var eta = Info.Hub.Config.Queues.EstimateDelay(position.Position, botct); msg += $". Estimated: {eta:F1} minutes."; } return(true); }
private bool AddToTradeQueue(PK8 pk8, int code, OnWhisperReceivedArgs e, bool sudo, PokeRoutineType type, out string msg) { // var user = e.WhisperMessage.UserId; var userID = ulong.Parse(e.WhisperMessage.UserId); var name = e.WhisperMessage.DisplayName; var trainer = new PokeTradeTrainerInfo(name); var notifier = new TwitchTradeNotifier <PK8>(pk8, trainer, code, e.WhisperMessage.Username, client, Channel, Hub.Config.Twitch); var tt = type == PokeRoutineType.SeedCheck ? PokeTradeType.Seed : PokeTradeType.Specific; var detail = new PokeTradeDetail <PK8>(pk8, trainer, notifier, tt, code: code); var trade = new TradeEntry <PK8>(detail, userID, type, name); var added = Info.AddToTradeQueue(trade, userID, sudo); if (added == QueueResultAdd.AlreadyInQueue) { msg = "Sorry, you are already in the queue."; return(false); } var position = Info.CheckPosition(userID, type); msg = $"@{name}: Added to the {type} queue, unique ID: {detail.ID}. Current Position: {position.Position}"; var botct = Info.Hub.Bots.Count; if (position.Position > botct) { var eta = Info.Hub.Config.Queues.EstimateDelay(position.Position, botct); msg += $". Estimated: {eta:F1} minutes."; } return(true); }
public static async Task AddToQueueAsync(this SocketCommandContext Context, int code, string trainer, bool sudo, PK8 trade, PokeRoutineType routine, PokeTradeType type) { if ((uint)code > MaxTradeCode) { await Context.Channel.SendMessageAsync("Trade code should be 00000000-99999999!").ConfigureAwait(false); return; } IUserMessage test; try { const string helper = "I've added you to the queue! I'll message you here when your trade is starting."; test = await Context.User.SendMessageAsync(helper).ConfigureAwait(false); } catch (HttpException ex) { await Context.Channel.SendMessageAsync($"{ex.HttpCode}: {ex.Reason}!").ConfigureAwait(false); await Context.Channel.SendMessageAsync("You must enable private messages in order to be queued!").ConfigureAwait(false); return; } // Try adding var result = Context.AddToTradeQueue(trade, code, trainer, sudo, routine, type, out var msg); // Notify in channel await Context.Channel.SendMessageAsync(msg).ConfigureAwait(false); // Notify in PM to mirror what is said in the channel. await Context.User.SendMessageAsync(msg).ConfigureAwait(false); // Clean Up if (result) { // Delete the user's join message for privacy if (!Context.IsPrivate) { await Context.Message.DeleteAsync(RequestOptions.Default).ConfigureAwait(false); } } else { // Delete our "I'm adding you!", and send the same message that we sent to the general channel. await test.DeleteAsync().ConfigureAwait(false); } }
private static bool AddToTradeQueue(SocketCommandContext context, T pk, int code, string trainerName, RequestSignificance sig, PokeRoutineType type, PokeTradeType t, SocketUser trader, out string msg, int catchID = 0) { var user = trader; var userID = user.Id; var name = user.Username; var trainer = new PokeTradeTrainerInfo(trainerName, userID); var notifier = new DiscordTradeNotifier <T>(pk, trainer, code, user); var detail = new PokeTradeDetail <T>(pk, trainer, notifier, t, code, sig == RequestSignificance.Favored); var trade = new TradeEntry <T>(detail, userID, type, name); var hub = SysCord <T> .Runner.Hub; var Info = hub.Queues.Info; var added = Info.AddToTradeQueue(trade, userID, sig == RequestSignificance.Owner); if (added == QueueResultAdd.AlreadyInQueue) { msg = "Sorry, you are already in the queue."; return(false); } if (detail.Type == PokeTradeType.TradeCord) { TradeCordHelper <T> .TradeCordTrades.Add(trader.Id, catchID); } var position = Info.CheckPosition(userID, type); var ticketID = ""; if (TradeStartModule <T> .IsStartChannel(context.Channel.Id)) { ticketID = $", unique ID: {detail.ID}"; } var pokeName = ""; if ((t == PokeTradeType.Specific || t == PokeTradeType.TradeCord || t == PokeTradeType.SupportTrade || t == PokeTradeType.Giveaway) && pk.Species != 0) { pokeName = $" Receiving: {(t == PokeTradeType.SupportTrade && pk.Species != (int)Species.Ditto && pk.HeldItem != 0 ? $"{(Species)pk.Species} ({ShowdownParsing.GetShowdownText(pk).Split('@','\n')[1].Trim()})" : $"{(Species)pk.Species}")}."; } msg = $"{user.Mention} - Added to the {type} queue{ticketID}. Current Position: {position.Position}.{pokeName}"; var botct = Info.Hub.Bots.Count; if (position.Position > botct) { var eta = Info.Hub.Config.Queues.EstimateDelay(position.Position, botct); msg += $" Estimated: {eta:F1} minutes."; } return(true); }
private static bool AddToTradeQueue(this SocketCommandContext Context, PK8 pk8, int code, string trainerName, bool sudo, PokeRoutineType type, PokeTradeType t, out string msg) { var user = Context.User; var userID = user.Id; var name = user.Username; var trainer = new PokeTradeTrainerInfo(trainerName); var notifier = new DiscordTradeNotifier <PK8>(pk8, trainer, code, Context); var detail = new PokeTradeDetail <PK8>(pk8, trainer, notifier, t, code: code); var trade = new TradeEntry <PK8>(detail, userID, type, name); var hub = SysCordInstance.Self.Hub; var Info = hub.Queues.Info; var added = Info.AddToTradeQueue(trade, userID, sudo); if (added == QueueResultAdd.AlreadyInQueue) { msg = "Sorry, you are already in the queue."; return(false); } var position = Info.CheckPosition(userID, type); var ticketID = ""; if (TradeStartModule.IsStartChannel(Context.Channel.Id)) { ticketID = $", unique ID: {detail.ID}"; } var pokeName = ""; if (t == PokeTradeType.Specific || t == PokeTradeType.EggRoll && pk8.Species != 0) { pokeName = $" Receiving: {(t == PokeTradeType.EggRoll ? "Mysterious egg" : hub.Config.Trade.ItemMuleSpecies == (Species)pk8.Species && pk8.HeldItem != 0 ? $"{(Species)pk8.Species + " (" + ShowdownSet.GetShowdownText(pk8).Split('@','\n')[1].Trim() + ")"}" : $"{(Species)pk8.Species}")}."; } msg = $"{user.Mention} - Added to the {type} queue{ticketID}. Current Position: {position.Position}.{pokeName}"; var botct = Info.Hub.Bots.Count; if (position.Position > botct) { var eta = Info.Hub.Config.Queues.EstimateDelay(position.Position, botct); msg += $" Estimated: {eta:F1} minutes."; } return(true); }
/// <summary> /// Sets the <see cref="NextRoutineType"/> so that the next iteration will perform as desired, /// and updates the <see cref="InitialRoutine"/> in the event the settings are saved. /// </summary> public void Initialize(PokeRoutineType type, ConnectionType conType) { NextRoutineType = type; InitialRoutine = type; ConnectionType = conType; }
private static bool AddToTradeQueue(this SocketCommandContext Context, PK8 pk8, int code, string trainerName, bool sudo, PokeRoutineType type, PokeTradeType t, out string msg) { var user = Context.User; var userID = user.Id; var name = user.Username; var priority = user.EvaluatePriority(); var trainer = new PokeTradeTrainerInfo(trainerName); var notifier = new DiscordTradeNotifier <PK8>(pk8, trainer, code, Context); var detail = new PokeTradeDetail <PK8>(pk8, trainer, notifier, t, code: code); var trade = new TradeEntry <PK8>(detail, userID, type, name); var hub = SysCordInstance.Self.Hub; var Info = hub.Queues.Info; var added = Info.AddToTradeQueue(trade, userID, priority, sudo); if (added == QueueResultAdd.AlreadyInQueue) { msg = "Sorry, you are already in the queue."; return(false); } user.Timestamp(); var position = Info.CheckPosition(userID, type); var ticketID = ""; if (TradeStartModule.IsStartChannel(Context.Channel.Id)) { ticketID = $", unique ID: {detail.ID}"; } msg = $"{user.Mention} - Added to the {type} queue{ticketID}. Current Position: {position.Position}"; var botct = Info.Hub.Bots.Count; if (position.Position > botct) { var eta = Info.Hub.Config.Queues.EstimateDelay(position.Position, botct); msg += $". Estimated: {eta:F1} minutes."; } return(true); }
public void Pause() => NextRoutineType = PokeRoutineType.Idle;
public static async Task AddToQueueAsync(SocketCommandContext context, int code, string trainer, RequestSignificance sig, T trade, PokeRoutineType routine, PokeTradeType type, SocketUser trader, int catchID = 0) { if ((uint)code > MaxTradeCode) { await context.Channel.SendMessageAsync("Trade code should be 00000000-99999999!").ConfigureAwait(false); return; } try { const string helper = "I've added you to the queue! I'll message you here when your trade is starting."; IUserMessage test = await trader.SendMessageAsync(helper).ConfigureAwait(false); // Try adding var result = AddToTradeQueue(context, trade, code, trainer, sig, routine, type, trader, out var msg, catchID); // Notify in channel await context.Channel.SendMessageAsync(msg).ConfigureAwait(false); // Notify in PM to mirror what is said in the channel. await trader.SendMessageAsync($"{msg}\nYour trade code will be **{code:0000 0000}**.").ConfigureAwait(false); // Clean Up if (result) { // Delete the user's join message for privacy if (!context.IsPrivate) { await context.Message.DeleteAsync(RequestOptions.Default).ConfigureAwait(false); } } else { // Delete our "I'm adding you!", and send the same message that we sent to the general channel. await test.DeleteAsync().ConfigureAwait(false); } } catch (HttpException ex) { await HandleDiscordExceptionAsync(context, trader, ex).ConfigureAwait(false); } }
public async Task ChangeTaskAsync([Summary("Identified name of bot (OT-ID)")] string name, [Summary("Routine enum name")] PokeRoutineType task) { var bot = SysCordInstance.Self.Hub.Bots.ToArray(); var match = Array.Find(bot, z => z.Connection.Name == name); if (match == null) { await ReplyAsync($"Could not find bot identified as {name}.").ConfigureAwait(false); return; } match.Config.Initialize(task); await ReplyAsync($"Changed {name}'s next routine to {task}.").ConfigureAwait(false); }