Ejemplo n.º 1
0
 public void ClearCooldowns(ICommand cmd = null)
 {
     if ( cmd == null )
         CommandCoolDowns.Clear();
     else
         CommandCoolDowns[MessageLocalizer.GetDefaultLocalization(cmd.CommandName)] = 0;
 }
Ejemplo n.º 2
0
 public CommandConfiguration(ICommand cmd) : this()
 {
     Command  = MessageLocalizer.GetDefaultLocalization(cmd.CommandName).ToLowerInvariant();
     Cost     = cmd.CommandCost;
     CoolDown = cmd.CommandCoolDown;
     Enabled  = true;
     Level    = cmd.CommandLevel;
 }
Ejemplo n.º 3
0
        public int GetCoolDown(ICommand cmd)
        {
            int timePassed = -1;

            if (cmd.CommandCoolDown <= 0)
                return 0;

            if (CommandCoolDowns.ContainsCommand(MessageLocalizer.GetDefaultLocalization(cmd.CommandName)))
            {
                timePassed = Age - CommandCoolDowns[MessageLocalizer.GetDefaultLocalization(cmd.CommandName)];
                return (timePassed > cmd.CommandCoolDown) ? 0 : cmd.CommandCoolDown - timePassed;
            }
            return 0;
        }
Ejemplo n.º 4
0
        public static void RegisterCommandHandlers(Assembly x)
        {
            foreach (var t in x.GetExportedTypes())
            {
                if (t.GetInterfaces().Contains(typeof(ICommand)))
                {
                    if (t.IsAbstract)
                    {
                        continue;
                    }
                    try
                    {
                        logger.Info("Loading Command {0} from {1}", t.FullName, x.GetName().Name);
                        ICommand ex = Activator.CreateInstance(t) as ICommand;

                        allCommands[MessageLocalizer.GetDefaultLocalization(ex.CommandName)] = ex;
                        ILogger l = LogManager.GetLogger(t.ToString(), typeof(ExtensionLogger)) as ILogger;
                        ex.Init(l, MessageLocalizer.Instance);
                        if (!Program.Config.Commands.ContainsCommand(MessageLocalizer.GetDefaultLocalization(ex.CommandName)))
                        {
                            Program.Config.Commands.Add(new Config.CommandConfiguration(ex));
                        }
                        else
                        {
                            Program.Config.Commands.UpdateCommand(ex);
                        }
                        foreach (var item in ex.CommandAliases)
                        {
                            if (!String.IsNullOrEmpty(item))
                            {
                                allCommands[item.ToLowerInvariant()] = ex;
                            }
                        }
                        Program.Config.Save(true);
                    }
                    catch (Exception ex)
                    {
                        logger.Error("Error loading {0}: {1}", t.ToString(), ex.ToString());
                    }
                }
            }
        }
Ejemplo n.º 5
0
        internal void UpdateCommand(ICommand cmd)
        {
            CommandConfiguration config = this[MessageLocalizer.GetDefaultLocalization(cmd.CommandName)];

            cmd.CommandCoolDown = config.CoolDown;
            cmd.CommandCost     = config.Cost;
            if (cmd.CommandLevel != config.Level)
            {
                logger.Warn("{0} Changing Level from {1} to {2}", MessageLocalizer.GetDefaultLocalization(cmd.CommandName), cmd.CommandLevel, config.Level);
            }
            cmd.CommandLevel = config.Level;
            if (config.Alias.Length > 0)
            {
                cmd.CommandAliases = config.Alias;
            }
            else
            {
                config.Alias           = cmd.CommandAliases;
                Program.Config.IsDirty = true;
            }
            Program.Config.Save();
        }
Ejemplo n.º 6
0
 public void SetCoolDown(ICommand cmd)
 {
     if (cmd.CommandCoolDown <= 0)
         return;
     CommandCoolDowns[MessageLocalizer.GetDefaultLocalization(cmd.CommandName)] = Age;
 }