public RuntimeCommandEvent(ICommandEvent commandEvent) : base(commandEvent) { CheckCommand = commandEvent?.CheckCommand; Cooldown = commandEvent.Cooldown; GuildPermissions = commandEvent?.GuildPermissions; ProcessCommand = commandEvent?.ProcessCommand; }
private void Init(EventBase evt) { this.eventBaseName = evt.GetType().Name; this.eventTypeId = evt.eventTypeId; this.eventId = evt.eventId; this.triggerEventId = evt.triggerEventId; this.timestamp = evt.timestamp; this.target = evt.target; this.skipElements = evt.skipElements; this.isPropagationStopped = evt.isPropagationStopped; this.isImmediatePropagationStopped = evt.isImmediatePropagationStopped; this.isDefaultPrevented = evt.isDefaultPrevented; IMouseEvent mouseEvent = evt as IMouseEvent; IMouseEventInternal mouseEventInternal = evt as IMouseEventInternal; this.hasUnderlyingPhysicalEvent = (mouseEvent != null && mouseEventInternal != null && mouseEventInternal.triggeredByOS); this.propagationPhase = evt.propagationPhase; this.originalMousePosition = evt.originalMousePosition; this.currentTarget = evt.currentTarget; this.dispatch = evt.dispatch; bool flag = mouseEvent != null; if (flag) { this.modifiers = mouseEvent.modifiers; this.mousePosition = mouseEvent.mousePosition; this.button = mouseEvent.button; this.pressedButtons = mouseEvent.pressedButtons; this.clickCount = mouseEvent.clickCount; } IPointerEvent pointerEvent = evt as IPointerEvent; IPointerEventInternal pointerEventInternal = evt as IPointerEventInternal; this.hasUnderlyingPhysicalEvent = (pointerEvent != null && pointerEventInternal != null && pointerEventInternal.triggeredByOS); bool flag2 = pointerEvent != null; if (flag2) { this.modifiers = pointerEvent.modifiers; this.mousePosition = pointerEvent.position; this.button = pointerEvent.button; this.pressedButtons = pointerEvent.pressedButtons; this.clickCount = pointerEvent.clickCount; } IKeyboardEvent keyboardEvent = evt as IKeyboardEvent; bool flag3 = keyboardEvent != null; if (flag3) { this.character = keyboardEvent.character; this.keyCode = keyboardEvent.keyCode; } ICommandEvent commandEvent = evt as ICommandEvent; bool flag4 = commandEvent != null; if (flag4) { this.commandName = commandEvent.commandName; } }
public RuntimeCommandEvent(ICommandEvent commandEvent) : base(commandEvent) { Aliases = commandEvent.Aliases; Cooldown = commandEvent.Cooldown; GuildPermissions = commandEvent?.GuildPermissions; ProcessCommand = commandEvent?.ProcessCommand; CommandPool = commandEvent?.CommandPool; }
public void AddCommand(ICommandEvent cmd) { foreach (string a in cmd.Aliases) { aliases.Add(a, cmd.Name.ToLower()); } Commands.Add(cmd.Name.ToLower(), cmd); }
void Init(EventBase evt) { eventBaseName = evt.GetType().Name; eventTypeId = evt.eventTypeId; eventId = evt.eventId; triggerEventId = evt.triggerEventId; timestamp = evt.timestamp; target = evt.target; skipElements = evt.skipElements; isPropagationStopped = evt.isPropagationStopped; isImmediatePropagationStopped = evt.isImmediatePropagationStopped; isDefaultPrevented = evt.isDefaultPrevented; IMouseEvent mouseEvent = evt as IMouseEvent; IMouseEventInternal mouseEventInternal = evt as IMouseEventInternal; hasUnderlyingPhysicalEvent = mouseEvent != null && mouseEventInternal != null && mouseEventInternal.triggeredByOS; propagationPhase = evt.propagationPhase; originalMousePosition = evt.originalMousePosition; currentTarget = evt.currentTarget; dispatch = evt.dispatch; if (mouseEvent != null) { modifiers = mouseEvent.modifiers; mousePosition = mouseEvent.mousePosition; button = mouseEvent.button; clickCount = mouseEvent.clickCount; // TODO: Scroll Wheel //delta = mouseEvent.delta; } IKeyboardEvent keyboardEvent = evt as IKeyboardEvent; if (keyboardEvent != null) { character = keyboardEvent.character; keyCode = keyboardEvent.keyCode; } ICommandEvent commandEvent = evt as ICommandEvent; if (commandEvent != null) { commandName = commandEvent.commandName; } }
internal async Task OnCommandDone(IDiscordMessage e, ICommandEvent commandEvent, bool success = true) { foreach (CommandDoneEvent ev in Events.CommandDoneEvents.Values) { MeruUtils.TryAsync(async() => { await ev.processEvent(e, commandEvent, success); }, async(ex) => { Log.ErrorAt($"commanddone@{ev.Name}", ex.Message); }); } }
internal async Task OnCommandDone(IDiscordMessage e, ICommandEvent commandEvent, bool success = true, float time = 0.0f) { foreach (CommandDoneEvent ev in Events.CommandDoneEvents.Values) { try { await ev.processEvent(e, commandEvent, success, time); } catch (Exception ex) { Log.ErrorAt($"commanddone@{ev.Name}", ex.Message); } } }
protected void commandEvent(ICommandEvent item) { try { if (Cmd.exec(item, SolutionEventType.CommandEvent)) { Log.Info("[CommandEvent] finished: '{0}'", item.Caption); } Status._.add(SolutionEventType.CommandEvent, StatusType.Success); } catch (Exception ex) { Log.Error("CommandEvent error: '{0}'", ex.Message); } Status._.add(SolutionEventType.CommandEvent, StatusType.Fail); }
protected void commandEvent(ICommandEvent item) { try { if (Cmd.exec(item, SolutionEventType.CommandEvent)) { Log.Info("[CommandEvent] finished: '{0}'", item.Caption); } Status._.add(SolutionEventType.CommandEvent, StatusType.Success); } catch (Exception ex) { Log.Error($"[{SolutionEventType.CommandEvent}] error: {ex.Message}"); Log.Debug(ex.StackTrace); } Status._.add(SolutionEventType.CommandEvent, StatusType.Fail); }
public async Task SetCommandAsync(EventContext e) { Locale locale = Locale.GetEntity(e.Channel.Id.ToDbLong()); string[] arguments = e.arguments.Split(' '); ICommandEvent command = Bot.instance.Events.CommandHandler.GetCommandEvent(arguments[0]); if (command == null) { await Utils.ErrorEmbed(locale, $"{arguments[0]} is not a valid command").SendToChannel(e.Channel); return; } bool setValue = false; switch (arguments[1]) { case "yes": case "y": case "1": case "true": setValue = true; break; } if (!command.CanBeDisabled) { await Utils.ErrorEmbed(locale, locale.GetString("miki_admin_cannot_disable", $"`{arguments[0]}`")).SendToChannel(e.Channel); return; } if (arguments.Length > 2) { if (arguments.Contains("-s")) { } } await command.SetEnabled(e.Channel.Id, setValue); await Utils.SuccessEmbed(locale, ((setValue) ? locale.GetString("miki_generic_enabled") : locale.GetString("miki_generic_disabled")) + $" {command.Name}").SendToChannel(e.Channel); }
public async Task <bool> TryRunCommandAsync(IDiscordMessage msg, PrefixInstance prefix) { string identifier = await prefix.GetForGuildAsync(msg.Guild.Id); string message = msg.Content.ToLower(); if (msg.Content.StartsWith(identifier)) { message = Regex.Replace(message, @"\r\n?|\n", ""); string command = message .Substring(identifier.Length) .Split(' ') .First(); command = (aliases.ContainsKey(command)) ? aliases[command] : command; ICommandEvent eventInstance = GetCommandEvent(command); if (eventInstance == null) { return(false); } if (GetUserAccessibility(msg) >= eventInstance.Accessibility) { if (await eventInstance.IsEnabled(msg.Channel.Id) || prefix.ForceCommandExecution && GetUserAccessibility(msg) >= EventAccessibility.DEVELOPERONLY) { await eventInstance.Check(msg, this, identifier); return(true); } } else { await eventSystem.OnCommandDone(msg, eventInstance, false); } } return(false); }
protected void commandEvent(ICommandEvent item) { try { if(Cmd.exec(item, SolutionEventType.CommandEvent)) { Log.Info("[CommandEvent] finished: '{0}'", item.Caption); } Status._.add(SolutionEventType.CommandEvent, StatusType.Success); } catch(Exception ex) { Log.Error("CommandEvent error: '{0}'", ex.Message); } Status._.add(SolutionEventType.CommandEvent, StatusType.Fail); }
void Init(EventBase evt) { var type = evt.GetType(); eventBaseName = EventDebugger.GetTypeDisplayName(type); eventTypeId = evt.eventTypeId; eventId = evt.eventId; triggerEventId = evt.triggerEventId; timestamp = evt.timestamp; target = evt.target; skipElements = evt.skipElements; isPropagationStopped = evt.isPropagationStopped; isImmediatePropagationStopped = evt.isImmediatePropagationStopped; isDefaultPrevented = evt.isDefaultPrevented; var mouseEvent = evt as IMouseEvent; var mouseEventInternal = evt as IMouseEventInternal; hasUnderlyingPhysicalEvent = mouseEvent != null && mouseEventInternal != null && mouseEventInternal.triggeredByOS; propagationPhase = evt.propagationPhase; originalMousePosition = evt.originalMousePosition; currentTarget = evt.currentTarget; dispatch = evt.dispatch; if (mouseEvent != null) { modifiers = mouseEvent.modifiers; mousePosition = mouseEvent.mousePosition; button = mouseEvent.button; pressedButtons = mouseEvent.pressedButtons; clickCount = mouseEvent.clickCount; var wheelEvent = mouseEvent as WheelEvent; if (wheelEvent != null) { delta = wheelEvent.delta; } } var pointerEvent = evt as IPointerEvent; if (pointerEvent != null) { var pointerEventInternal = evt as IPointerEventInternal; hasUnderlyingPhysicalEvent = pointerEvent != null && pointerEventInternal != null && pointerEventInternal.triggeredByOS; modifiers = pointerEvent.modifiers; mousePosition = pointerEvent.position; button = pointerEvent.button; pressedButtons = pointerEvent.pressedButtons; clickCount = pointerEvent.clickCount; } IKeyboardEvent keyboardEvent = evt as IKeyboardEvent; if (keyboardEvent != null) { character = keyboardEvent.character; keyCode = keyboardEvent.keyCode; } ICommandEvent commandEvent = evt as ICommandEvent; if (commandEvent != null) { commandName = commandEvent.commandName; } INavigationEvent navigationEvent = evt as INavigationEvent; if (navigationEvent != null) { deviceType = navigationEvent.deviceType; if (evt is NavigationMoveEvent nme) { navigationDirection = nme.direction; } } }
public abstract ICommandEvent Post(ICommandEvent commandEvent);
ICommandRequest <T> IEventSourceSerializer.Deserialize <T>(ICommandEvent commandEvent) { throw new NotImplementedException(); }
public CommandHandlerBuilder AddCommand(ICommandEvent cmd) { commandHandler.AddCommand(cmd); return(this); }
public void RegisterAttributeCommands() { Assembly assembly = Assembly.GetEntryAssembly(); var modules = assembly.GetTypes() .Where(m => m.GetCustomAttributes <ModuleAttribute>().Count() > 0) .ToArray(); foreach (var m in modules) { RuntimeModule newModule = new RuntimeModule(); object instance = null; try { instance = (object)Activator.CreateInstance(Type.GetType(m.AssemblyQualifiedName), newModule); } catch { instance = (object)Activator.CreateInstance(Type.GetType(m.AssemblyQualifiedName)); } newModule.EventSystem = this; ModuleAttribute mAttrib = m.GetCustomAttribute <ModuleAttribute>(); newModule.Name = mAttrib.module.Name.ToLower(); newModule.Nsfw = mAttrib.module.Nsfw; newModule.CanBeDisabled = mAttrib.module.CanBeDisabled; var methods = m.GetMethods() .Where(t => t.GetCustomAttributes <CommandAttribute>().Count() > 0) .ToArray(); foreach (var x in methods) { RuntimeCommandEvent newEvent = new RuntimeCommandEvent(); CommandAttribute commandAttribute = x.GetCustomAttribute <CommandAttribute>(); newEvent = commandAttribute.command; newEvent.ProcessCommand = async(context) => await(Task) x.Invoke(instance, new object[] { context }); newEvent.Module = newModule; ICommandEvent foundCommand = newModule.Events.Find(c => c.Name == newEvent.Name); if (foundCommand != null) { if (commandAttribute.on != "") { foundCommand.On(commandAttribute.On, newEvent.ProcessCommand); } else { foundCommand.Default(newEvent.ProcessCommand); } } else { newModule.AddCommand(newEvent); } } newModule.InstallAsync(bot).GetAwaiter().GetResult(); } }
protected void renderData(ICommandEvent evt) { dgvCEFilters.Rows.Clear(); if(evt.Filters == null) { return; } foreach(IFilter f in evt.Filters) { dgvCEFilters.Rows.Add(f.Guid, f.Id, Value.pack(f.CustomIn), Value.pack(f.CustomOut), f.Description, f.Cancel, f.Pre, f.Post); } }
public async Task HelpAsync(EventContext e) { Locale locale = Locale.GetEntity(e.Channel.Id.ToDbLong()); if (!string.IsNullOrEmpty(e.arguments)) { ICommandEvent ev = Bot.instance.Events.CommandHandler.GetCommandEvent(e.arguments); if (ev == null) { IDiscordEmbed helpListEmbed = Utils.Embed; helpListEmbed.Title = locale.GetString("miki_module_help_error_null_header"); helpListEmbed.Description = locale.GetString("miki_module_help_error_null_message", await Bot.instance.Events.GetPrefixInstance(">").GetForGuildAsync(e.Guild.Id)); helpListEmbed.Color = new Color(1.0f, 0, 0); API.StringComparison.StringComparer comparer = new API.StringComparison.StringComparer(e.commandHandler.GetAllEventNames()); API.StringComparison.StringComparison best = comparer.GetBest(e.arguments); helpListEmbed.AddField(locale.GetString("miki_module_help_didyoumean"), best.text); await helpListEmbed.SendToChannel(e.Channel); } else { if (Bot.instance.Events.CommandHandler.GetUserAccessibility(e.message) < ev.Accessibility) { return; } IDiscordEmbed explainedHelpEmbed = Utils.Embed .SetTitle(ev.Name.ToUpper()); if (ev.Aliases.Length > 0) { explainedHelpEmbed.AddInlineField( locale.GetString("miki_module_general_help_aliases"), string.Join(", ", ev.Aliases)); } explainedHelpEmbed.AddField( locale.GetString("miki_module_general_help_description"), (locale.HasString("miki_command_description_" + ev.Name.ToLower())) ? locale.GetString("miki_command_description_" + ev.Name.ToLower()) : locale.GetString("miki_placeholder_null")); explainedHelpEmbed.AddField( locale.GetString("miki_module_general_help_usage"), (locale.HasString("miki_command_usage_" + ev.Name.ToLower())) ? locale.GetString("miki_command_usage_" + ev.Name.ToLower()) : locale.GetString("miki_placeholder_null")); await explainedHelpEmbed.SendToChannel(e.Channel); } return; } IDiscordEmbed embed = Utils.Embed; embed.Description = locale.GetString("miki_module_general_help_dm"); embed.Color = new Color(0, 0.5f, 1); await embed.SendToChannel(e.Channel); await(await Bot.instance.Events.ListCommandsInEmbedAsync(e.message)).SendToUser(e.Author); }
protected void saveData(ICommandEvent evt) { List<Filter> list = new List<Filter>(); foreach(DataGridViewRow row in dgvCEFilters.Rows) { if(row.IsNewRow) { continue; } object customIn = Value.packArgument(row.Cells[dgvCEFiltersColumnCustomIn.Name].Value); object customOut = Value.packArgument(row.Cells[dgvCEFiltersColumnCustomOut.Name].Value); object guid = row.Cells[dgvCEFiltersColumnGuid.Name].Value; list.Add(new Filter() { Guid = (guid == null)? String.Empty : ((string)guid).Trim(), CustomIn = customIn.IsNullOrEmptyString() ? null : customIn, CustomOut = customOut.IsNullOrEmptyString() ? null : customOut, Description = (string)row.Cells[dgvCEFiltersColumnDescription.Name].Value, Id = Convert.ToInt32(row.Cells[dgvCEFiltersColumnId.Name].Value), Cancel = Convert.ToBoolean(row.Cells[dgvCEFiltersColumnCancel.Name].Value), Pre = Convert.ToBoolean(row.Cells[dgvCEFiltersColumnPre.Name].Value), Post = Convert.ToBoolean(row.Cells[dgvCEFiltersColumnPost.Name].Value), }); } evt.Filters = list.ToArray(); }
ICommandEvent ICommandEventDataProvider.Post(ICommandEvent commandEvent) { return(Post(commandEvent)); }
public RuntimeModule AddCommand(ICommandEvent command) { Events.Add(command); return(this); }