示例#1
0
        public override MessageResponse HandleMessage(string[] args, SocketUserMessage message)
        {
            if (args.Length == 0 || args[0] != "!fueldbg")
            {
                return(MessageResponse.NotHandled());
            }

            if (args.Length < 2)
            {
                return(MessageResponse.Handled("Please specify a valid station or system name."));
            }
            var stationOrSystemName = string.Join(' ', args.Skip(1));

            var sotherynFuelService = _serviceProvider.GetRequiredService <ISotherynPriceTrackerService>();
            var approximations      = sotherynFuelService.GetFuelPricesDebug(stationOrSystemName);

            if (approximations == null || approximations.Count() == 0)
            {
                return(MessageResponse.Handled("Sorry, no results found. Please try again."));
            }
            var resultBuilder = new StringBuilder(string.Format("Found {0} fuel price(s):\n", approximations.Count()));

            foreach (var fuelInfo in approximations)
            {
                resultBuilder.AppendFormat("Station {0}: {1}\n",
                                           fuelInfo.Key,
                                           fuelInfo.Value);
            }
            return(MessageResponse.Handled(resultBuilder.ToString()));
        }
示例#2
0
 public override MessageResponse HandleMessage(string[] args, SocketUserMessage message)
 {
     if (args.Length < 1)
     {
         return(MessageResponse.NotHandled());
     }
     if (args[0] != "!campaign")
     {
         return(MessageResponse.NotHandled());
     }
     if (args.Length == 1) // Just campaign info
     {
         using (var scope = _serviceProvider.CreateScope())
         {
             var campaignLogic = scope.ServiceProvider.GetRequiredService <ICampaignLogic>();
             var nextCamp      = campaignLogic.GetNextCampaignByDiscordLogin(message.FullDiscordAuthorLogin());
             if (nextCamp == null)
             {
                 return(MessageResponse.Handled("No future campaign(s) found for your syndicate or account not connected."));
             }
             return(MessageResponse.HandledFormat("Syndicate [{0}] has its next campaign planned at {1} ({2} UTC), at {3}.\nIt will be T{4} {5} campaign, organized by {6}.",
                                                  nextCamp.Syndicate.Tag,
                                                  nextCamp.GCTDateString,
                                                  nextCamp.UTCDateString,
                                                  nextCamp.Station,
                                                  nextCamp.TiersString,
                                                  nextCamp.Difficulty,
                                                  nextCamp.Manager.Name
                                                  ));
         }
     }
     return(MessageResponse.NotHandled());
 }
示例#3
0
 public override MessageResponse HandleMessage(string[] args, SocketUserMessage message)
 {
     if (args.Length != 2)
     {
         return(MessageResponse.NotHandled());
     }
     if (args[0] != "!subscribe")
     {
         return(MessageResponse.NotHandled());
     }
     // int flags;
     // if (!int.TryParse(args[1], out flags)) return MessageResponse.Handled("Invalid flag parameter.");
     // var service = _serviceProvider.GetRequiredService<IRegisteredDiscordUsersService>();
     // var fullName = message.Author.Username + "#" + message.Author.Discriminator;
     // if (!service.IsUserRegistered(fullName))
     // {
     //     return MessageResponse.Handled("Please use !connect command first.");
     // }
     // using (var scope = _serviceProvider.CreateScope())
     // {
     //     var playerLogic = scope.ServiceProvider.GetRequiredService<IPlayerLogic>();
     //     if (!playerLogic.SetPlayerNotificationByDiscord(fullName, flags))
     //     {
     //         return MessageResponse.Handled("Subscription request failed, please re-check your flags or contact Dotsent.");
     //     }
     // }
     return(MessageResponse.Handled("This command is deprecated. Please use the settings page at https://dotsent.nl/Settings/Discord instead."));
 }
示例#4
0
        public override MessageResponse HandleMessage(string[] args, SocketUserMessage message)
        {
            if (args.Length != 2)
            {
                return(MessageResponse.NotHandled());
            }
            if (args[0] != "!connect")
            {
                return(MessageResponse.NotHandled());
            }
            var playerName = args[1];

            using (var scope = _serviceProvider.CreateScope())
            {
                var playerLogic = scope.ServiceProvider.GetRequiredService <IPlayerLogic>();
                var fullName    = message.Author.Username + "#" + message.Author.Discriminator;
                var result      = playerLogic.RequestPlayerDiscordLink(playerName, fullName);
                if (string.IsNullOrEmpty(result))
                {
                    return(MessageResponse.Handled("Subscription request failed. Possible causes: player name is not registered or the account is already connected. If the problem persists, please contact Dotsent."));
                }
                return(MessageResponse.HandledFormat("Please follow this link to connect your Discord and Manager profiles: https://dotsent.nl/Settings/ConnectDiscordAccount?login={0}%23{1}&authCode={2}",
                                                     message.Author.Username,
                                                     message.Author.Discriminator,
                                                     result));
            }
        }
