コード例 #1
0
        private static async Task SearchForObjectByNameAsync(ReceivedMessage receivedMessage, Match regexMatch, SimbadClient simbadClient)
        {
            var objectName  = regexMatch.Groups["AstroObject"].Value;
            var foundObject = simbadClient.FindObjectByName(objectName);

            if (foundObject == null)
            {
                WriteObjectNotFound(receivedMessage, objectName);
                return;
            }

            await WriteObjectDetailsEmbeddedAsync(receivedMessage, foundObject).ConfigureAwait(false);
        }
コード例 #2
0
        private static async Task SearchForObjectsAroundRaDecAsync(ReceivedMessage receivedMessage, Match regexMatch, SimbadClient simbadClient)
        {
            RaDecCoordinate centerCoordinates = null;
            const float     radiusInDegrees   = 0.5f;

            try
            {
                if (regexMatch.Groups["CenterOfSearchRA"].Success)
                {
                    centerCoordinates = new RaDecCoordinate(
                        double.Parse(regexMatch.Groups["CenterOfSearchRA"].Value, CultureInfo.InvariantCulture),
                        double.Parse(regexMatch.Groups["CenterOfSearchDEC"].Value, CultureInfo.InvariantCulture));
                }
                else if (regexMatch.Groups["CenterOfSearchName"].Success)
                {
                    var name = regexMatch.Groups["CenterOfSearchName"].Value;
                    var queryAroundObject = simbadClient.FindObjectByName(name);
                    if (queryAroundObject == null)
                    {
                        await receivedMessage.Channel.SendMessageAsync($"No object with name {name} found in the SIMBAD databse!").ConfigureAwait(false);

                        return;
                    }

                    centerCoordinates = queryAroundObject.RaDecCoordinate;
                }
            }
            finally
            {
                if (centerCoordinates == null)
                {
                    await receivedMessage.Channel.SendMessageAsync("Could not parse RA/DEC coordinates").ConfigureAwait(false);
                }
            }

            var objectsAroundTarget = simbadClient.QueryAround(centerCoordinates, radiusInDegrees);
            var csvString           = CsvExporter.AstronomicalObjectsToCsv(objectsAroundTarget);
            await receivedMessage.Channel.SendMessageAsync($"Found {objectsAroundTarget.Count} objects around {centerCoordinates} within a radius of {radiusInDegrees}°:").ConfigureAwait(false);

            await receivedMessage.Channel.SendMessageAsync(
                new SendMessage(
                    content : null,
                    new List <Attachment>
            {
                new SendAttachment
                {
                    Name = "queryResult.csv",
                    Content = Encoding.ASCII.GetBytes(csvString)
                }
            })).ConfigureAwait(false);
        }
コード例 #3
0
        public async Task <bool> ExecuteRegexCommandAsync(ReceivedMessage receivedMessage, Match regexMatch)
        {
            if (regexMatch.Groups["ObjectName"].Success)
            {
                var astronomicalObjectName = regexMatch.Groups["ObjectName"].Value;
                var simbadClient           = new SimbadClient();
                var objectResolvedBySimbad = simbadClient.FindObjectByName(astronomicalObjectName);

                if (objectResolvedBySimbad == null)
                {
                    await receivedMessage.Channel.SendMessageAsync($"No object with name {astronomicalObjectName} could be found on simbad!").ConfigureAwait(false);

                    return(true);
                }

                if (objectResolvedBySimbad.RaDecCoordinate == null)
                {
                    await receivedMessage.Channel.SendMessageAsync($"The object was found, but no Ra / Dec coordinates are known for the object!").ConfigureAwait(false);

                    return(true);
                }

                await receivedMessage.Channel.SendMessageAsync("Getting the image from the deep sky survey (DSS) server, one moment...\r\n(The larger the FOV, the longer it takes)").ConfigureAwait(false);

                var arcminutesSize =
                    Math.Max(objectResolvedBySimbad.AngularDimensions != null
                        ? Math.Min(objectResolvedBySimbad.AngularDimensions.MajorAxis * FACTOR_ANGULARSIZE_ARCMINUTES, MAX_ANGULARSIZE_ARCMINUTES)
                        : DEFAULT_ANGULARSIZE_ARCMINUTES,
                             MIN_ANGULARSIZE_ARCMINUTES);

                var image = DeepSkySurvey.DeepSkySurveyClient.GetImage(
                    Convert.ToSingle(objectResolvedBySimbad.RaDecCoordinate.RightAscension),
                    Convert.ToSingle(objectResolvedBySimbad.RaDecCoordinate.Declination),
                    arcminutesSize.ToString(CultureInfo.InvariantCulture));

                await receivedMessage.Channel.SendMessageAsync(new SendMessage(
                                                                   content : $"Image size: {Math.Round(arcminutesSize, 3)}' x {Math.Round(arcminutesSize, 3)}'",
                                                                   new List <Attachment>
                {
                    new SendAttachment
                    {
                        Name = $"{objectResolvedBySimbad.Name}.jpg",
                        Content = image
                    }
                })).ConfigureAwait(false);
            }

            return(true);
        }
コード例 #4
0
 public void TestFindObjectByName()
 {
     var objName      = "M31";
     var simbadClient = new SimbadClient();
     var foundObject  = simbadClient.FindObjectByName(objName);
 }