private static void PluginsCallback(object source, PluginEventArgs e) { switch (e.MessageType) { case PluginEventMessageType.Message: if (e.Result is PluginReturnMessage) { PluginReturnMessage response = (PluginReturnMessage)e.Result; Writer.SendData(response.Protocol, $"{response.Target} {response.Message}"); break; } Writer.Log(e.Result.ToString(), EventLogEntryType.Information); break; case PluginEventMessageType.EventLog: break; case PluginEventMessageType.Action: if (e.EventAction.ActionToTake == PluginActionType.AddCommand) { if (!(e.Result is KeyValuePair<string, string>)) break; var temp = (KeyValuePair<string, string>)e.Result; Commands.Add(temp.Key, temp.Value); } break; default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Intermediary method for activating PluginCallback /// </summary> /// <param name="e"></param> private void OnCallback(PluginEventArgs e) { PluginCallback?.Invoke(this, e); }
/// <summary> /// Is called when ProxyLoader_RaiseCallbackEvent() is triggered, /// sends `Callback's to PluginWrapper for deliberation /// </summary> /// <param name="e"></param> private void OnCallback(PluginEventArgs e) { if (e.MessageType == PluginEventMessageType.Action) { switch (e.EventAction.ActionToTake) { case PluginActionType.None: break; case PluginActionType.Load: break; case PluginActionType.Unload: if (Callback == null) break; e.MessageType = PluginEventMessageType.Message; e.Result = "Unload recieved from plugin."; Callback(this, e); if (!IsShuttingDown) break; bool canTerminate = true; foreach (PluginStatus status in Plugins.Select(plgn => plgn.Instance.Status)) { e.MessageType = PluginEventMessageType.Message; e.Result = $"Unload —— checking for stopped: {status}"; Callback(this, e); if (status == PluginStatus.Stopped) continue; canTerminate = false; break; } if (canTerminate) { CanUnload = true; e.MessageType = PluginEventMessageType.Action; e.EventAction.ActionToTake = PluginActionType.UpdatePlugin; Callback(this, e); } e.MessageType = PluginEventMessageType.Message; e.Result = $"Can terminate: {canTerminate}"; Callback(this, e); break; case PluginActionType.RunProcess: break; case PluginActionType.TerminateAndUnloadPlugins: Writer.Log("UNLOAD ALL RECIEVED — shutting down plugins.", EventLogEntryType.Information); IsShuttingDown = true; // todo tell all plugins to stop if (Callback == null) break; e.MessageType = PluginEventMessageType.Message; e.Result = "UNLOAD ALL RECIEVED — shutting down."; Callback(this, e); e.MessageType = PluginEventMessageType.Action; e.EventAction.ActionToTake = PluginActionType.SignalTerminate; Callback(this, e); break; case PluginActionType.SignalTerminate: break; case PluginActionType.UpdatePlugin: break; case PluginActionType.AddCommand: break; default: throw new ArgumentOutOfRangeException(); } } else Callback?.Invoke(this, e); }
/// <summary> /// Triggers callback /// </summary> /// <param name="source"></param> /// <param name="e"></param> public void ProxyLoader_RaiseCallbackEvent(object source, PluginEventArgs e) { OnCallback(e); }
/// <summary> /// Raises self object callback to be hooked /// padd through callback messages recieved /// </summary> /// <param name="source"></param> /// <param name="e"></param> public void PluginsCallback(object source, PluginEventArgs e) { switch (e.EventAction.ActionToTake) { case PluginActionType.None: break; case PluginActionType.Load: break; case PluginActionType.Unload: break; case PluginActionType.RunProcess: break; case PluginActionType.TerminateAndUnloadPlugins: break; case PluginActionType.SignalTerminate: StopAllPlugins(); break; case PluginActionType.UpdatePlugin: if (AllDomainPluginsStopped()) OnCallback(e); break; case PluginActionType.AddCommand: break; default: OnCallback(e); break; } }
public void OnChannelMessage(object source, ChannelMessageEventArgs e) { Status = PluginStatus.Processing; Console.WriteLine(Program.Bot.Users.GetAll().First().Realname); PluginEventArgs responseEvent = new PluginEventArgs { MessageType = PluginEventMessageType.Message }; PluginReturnMessage response = new PluginReturnMessage(Protocols.PRIVMSG, e.Recipient, string.Empty); switch (e.SplitArgs[1]) { case "eval": if (e.SplitArgs.Count < 3) { response.Message = "Not enough parameters."; responseEvent.Result = response; DoCallback(responseEvent); Status = PluginStatus.Stopped; break; } Status = PluginStatus.Running; string evalArgs = e.SplitArgs.Count > 3 ? e.SplitArgs[2] + e.SplitArgs[3] : e.SplitArgs[2]; try { response.Message = new Calculator().Evaluate(evalArgs).ToString(CultureInfo.CurrentCulture); responseEvent.Result = response; DoCallback(responseEvent); } catch (Exception ex) { response.Message = ex.Message; responseEvent.Result = response; DoCallback(responseEvent); } break; case "join": if (Program.Bot.Users.LastSeen.Access > 1) response.Message = "Insufficient permissions."; else if (e.SplitArgs.Count < 3) response.Message = "Insufficient parameters. Type 'eve help join' to view command's help index."; else if (!e.SplitArgs[2].StartsWith("#")) response.Message = "Channel name must start with '#'."; else if (Program.Bot.Channels.Get(e.SplitArgs[2].ToLower()) != null) response.Message = "I'm already in that channel."; if (!string.IsNullOrEmpty(response.Message)) { responseEvent.Result = response; DoCallback(responseEvent); return; } response.Target = string.Empty; response.Message = e.SplitArgs[2]; response.Protocol = Protocols.JOIN; responseEvent.Result = response; DoCallback(responseEvent); break; } Status = PluginStatus.Stopped; }
public void DoCallback(PluginEventArgs e) { CallbackEvent?.Invoke(this, e); }