Basic Command Class, Inherit your Commands from here. Automatically creates one instance per IrcClient when the Class is loaded, using the default constructor.
        //public static IDictionary<Type, Command> CommandsByType {
        //    get { return commandMapByType; }
        //}
        /// <summary>
        /// Adds a Command to the CommandsByAlias.
        /// </summary>
        public static void Add(Command cmd)
        {
            //Type type = cmd.GetType();
            //if (commandMapByType.ContainsKey(type)) {
            //    throw new Exception("Trying to create a second instance of a Singleton Command-object");
            //}

            //// map by type
            //commandMapByType[type] = cmd;
            commands.Add(cmd);

            // Add to table, mapped by aliases
            foreach (var alias in cmd.Aliases)
            {
                Command exCommand;
                //if (!commandsByAlias.TryGetValue(alias, out exCommand))
                {
                    CommandsByAlias[alias] = cmd;
                }
                //else
                {
                    //throw new IrcException("Found two Commands with Alias \"{0}\": {1} and {2}", alias, exCommand, cmd);
                }
            }
        }
 /// <summary>
 /// Return wether or not a command may be triggered. 
 /// Is called everytime, a command is triggered.
 /// </summary>
 /// <param name="cmd">A command.</param>
 public virtual bool MayTriggerCommand(CmdTrigger trigger, Command cmd)
 {
     return trigger.User == null || trigger.User == Me || trigger.User.AccountLevel >= cmd.RequiredAccountLevel;
 }
        /// <summary>
        /// Removes a Command.
        /// </summary>
        public static void Remove(Command cmd)
        {
            //commandMapByType.Remove(cmd.GetType());
            commands.Remove(cmd);

            foreach (var alias in cmd.Aliases)
            {
                CommandsByAlias.Remove(alias);
            }
        }
 /// <summary>
 /// Return wether or not a command may be triggered. 
 /// Is called everytime, a command is triggered.
 /// </summary>
 /// <param name="cmd">A command.</param>
 public virtual bool MayTriggerCommand(CmdTrigger trigger, Command cmd)
 {
     return trigger.User == null || trigger.User == Me;
 }
Exemple #5
0
 /// <returns>Wether this is allowed to trigger the given command or not.</returns>
 public bool MayTrigger(Command cmd)
 {
     return Irc.MayTriggerCommand(this, cmd);
 }
        public override bool MayTriggerCommand(CmdTrigger trigger, Command cmd)
        {
            try
            {
                if (base.MayTriggerCommand(trigger, cmd))
                {
                    if (trigger.Channel != null && trigger.Target == trigger.Channel && !trigger.Args.String.ToLower().StartsWith(CommandHandler.RemoteCommandPrefix + "help"))
                    {
                        if (!SpamTimer.Enabled)
                        {
                            SpamTimer.Start();
                            return true;
                        }
                        else
                        {
                            trigger.User.Msg("Don't try to make me spam!");
                            return false;
                        }
                    }
                    else
                    {
                        return true;
                    }
                }
                return false;
            }
            catch (Exception e)
            {
                Console.WriteLine(DateTime.Now.ToString() + ":" + e.ToString());
                return false;
            }

            /*
            try
            {
                if (File.Exists("auth.txt") && cmd.Name.ToLower() != "addauth")
                {
                    using (var reader = new StreamReader("auth.txt"))
                    {
                        var usernames = new List<string>();
                        while (!reader.EndOfStream)
                        {
                            usernames.Add(reader.ReadLine());
                        }
                        if (usernames.Any(username => username == trigger.User.AuthName))
                        {
                            return true;
                        }
                    }
                }
                return trigger.User.IsOn("#wcell.dev") || trigger.User.IsOn("#woc") || trigger.User.IsOn("#wcell");*/
            //TODO: Update to add a proper suited auth system.);
            //return true;
        }
Exemple #7
0
 public override bool MayTriggerCommand(CmdTrigger trigger, Command cmd)
 {
     try
     {
         return true;
         /*
         if (trigger.Args.String.ToLower().StartsWith(CommandHandler.RemoteCommandPrefix + "help"))
         {
             return true;
         }
         if (base.MayTriggerCommand(trigger, cmd))
         {
             if (trigger.Target != null)
             {
                 if (!SpamTimer.Enabled)
                 {
                     SpamTimer.Start();
                     return true;
                 }
                 else
                 {
                     trigger.User.Msg("Don't try to make me spam!");
                     return false;
                 }
             }
         }
         return false;*/
     }
     catch (Exception e)
     {
         Console.WriteLine(DateTime.Now.ToString() + ":" + e.ToString());
         return false;
     }
 }
 /// <summary>
 /// Return wether or not a command may be triggered. 
 /// Is called everytime, a command is triggered
 /// By default Squishy is set to do nothing until you override this and add an auth system
 /// </summary>
 /// <param name="cmd">A command.</param>
 public virtual bool MayTriggerCommand(CmdTrigger<IrcCmdArgs> trigger, Command<IrcCmdArgs> cmd)
 {
     return trigger.Args.User == null || trigger.Args.User == Me;
 }