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()); }
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); } }