Exemplo n.º 1
0
        public ServiceInfo GetServiceInfo()
        {
            var proc = Process.GetCurrentProcess();

            return(new ServiceInfo
            {
                ServiceName = _hostingEnvironment.ApplicationName,
                Environment = _hostingEnvironment.EnvironmentName,
                ProcessName = proc.ProcessName,
                StartTime = proc.StartTime,
                CommandSuccesses = _messageReceiver.CommandSuccesses,
                CommandFailures = _messageReceiver.CommandFailures,
                Guilds = _discord.Guilds.Count,
                Users = _discord.Guilds.Select(a => a.MemberCount).Sum(),
                Channels = _discord.Guilds.Select(a => a.TextChannels.Count + a.VoiceChannels.Count).Sum(),
                Modules = _commandService.GetAllModules().Count,
                Commands = _commandService.GetAllCommands().Count,
                OperatingSystem = Environment.OSVersion.VersionString,
                MachineName = Environment.MachineName,
                ProcessorCount = Environment.ProcessorCount,
                CurrentThreadId = Environment.CurrentManagedThreadId,
                RuntimeVersion = Environment.Version.ToString(),
                Culture = CultureInfo.InstalledUICulture.EnglishName,
                ContentRootPath = _hostingEnvironment.ContentRootPath,
                AddonsLoaded = _addons.GetAllAddons().Count
            });
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Command_GetAbyssInfoAsync()
        {
            var dotnetVersion =
                Assembly.GetEntryAssembly()?.GetCustomAttribute <TargetFrameworkAttribute>()?.FrameworkName ??
                ".NET Core";

            var app = await Context.Client.GetApplicationInfoAsync().ConfigureAwait(false);

            var response = new EmbedBuilder
            {
                ThumbnailUrl = Context.Client.CurrentUser.GetEffectiveAvatarUrl(),
                Description  = string.IsNullOrEmpty(app.Description) ? "None" : app.Description,
                Author       = new EmbedAuthorBuilder
                {
                    Name    = $"Information about {_config.Name}",
                    IconUrl = Context.Bot.GetEffectiveAvatarUrl()
                }
            };

            response
            .AddField("Uptime", DateTime.Now - Process.GetCurrentProcess().StartTime)
            .AddField("Heartbeat", Context.Client.Latency + "ms", true)
            .AddField("Commands", _commandService.GetAllCommands().Count(), true)
            .AddField("Modules", _commandService.GetAllModules().Count(), true)
            .AddField("Source", $"https://github.com/abyssal512/Abyss");

            if (!string.IsNullOrWhiteSpace(_config.Connections.Discord.SupportServer))
            {
                response.AddField("Support Server", _config.Connections.Discord.SupportServer, true);
            }

            response
            .AddField("Language",
                      $"C# 7.1 ({dotnetVersion})")
            .AddField("Libraries", $"Discord.Net {DiscordConfig.Version} w/ Qmmands");

            return(Ok(response));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Command_ListCommandsAsync(
            [Name("Query")]
            [Description("The command or module to view, or nothing to see a list of commands.")]
            [Remainder]
            string query = null)
        {
            if (query != null)
            {
                // Searching for command or module
                var search = _commandService.FindCommands(query).ToList();
                if (search.Count == 0)
                {
                    // Searching for module
                    var module = _commandService.GetAllModules().Search(query.Replace("\"", ""));
                    if (module == null)
                    {
                        return(BadRequest($"No module or command found for `{query}`."));
                    }

                    var embed0 = new EmbedBuilder
                    {
                        Timestamp = DateTimeOffset.Now,
                        Color     = BotService.DefaultEmbedColour,
                        Title     = $"Module '{module.Name}'"
                    };

                    if (!string.IsNullOrWhiteSpace(module.Description))
                    {
                        embed0.Description = module.Description;
                    }

                    if (module.Parent != null)
                    {
                        embed0.AddField("Parent", module.Parent.Aliases.FirstOrDefault());
                    }

                    var commands = module.Commands.Where(a => !a.HasAttribute <HiddenAttribute>()).ToList();

                    embed0.AddField("Commands",
                                    commands.Count > 0
                            ? string.Join(", ", commands.Select(a => a.Aliases.FirstOrDefault())) + " (" +
                                    commands.Count + ")"
                            : "None (all hidden)");

                    return(Ok(embed0));
                }

                foreach (var embed0 in await Task.WhenAll(search.Select(a =>
                                                                        _help.CreateCommandEmbedAsync(a.Command, Context))).ConfigureAwait(false))
                {
                    await Context.Channel.SendMessageAsync(string.Empty, false, embed0).ConfigureAwait(false);
                }

                return(Empty());
            }

            var prefix = Context.GetPrefix();

            var embed = new EmbedBuilder();

            embed.WithAuthor(Context.BotUser);

            embed.WithDescription(
                $"Use `{prefix}help <command>` for more details on a command.");

            embed.WithFooter(
                $"You can use \"{prefix}help <command name>\" to see help on a specific command.",
                Context.BotUser.GetAvatarUrl());

            foreach (var module in _commandService.GetAllModules().Where(module =>
                                                                         !module.HasAttribute <HiddenAttribute>()))
            {
                var list         = new List <string>();
                var seenCommands = new List <string>();
                foreach (var command in module.Commands.Where(command => !command.HasAttribute <HiddenAttribute>()))
                {
                    if (!await CanShowCommandAsync(command).ConfigureAwait(false))
                    {
                        continue;
                    }
                    if (seenCommands.Contains(command.FullAliases[0]))
                    {
                        continue;
                    }
                    seenCommands.Add(command.FullAliases[0]);
                    list.Add(FormatCommandShort(command));
                }

                if (list.Count > 0)
                {
                    embed.AddField(string.IsNullOrWhiteSpace(module.Name) ? "[Internal Error]" : module.Name,
                                   string.Join(", ", list), true);
                }
            }

            return(Ok(embed));
        }