internal static void RegisterPluginTrigger(string Trigger, CogitoPlugin Plugin) { if (!Trigger.StartsWith(AppSettings.TriggerPrefix)) { Trigger.Insert(0, AppSettings.TriggerPrefix); } AITriggers.Add(Trigger, Plugin); Core.SystemLog.Log(String.Format("Added trigger {0} for Delegate {1}", Trigger, Plugin.Name)); }
internal static void ProcessPossibleCommand(Message m) { AccessPath accesspath = new AccessPath(); string TargetMethod = m.Args[0]; if (m.sourceChannel != null) { //if (m.sourceChannel.Mods.Select(n => n._Name).Contains(m.sourceUser._Name)) { m.AccessLevel++; } if (m.sourceChannel.Mods.Contains(m.sourceUser)) { m.AccessLevel++; } accesspath = AccessPath.ChannelOnly; } else { accesspath = AccessPath.PMOnly; } if (TargetMethod.StartsWith(Config.AppSettings.TriggerPrefix) && Config.AITriggers.ContainsKey(TargetMethod)) { m.Args = m.Args.Skip(1).ToArray(); //remove Trigger if (m.Args.Length >= 2) { int chanIndex = -1; if (m.Args[m.Args.Length - 2] == Config.AppSettings.RedirectOperator && int.TryParse(m.Args[m.Args.Length - 1], out chanIndex)) { if (chanIndex <= Core.joinedChannels.Count) { m.sourceChannel = Core.joinedChannels[chanIndex]; } m.Args = m.Args.Take(m.Args.Length - 2).ToArray(); } } if (Core.globalOps.Contains(m.sourceUser)) { m.AccessLevel = AccessLevel.GlobalOps; } if (Core.Ops.Contains(m.sourceUser.Name)) { m.AccessLevel = AccessLevel.RootOnly; } try { CogitoPlugin AIMethod = Config.AITriggers[TargetMethod]; if (m.AccessLevel >= AIMethod.AccessLevel && accesspath >= AIMethod.AccessPath) { if (m.AccessLevel >= AccessLevel.ChannelOps) { if (m.sourceChannel != null) { m.sourceChannel.ChannelModLog.Log(string.Format("Executing command {0} by order of {1} [{2}], channel {3}. Args: {4}", TargetMethod, m.sourceUser.Name, m.AccessLevel, m.sourceChannel.Name, m.Body)); } else { Core.ModLog.Log(string.Format("Executing command {0} by order of {1} [{2}], via PM. Args: '{3}'", TargetMethod, m.sourceUser.Name, m.AccessLevel, m.Body)); } } AIMethod.PluginMethod(m); } else { if (AIMethod.AccessLevel == AccessLevel.ChannelOps && m.sourceChannel.Mods.Select(x => x.Name.ToLowerInvariant()).Contains(m.sourceUser.Name.ToLowerInvariant())) { m.Reply("The mod list for channel '" + m.sourceChannel.Name + "' does not appear to contain your character name in the correct capitalization. This is an error with [b]Fserv/FList[/b] (which doesn't check capitalization when making someone a mod), [u][b]not[/b][/u] Cogito.\nF-List will probably not recognize you as a mod (test this by trying to kick someone willing).\nPlease contact the channel owner/another moderator, demod the bad entry, and get modded with the right capitalisation.\nWe apologise for any inconvenience.\n\nCurrent modlist:" + string.Join("\n\t", m.sourceChannel.Mods.Select(x => x.Name))); } else { m.Reply(string.Format("You do not have the neccessary access permissions to execute {0} in channel {1}. Check channel modlist for capitalisation, or contact Cogito's owner (see profile).", TargetMethod, m.sourceChannel.Name)); } } } catch (KeyNotFoundException NoMethod) { Core.ErrorLog.Log(string.Format("Invocation of Bot Method {0} failed, as the method is not registered in the AITriggers.Triggers dictionary or does not exist:\n\t{1}\n\t{2}", m.OpCode, NoMethod.Message, NoMethod.InnerException)); } catch (TargetException NoMethod) { Core.ErrorLog.Log(string.Format("Invocation of Bot Method {0} failed, as the method does not exist:\n\t{1}\n\t{2}", m.OpCode, NoMethod.Message, NoMethod.InnerException)); } catch (ArgumentException WrongData) { Core.ErrorLog.Log(string.Format("Invocation of Bot Method {0} failed, due to a wrong argument:\n\t{1}\n\t{2}", m.OpCode, WrongData.Message, WrongData.InnerException)); } catch (Exception FuckUp) { Core.ErrorLog.Log(string.Format("Invocation of Bot Method {0} failed due to an unexpected error:\n\t{1}\n\t{2}", m.OpCode, FuckUp.Message, FuckUp.InnerException)); } } else { OnChatMessage(m); } //raise MessageEvent to signal to plugins ~eine nachricht has arrived~ }
internal static void LoadPlugins() { List <string> dllFileNames = new List <string>(); if (Directory.Exists(Config.AppSettings.PluginsPath)) { dllFileNames.AddRange(Directory.GetFiles(Config.AppSettings.PluginsPath, "*.dll")); } if (dllFileNames.Count > 0) { Type CSPluginType = typeof(CogitoPlugin); ICollection <Type> CSPluginTypes = new HashSet <Type>(); foreach (string filename in dllFileNames) { Assembly a = Assembly.LoadFile(filename); if (a != null) { Type[] types = a.GetTypes(); foreach (Type t in types) { if (t.IsInterface || t.IsAbstract) { continue; } else { if (t.GetInterface(CSPluginType.FullName) != null) { CSPluginTypes.Add(t); } } } //foreach Type t } // a != null } //foreach filename foreach (Type _t in CSPluginTypes) { CogitoPlugin plugin = (CogitoPlugin)Activator.CreateInstance(_t); if (!PluginStore.ContainsKey(plugin.Name)) //no duplicates, no overwrites. { PluginStore.Add(plugin.Name, plugin); //registers name -> Plugin Config.AITriggers.Add(plugin.Trigger, plugin); } else { Core.ErrorLog.Log("Attempted to load duplicate plugin, type '" + plugin.Name + "'."); } } } AddInternalPlugin <Admin>(); AddInternalPlugin <Horoscopes>(); AddInternalPlugin <Ignore>(); AddInternalPlugin <ListChannels>(); AddInternalPlugin <Minage>(); AddInternalPlugin <ModQueue>(); AddInternalPlugin <RainbowText>(); AddInternalPlugin <Remote>(); AddInternalPlugin <Scan>(); AddInternalPlugin <Shutdown>(); AddInternalPlugin <Whitelist>(); AddInternalPlugin <YouTube>(); }