예제 #1
0
        public async Task ListServices()
        {
            EmbedBuilder builder = new EmbedBuilder();

            Type type  = typeof(IBotService);
            var  types = AppDomain.CurrentDomain.GetAssemblies()
                         .SelectMany(s => s.GetTypes())
                         .Where(p => type.IsAssignableFrom(p))
                         .Where(p => p.IsClass);


            foreach (var service in types)
            {
                Attribute[]    attributes = Attribute.GetCustomAttributes(service);
                BotServiceInfo info       = null;
                foreach (var attr in attributes)
                {
                    if (attr is BotServiceInfo serviceInfo)
                    {
                        builder.AddField(serviceInfo.Name,
                                         $"Desc: \"{serviceInfo.About}\"\n" +
                                         $"Priority: {serviceInfo.Priority.ToString()}");
                    }
                }
            }

            await ReplyAsync("", false, builder.Build());
        }
예제 #2
0
파일: Logger.cs 프로젝트: DrogonMar/ZomoBot
        public static void Log(this IBotService obj, string message)
        {
            BotServiceInfo info = (BotServiceInfo)Attribute.GetCustomAttribute(obj.GetType(), typeof(BotServiceInfo));

            if (info != null)
            {
                Write(info.Name, message);
            }
        }