示例#5
0
        public override MessageResponse HandleMessage(string[] args, SocketUserMessage message)
        {
            if (args.Length != 1)
            {
                return(MessageResponse.NotHandled());
            }
            if (args[0] != "!help")
            {
                return(MessageResponse.NotHandled());
            }
            return(MessageResponse.Handled(@"
Hello, I'm friendly TauManager Bot! *(Don't mind my avatar, I told you I'm friendly, so I am)*

I accept the following commands:

* !help - this command, lists help on all commands
* !connect *player_name* - connect your Discord account with your Manager account, needed if you want to setup notifications
* !disconnect - disconnect your Discord account from any Manager accounts it might be connected to
* !stats *syndicate_tag* - lists current statistics by tier for a given syndicate tag (if found)
* !fuel *station_or_system_tag* - lists last recorded fuel price at the given station or system
* !ration - gives the last recorded price of Tier 1 Ration at CSH vendors
* !subscribe *number* - Deprecated. Please use the settings page at https://dotsent.nl/Settings/Discord instead

Still got questions? Ping Dotsent!"));
        }
示例#6
0
        public override MessageResponse HandleMessage(string[] args, SocketUserMessage message)
        {
            if (args.Length == 0 || args[0] != "!stats")
            {
                return(MessageResponse.NotHandled());
            }

            if (args.Length != 2)
            {
                return(MessageResponse.Handled("Please specify a valid syndicate tag."));
            }
            var syndicateTag = args[1];

            using (var scope = _serviceProvider.CreateScope())
            {
                var dbContext = scope.ServiceProvider.GetRequiredService <TauDbContext>();
                var syndicate = dbContext.Syndicate.SingleOrDefault(s => syndicateTag.ToLower() == s.Tag.ToLower());
                if (syndicate == null)
                {
                    return(MessageResponse.HandledFormat("Can't find the syndicate with tag '{0}'", syndicateTag));
                }
                else
                {
                    var playerLogic      = scope.ServiceProvider.GetRequiredService <IPlayerLogic>();
                    var syndicateMetrics = playerLogic.GetSyndicatePlayers(null, false, syndicate.Id);
                    var messageBuilder   = new StringBuilder("Average stats for syndicate ");
                    messageBuilder.Append(syndicate.Tag);
                    messageBuilder.AppendLine();
                    messageBuilder.Append("```");
                    messageBuilder.AppendLine("Tier | Players |  Total avg (STR/AGI/STA)  | TS median");
                    messageBuilder.AppendLine("-----+---------+---------------------------+----------");
                    foreach (var tier in syndicateMetrics.PlayerStats.Keys.OrderByDescending(k => k))
                    {
                        var tierStats = syndicateMetrics.PlayerStats[tier];
                        messageBuilder.AppendFormat("  {0}  |    {1,2:d}   | {2,4:d} ({3,4:d} / {4,4:d} / {5,4:d}) |  {6,4:d}",
                                                    tierStats.Tier,
                                                    tierStats.PlayerCount,
                                                    (int)Math.Round(tierStats.StatTotal),
                                                    (int)Math.Round(tierStats.Strength),
                                                    (int)Math.Round(tierStats.Agility),
                                                    (int)Math.Round(tierStats.Stamina),
                                                    (int)Math.Round(tierStats.StatTotalMedian));
                        messageBuilder.AppendLine();
                    }
                    messageBuilder.Append("```");
                    return(MessageResponse.Handled(messageBuilder.ToString()));
                }
            }
        }
示例#7
0
        public override MessageResponse HandleMessage(string[] args, SocketUserMessage message)
        {
            if (args.Length != 1 || args[0] != "!ration")
            {
                return(MessageResponse.NotHandled());
            }

            var rationService = _serviceProvider.GetRequiredService <IRationInfoService>();
            var result        = rationService.GetCurrentPricePerTier();

            if (result == 0)
            {
                return(MessageResponse.Handled("Sorry, can't parse the ration price. Please try again later."));
            }
            return(MessageResponse.HandledFormat("Current Tier 1 Ration price on CSH: {0,7:F2} c", result));
        }
示例#8
0
        public override MessageResponse HandleMessage(string[] args, SocketUserMessage message)
        {
            if (args.Length == 0 || args[0] != "!fuel")
            {
                return(MessageResponse.NotHandled());
            }

            if (args.Length < 2)
            {
                return(MessageResponse.Handled("Please specify a valid station or system name."));
            }
            var stationOrSystemName = string.Join(' ', args.Skip(1));
            var fuelService         = _serviceProvider.GetRequiredService <IFuelTrackerService>();
            var result = fuelService.GetPrices(stationOrSystemName);

            if (result == null || result.Count() == 0)
            {
                var allSystemNames     = fuelService.GetValidSystemNames();
                var allSystemShortcuts = fuelService.GetValidSystemShortcuts();
                return(MessageResponse.HandledFormat("No results found for system or station name '{0}'. Valid system names are: {1} or shortcuts: {2}.",
                                                     stationOrSystemName,
                                                     String.Join(", ", allSystemNames),
                                                     String.Join(", ", allSystemShortcuts)
                                                     ));
            }
            var resultBuilder = new StringBuilder(string.Format("Found {0} fuel price(s):\n", result.Count()));

            resultBuilder.AppendLine("```");
            resultBuilder.AppendLine("┌──────────┬─────────┬──────────────────────┬─────────┐");
            resultBuilder.AppendLine("│  Station │  Price  │       Recorded       │   Est.  │");
            resultBuilder.AppendLine("├──────────┼─────────┼──────────────────────┼─────────┤");
            foreach (var fuelInfo in result)
            {
                resultBuilder.AppendFormat("│ {0,8} │ {1} │ {2} │ {3,7:F2} │",
                                           fuelInfo.Station_Short_Name,
                                           fuelInfo.Last_Price < 1 ? "  N/A  " : String.Format("{0,7:F2}", fuelInfo.Last_Price),
                                           fuelInfo.Last_Price < 1 ? "    --outdated--    " : String.Format("{0:u}", fuelInfo.Last_Reading),
                                           fuelInfo.Estimation.HasValue ?
                                           String.Format("{0,7:F2}", (double)fuelInfo.Estimation.Value) :
                                           "   N/A");
                resultBuilder.Append("\n");
            }
            resultBuilder.AppendLine("└──────────┴─────────┴──────────────────────┴─────────┘");
            resultBuilder.AppendLine("```");
            resultBuilder.Append("*Credits: data - moritz' TauTracker; approximation logic - Sotheryn; Python implementation - SandwichMaker*");
            return(MessageResponse.Handled(resultBuilder.ToString()));
        }
示例#9
0
 public override MessageResponse HandleMessage(string[] args, SocketUserMessage message)
 {
     if (args.Length != 1)
     {
         return(MessageResponse.NotHandled());
     }
     if (args[0] != "!disconnect")
     {
         return(MessageResponse.NotHandled());
     }
     using (var scope = _serviceProvider.CreateScope())
     {
         var playerLogic = scope.ServiceProvider.GetRequiredService <IPlayerLogic>();
         var fullName    = message.Author.Username + "#" + message.Author.Discriminator;
         var result      = playerLogic.DisconnectDiscordAccountByDiscordLogin(fullName);
         if (!result)
         {
             return(MessageResponse.Handled("Failed to disconnect your account: maybe it's not connected? If the problem persists, please contact Dotsent."));
         }
         return(MessageResponse.HandledFormat("Your Discord account has been successfully disconnected. Please use !connect <player_name> if you want to reconnect."));
     }
 }
示例#10
0
 public override MessageResponse HandleMessage(string[] args, SocketUserMessage message)
 {
     if (args.Length < 2)
     {
         return(MessageResponse.NotHandled());
     }
     if (args[0] != "!admin")
     {
         return(MessageResponse.NotHandled());
     }
     if (message.Author.Username != "Dotsent" || message.Author.DiscriminatorValue != 5616)
     {
         return(MessageResponse.NotHandled());
     }
     if (args[1] == "officer")
     {
         if (args.Length < 3)
         {
             return(MessageResponse.NotHandled());
         }
         var officerListService = _serviceProvider.GetRequiredService <IRegisteredDiscordUsersService>();
         if (args[2] == "list")
         {
             var officerList = new StringBuilder();
             foreach (var officer in officerListService.GetOfficers())
             {
                 officerList.AppendLine(officer);
             }
             return(MessageResponse.HandledFormat("Current officers in Discord: \n{0}", officerList));
         }
         else if (args[2] == "add" && args.Length == 4)
         {
             var result = officerListService.AddOfficer(args[3]);
             if (result)
             {
                 return(MessageResponse.Handled("Officer added OK."));
             }
             return(MessageResponse.Handled("Officer addition failed."));
         }
         else if (args[2] == "remove" && args.Length == 4)
         {
             var result = officerListService.RemoveOfficer(args[3]);
             if (result)
             {
                 return(MessageResponse.Handled("Officer removed OK."));
             }
             return(MessageResponse.Handled("Officer removal failed."));
         }
         else if (args[2] == "reload")
         {
             officerListService.ReloadOfficers();
             return(MessageResponse.Handled("Officer list reloaded from DB."));
         }
     }
     else if (args[1] == "say")
     {
         if (args.Length < 4)
         {
             return(MessageResponse.NotHandled());
         }
         ulong channelId = 0;
         var   result    = ulong.TryParse(args[2], out channelId);
         if (!result)
         {
             return(MessageResponse.Handled("Sorry, boss, can't parse the channel id!"));
         }
         return(MessageResponse.Handled(string.Join(' ', args.Skip(3)), channelId));
     }
     return(MessageResponse.Handled("Sorry, boss, I don't get it!"));
 }