Ejemplo n.º 1
0
    [RequireOwner] // Only for owners, as this is sensitive information meant for debugging.
    public async Task GetIpAddress()
    {
        using var setTyping = Context.Channel.EnterTypingState();

        var criteria = new InfoCriteria()
        {
            InfoRequest = InfoRequest.IpAddress
        };

        var result = await _infoManager.GetInfo(criteria);

        await ReplyAsync($"My current public IP Address is `{result.IpAddress}`.");
    }
Ejemplo n.º 2
0
    public async Task <InfoResult> GetInfo(InfoCriteria criteria)
    {
        _logger.LogDebug("Getting info for '[InfoRequest]'.", GetFlags(criteria.InfoRequest));

        var result = new InfoResult();

        try
        {
            var tasks = new List <Task>();

            if (criteria.InfoRequest.HasFlag(InfoRequest.IpAddress))
            {
                tasks.Add(_publicIpAccessor.GetIp().ContinueWith(data => result.IpAddress = data.Result.Ip));
            }

            await Task.WhenAll(tasks);
        }
        catch (Exception ex)
        {
            _logger.LogWarning(ex, "Exception occured while gathering info.");
        }

        return(result);
    }