public static void Initialize() { ChatCommandsList = new Dictionary <string, BaseChatCommand>(); var typelist = Assembly.GetExecutingAssembly().GetTypes().Where(t => (t != null && t.Namespace != null && t.Namespace.StartsWith("ColonyPlusPlus.Classes.CustomChatCommands"))); foreach (var t in typelist) { try { BaseChatCommand command = ((BaseChatCommand)Activator.CreateInstance(t)); ChatCommandsList.Add(command.ChatCommandPrefix, command); Utilities.WriteLog("Registered chat command: " + command.ChatCommandPrefix); } catch (MissingMethodException mme) { Utilities.WriteLog(t.Name + " cannot be instantiated. This probably isn't an error."); Pipliz.Log.WriteWarning(mme.Message); } catch (InvalidCastException ice) { Utilities.WriteLog(t.Name + " doesn't use our command system. This probably isn't an error."); Pipliz.Log.WriteWarning(ice.Message); } catch (Exception e) { Utilities.WriteLog(t.Name + " Command Error."); Pipliz.Log.WriteWarning(e.Message + e.StackTrace); } } Utilities.WriteLog("Chat Commands Loaded."); }
public override void InvokeScope(OnMessageReceivedArgs e, TwitchClient client) { if (e.ChatMessage.Message.StartsWith("!", StringComparison.InvariantCultureIgnoreCase)) { BaseChatCommand comm = Commands[e.ChatMessage.Message.ToString().Trim().Substring(1)]; if (comm != null) { comm.InvokeCommand(e, client); } } }