private void OnCommandLoaded(string name, bool success, DBPlugin command, Exception exception) { if (onCMDLoad != null) { onCMDLoad.Invoke(name, success, exception); } }
public List <DBPlugin> LoadCommands() { if (!Directory.Exists(CMDPath)) { Directory.CreateDirectory(CMDPath); return(null); } string[] files = Directory.GetFiles(CMDPath, $"*{CMDExtension}", SearchOption.AllDirectories); foreach (var file in files) { Assembly.LoadFile(Path.GetFullPath(file)); if (OnCommandFileLoaded != null) { OnCommandFileLoaded.Invoke(file); } } List <DBPlugin> plugins = new List <DBPlugin>(); try { Type interfaceType = typeof(DBPlugin); Type[] types = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(a => a.GetTypes()) .Where(p => interfaceType.IsAssignableFrom(p) && p.IsClass) .ToArray(); foreach (Type type in types) { try { DBPlugin plugin = (DBPlugin)Activator.CreateInstance(type); plugins.Add(plugin); if (OnCommandLoaded != null) { OnCommandLoaded.Invoke(type.FullName, true, plugin); } } catch (Exception e) { if (OnCommandLoaded != null) { OnCommandLoaded.Invoke(type.FullName, false, null, e); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); return(null); } return(plugins); }
private async Task MessageHandler(SocketMessage Message) { if (Message as SocketUserMessage == null) { return; } var message = Message as SocketUserMessage; int argPos = 0; if (message.HasMentionPrefix(client.CurrentUser, ref argPos)) { await message.Channel.SendMessageAsync("Can not exec mentioned commands !"); return; } if (!(message.HasCharPrefix(botPrefix, ref argPos) || message.Author.IsBot)) { return; } var context = new SocketCommandContext(client, message); await commandService.ExecuteAsync( context : context, argPos : argPos, services : null ); DBPlugin plugin = PluginLoader.Plugins.Where(p => p.Command == (message.Content.Split(' ')[0]).Substring(1)).FirstOrDefault(); if (plugin != null) { plugin.Execute(context, message, client); Functions.WriteLogFile("Executed command : " + plugin.Command); } }
public DBConfigForm(DBPlugin DBPlugin) { InitializeComponent(); this.DBPlugin = DBPlugin; }