Esempio n. 1
0
 public CommandData(PluginHandle target, BotCommandHandler commandHandler, 
     CommandDataAttributes attributes)
 {
     Target = target;
     Commands = attributes.CommandAttribute.Commands;
     CommandHandler = commandHandler;
     Attribute = attributes.CommandAttribute;
     Help = attributes.HelpAttribute;
     if (attributes.RoleAttribute != null)
         DefaultRole = attributes.RoleAttribute.Role.ToString();
 }
Esempio n. 2
0
        /// <summary>
        /// Initializes the command handlers.
        /// </summary>
        private void InitializeCommandHandlers()
        {
            foreach (var item in this.allCommandHandlers)
            {
                BotCommandHandler handler = null;

                // try to get the value
                try
                {
                    handler = item.Value;
                }
                catch (CompositionException ex)
                {
                    ReportPluginCompositionError(ex);
                    continue;
                }

                // handler is valid, process it
                var attribute = handler.GetHandlerAttribute();
                var target = PluginHandle.Get(handler);
                var attributes = new CommandDataAttributes
                {
                    CommandAttribute = attribute,
                    HelpAttribute = handler.GetHelpAttribute(),
                    RoleAttribute = handler.GetRoleDefaultAttribute()
                };
                var commandData = new CommandData(target, handler, attributes);
                this.commandHandlers.Add(commandData);

                // assign a role to this command
                authorizer.EnsureCommandRole(attribute.Commands, commandData.DefaultRole);

                // save plugin reference
                AddPluginToRunningList(target);
            }
        }