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 async Task TradeAsyncAttach(int code, RequestSignificance sig, SocketUser usr) { var attachment = Context.Message.Attachments.FirstOrDefault(); if (attachment == default) { await ReplyAsync("No attachment provided!").ConfigureAwait(false); return; } var att = await NetUtil.DownloadPKMAsync(attachment).ConfigureAwait(false); if (!att.Success || !(att.Data is PK8 pk8)) { await ReplyAsync("No PK8 attachment provided!").ConfigureAwait(false); return; } await AddTradeToQueueAsync(code, usr.Username, pk8, sig, usr).ConfigureAwait(false); }
private async Task TradeAsyncAttach(int code, RequestSignificance sig, SocketUser usr) { var attachment = Context.Message.Attachments.FirstOrDefault(); if (attachment == default) { await ReplyAsync("No attachment provided!").ConfigureAwait(false); return; } var att = await NetUtil.DownloadPKMAsync(attachment).ConfigureAwait(false); var pk8 = GetRequest(att); if (pk8 == null) { await ReplyAsync("Attachment provided is not compatible with this module!").ConfigureAwait(false); return; } await AddTradeToQueueAsync(code, usr.Username, pk8, sig, usr).ConfigureAwait(false); }
private static bool AddToTradeQueue(this SocketCommandContext Context, PK8 pk8, int code, string trainerName, RequestSignificance sig, 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, 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 || t == PokeTradeType.TradeCord && pk8.Species != 0) { pokeName = $" Receiving: {(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); }
public static async Task AddToQueueAsync(this SocketCommandContext Context, int code, string trainer, RequestSignificance sig, 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, sig, 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); }
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); }
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 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 async Task AddTradeToQueueAsync(int code, string trainerName, PK8 pk8, RequestSignificance sig) { if (!pk8.CanBeTraded() || !new TradeExtensions(Info.Hub).IsItemMule(pk8)) { var msg = "Provided Pokémon content is blocked from trading!"; await ReplyAsync($"{(!Info.Hub.Config.Trade.ItemMuleCustomMessage.Equals(string.Empty) && !Info.Hub.Config.Trade.ItemMuleSpecies.Equals(Species.None) ? Info.Hub.Config.Trade.ItemMuleCustomMessage : msg)}").ConfigureAwait(false); return; } if (Info.Hub.Config.Trade.DittoTrade && pk8.Species == 132) { TradeExtensions.DittoTrade(pk8); } if (Info.Hub.Config.Trade.EggTrade && pk8.Nickname == "Egg") { TradeExtensions.EggTrade(pk8); } var la = new LegalityAnalysis(pk8); if (!la.Valid && SysCordInstance.Self.Hub.Config.Legality.VerifyLegality) { await ReplyAsync("PK8 attachment is not legal, and cannot be traded!").ConfigureAwait(false); return; } await Context.AddToQueueAsync(code, trainerName, sig, pk8, PokeRoutineType.LinkTrade, PokeTradeType.Specific).ConfigureAwait(false); }
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); } }
private async Task AddTradeToQueueAsync(int code, string trainerName, PK8 pk8, RequestSignificance sig, SocketUser usr) { if (!pk8.CanBeTraded()) { await ReplyAsync("Provided Pokémon content is blocked from trading!").ConfigureAwait(false); return; } var la = new LegalityAnalysis(pk8); if (!la.Valid && SysCordInstance.Self.Hub.Config.Legality.VerifyLegality) { await ReplyAsync("PK8 attachment is not legal, and cannot be traded!").ConfigureAwait(false); return; } await Context.AddToQueueAsync(code, trainerName, sig, pk8, PokeRoutineType.LinkTrade, PokeTradeType.Specific, usr).ConfigureAwait(false); }
private static bool AddToTradeQueue(this SocketCommandContext Context, PK8 pk8, int code, string trainerName, RequestSignificance sig, PokeRoutineType type, PokeTradeType t, SocketUser trader, out string msg, string requestedIgn = "") { var user = trader; var userID = user.Id; var name = user.Username; var trainer = new PokeTradeTrainerInfo(trainerName); var notifier = new DiscordTradeNotifier <PK8>(pk8, trainer, code, Context, user); var detail = new PokeTradeDetail <PK8>(pk8, trainer, notifier, t, code, userID, sig == RequestSignificance.Favored, requestedIgn); 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.Favored); 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.LanTrade || t == PokeTradeType.Specific || t == PokeTradeType.EggRoll && Info.Hub.Config.Discord.DisplayPokeName && 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}")}{(pk8.IsEgg && t != PokeTradeType.EggRoll ? " (Egg)" : "")}."; } if (t == PokeTradeType.LanRoll && Info.Hub.Config.Discord.DisplayPokeName && pk8.Species != 0) { pokeName = $" Receiving: An Illegal Egg."; } string overallPosition = ""; if (Info.Hub.Config.Discord.PostOverallQueueCount) { if (position.QueueCount != position.OverallQueueCount) { if (type == PokeRoutineType.SeedCheck && hub.Config.Queues.FlexMode == FlexYieldMode.LessCheatyFirst) { overallPosition = $" | __Overall: {position.Position}/{position.OverallQueueCount}__"; } else { overallPosition = $" | __Overall: {position.OverallPosition}/{position.OverallQueueCount}__"; } } else { overallPosition = $""; } } var ignName = ""; if (t == PokeTradeType.LanTrade || t == PokeTradeType.LanRoll) { if (requestedIgn != string.Empty) { ignName = $" Looking for {requestedIgn}."; } } msg = $"{user.Mention} - Added to the **{type}** queue{ticketID}. Current Position: __{type}: {position.Position}/{position.QueueCount}__{overallPosition}.{pokeName}{ignName}"; 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); }