示例#1
0
        public async Task MainAsync(string apiToken, CancellationToken token)
        {
            // Centralize the logic for commands into a separate method.
            await InitCommands().ConfigureAwait(false);

            // Login and connect.
            await _client.LoginAsync(TokenType.Bot, apiToken).ConfigureAwait(false);

            await _client.StartAsync().ConfigureAwait(false);

            // Restore Echoes
            await Task.Delay(5_000, token).ConfigureAwait(false);

            EchoModule.RestoreChannels(_client);

            // Restore Logging
            await Task.Delay(5_000, token).ConfigureAwait(false);

            LogModule.RestoreLogging(_client);
            TradeStartModule.RestoreTradeStarting(_client);

            var game = SysCordInstance.Settings.BotGameStatus;

            if (!string.IsNullOrWhiteSpace(game))
            {
                await _client.SetGameAsync(game).ConfigureAwait(false);
            }

            var app = await _client.GetApplicationInfoAsync().ConfigureAwait(false);

            SysCordInstance.Manager.Owner = app.Owner.Id;

            // Wait infinitely so your bot actually stays connected.
            await MonitorStatusAsync(token).ConfigureAwait(false);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#6
0
        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);
        }