예제 #1
0
        public async Task Help()
        {
            EmbedBuilder embedBuilder = new EmbedBuilder();

            foreach (CommandInfo command in _commandService.Commands.ToList())
            {
                if (command.Name.ToLower() == "help")
                {
                    continue;
                }

                var           guildConfig    = GuildConfigFunctions.GetGuildConfig(Context.Guild, _connection);
                StringBuilder embedFieldText = new StringBuilder();
                embedFieldText.Append(command.Summary ?? "No description available\n");
                embedFieldText.Append(" Usage: " + Environment.NewLine);

                var commandInfo = command.Parameters;
                embedFieldText.Append($"```{guildConfig.prefix}{command.Name.ToLower()} {(commandInfo.Count > 0 ? string.Join(' ', commandInfo) : string.Empty)}```");

                embedBuilder.AddField(command.Name, embedFieldText);
            }

            await ReplyAsync(
                message : "Here's a list of commands and their description: ",
                embed : embedBuilder.Build()
                );
        }
예제 #2
0
        private void UpdateGuildConfigs()
        {
            while (true)
            {
                Dictionary <ulong, GuildConfig> Configs = new Dictionary <ulong, GuildConfig>();
                foreach (var guild in _client.Guilds)
                {
                    try
                    {
                        if (GuildConfigFunctions.GuildHasConfig(guild, connection))
                        {
                            Configs.Add(guild.Id, GuildConfigFunctions.GetGuildConfig(guild, connection));
                        }
                        else
                        {
                            GuildConfigFunctions.CreateGuildConfig(guild, connection);

                            List <EmbedFieldBuilder> fields = new List <EmbedFieldBuilder>();
                            fields.Add(new EmbedFieldBuilder
                            {
                                Name  = "**I'm sorry for being late**",
                                Value = $"We had some technical difficulties.\n" +
                                        $"Everything should be normal by now.",
                                IsInline = false
                            });

                            fields.Add(new EmbedFieldBuilder
                            {
                                Name  = "**Please Note**",
                                Value = $"By default, {guild.DefaultChannel.Mention} is the default bot channel.\n" +
                                        $"If you want to change it, type {GlobalData.Config.defaultPrefix}whitelist add #YourTextChannel",
                                IsInline = false
                            });

                            Task.Run(async() =>
                            {
                                await guild.DefaultChannel.SendMessageAsync(embed: await EmbedHandler.CreateCustomEmbed(
                                                                                guild: guild,
                                                                                embedTitle: "Oh oh..",
                                                                                fields: fields,
                                                                                color: Color.DarkTeal,
                                                                                footer: $"Thank you for choosing {guild.CurrentUser.Username}"
                                                                                ));
                            });
                        }
                    }
                    catch (Exception e)
                    {
                        LoggingService.Log("UGC", e.Message, ConsoleColor.Red);
                    }
                }

                //LoggingService.Log("UGC", $"Updated all guild configs ({Configs.Count})");
                _commandHandler.GuildConfigs = Configs;

                Thread.Sleep(GlobalData.Config.cacheUpdateTime);
            }
        }