Exemplo n.º 1
0
 /// <summary>
 /// Initialises a new instance of the <see cref="Configcacheclear"/> class.
 /// </summary>
 /// <param name="source">
 /// The source.
 /// </param>
 /// <param name="channel">
 /// The channel.
 /// </param>
 /// <param name="args">
 /// The args.
 /// </param>
 /// <param name="commandServiceHelper">
 /// The message Service.
 /// </param>
 public Configcacheclear(
     LegacyUser source, 
     string channel, 
     string[] args, 
     ICommandServiceHelper commandServiceHelper)
     : base(source, channel, args, commandServiceHelper)
 {
 }
Exemplo n.º 2
0
 /// <summary>
 /// Initialises a new instance of the <see cref="Threadstatus"/> class.
 /// </summary>
 /// <param name="source">
 /// The source.
 /// </param>
 /// <param name="channel">
 /// The channel.
 /// </param>
 /// <param name="args">
 /// The args.
 /// </param>
 /// <param name="commandServiceHelper">
 /// The message Service.
 /// </param>
 public Threadstatus(
     LegacyUser source, 
     string channel, 
     string[] args, 
     ICommandServiceHelper commandServiceHelper)
     : base(source, channel, args, commandServiceHelper)
 {
 }
Exemplo n.º 3
0
 /// <summary>
 /// Initialises a new instance of the <see cref="FunCommand"/> class.
 /// </summary>
 /// <param name="source">
 /// The source.
 /// </param>
 /// <param name="channel">
 /// The channel.
 /// </param>
 /// <param name="args">
 /// The args.
 /// </param>
 /// <param name="commandServiceHelper">
 /// The message Service.
 /// </param>
 protected FunCommand(
     LegacyUser source, 
     string channel, 
     string[] args, 
     ICommandServiceHelper commandServiceHelper)
     : base(source, channel, args, commandServiceHelper)
 {
 }
Exemplo n.º 4
0
 /// <summary>
 /// Initialises a new instance of the <see cref="GenericCommand"/> class.
 /// </summary>
 /// <param name="source">
 /// The source.
 /// </param>
 /// <param name="channel">
 /// The channel.
 /// </param>
 /// <param name="args">
 /// The args.
 /// </param>
 /// <param name="commandServiceHelper">
 /// The command Service Helper.
 /// </param>
 protected GenericCommand(
     LegacyUser source, 
     string channel, 
     string[] args, 
     ICommandServiceHelper commandServiceHelper)
     : this(commandServiceHelper)
 {
     this.Source = source;
     this.Channel = channel;
     this.Arguments = args;
 }
Exemplo n.º 5
0
        /// <summary>
        /// The notify join.
        /// </summary>
        /// <param name="source">
        /// The source.
        /// </param>
        /// <param name="channel">
        /// The channel.
        /// </param>
        internal void NotifyJoin(LegacyUser source, string channel)
        {
            List<LegacyUser> toNotify;
            lock (NotificationsDictionaryLock)
            {
                if (RequestedNotifications.TryGetValue(source.Nickname.ToUpperInvariant(), out toNotify))
                {
                    RequestedNotifications.Remove(source.Nickname);
                }
            }

            if (toNotify == null)
            {
                return;
            }
            
            var message = this.CommandServiceHelper.MessageService.RetrieveMessage("notifyJoin", this.Channel, new[] { source.Nickname, channel });
            foreach (var user in toNotify)
            {
                this.CommandServiceHelper.Client.SendMessage(user.Nickname, message);
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Initialises a new instance of the <see cref="Forget"/> class.
 /// </summary>
 /// <param name="source">
 /// The source.
 /// </param>
 /// <param name="channel">
 /// The channel.
 /// </param>
 /// <param name="args">
 /// The args.
 /// </param>
 /// <param name="commandServiceHelper">
 /// The message Service.
 /// </param>
 public Forget(LegacyUser source, string channel, string[] args, ICommandServiceHelper commandServiceHelper)
     : base(source, channel, args, commandServiceHelper)
 {
     // FIXME: ServiceLocator - keywordservice
     this.keywordService = ServiceLocator.Current.GetInstance<IKeywordService>();
 }
Exemplo n.º 7
0
        /// <summary>
        /// New user from string.
        /// </summary>
        /// <param name="source">
        /// The source.
        /// </param>
        /// <param name="network">
        /// The network.
        /// </param>
        /// <returns>
        /// The legacy user
        /// </returns>
        public static LegacyUser NewFromString(string source, uint network)
        {
            string user, host;
            string nick = user = host = null;

            var logger = ServiceLocator.Current.GetInstance<ILogger>();

            try
            {
                if (source.Contains("@") && source.Contains("!"))
                {
                    char[] splitSeparators = { '!', '@' };
                    string[] sourceSegment = source.Split(splitSeparators, 3);
                    nick = sourceSegment[0];
                    user = sourceSegment[1];
                    host = sourceSegment[2];
                }
                else if (source.Contains("@"))
                {
                    char[] splitSeparators = { '@' };
                    string[] sourceSegment = source.Split(splitSeparators, 2);
                    nick = sourceSegment[0];
                    host = sourceSegment[1];
                }
                else
                {
                    nick = source;
                }
            }
            catch (IndexOutOfRangeException ex)
            {
                logger.Error(ex.Message, ex);
            }

            if (nick == null)
            {
                return null;
            }

            var ret = new LegacyUser { Hostname = host, Nickname = nick, Username = user, Network = network, Log = logger };
            return ret;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Handles the command response handler.
        /// </summary>
        /// <param name="source">
        /// The source.
        /// </param>
        /// <param name="destination">
        /// The destination.
        /// </param>
        /// <param name="directedTo">
        /// The directed to.
        /// </param>
        /// <param name="response">
        /// The response.
        /// </param>
        private void HandleCommandResponseHandler(
            LegacyUser source, 
            string destination, 
            string directedTo, 
            CommandResponseHandler response)
        {
            if (response != null)
            {
                foreach (CommandResponse item in response.GetResponses())
                {
                    string message = item.Message;

                    if (directedTo != string.Empty)
                    {
                        message = directedTo + ": " + message;
                    }

                    var irc1 = this.commandServiceHelper.Client;
                    switch (item.Destination)
                    {
                        case CommandResponseDestination.Default:
                            if (this.OverrideBotSilence || LegacyConfig.Singleton()["silence", destination] != "true")
                            {
                                irc1.SendMessage(destination, message);
                            }

                            break;
                        case CommandResponseDestination.ChannelDebug:
                            irc1.SendMessage(this.commandServiceHelper.ConfigurationHelper.CoreConfiguration.DebugChannel, message);
                            break;
                        case CommandResponseDestination.PrivateMessage:
                            irc1.SendMessage(source.Nickname, message);
                            break;
                    }
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Handles the command.
        /// </summary>
        /// <param name="source">
        /// The source.
        /// </param>
        /// <param name="destination">
        /// The destination.
        /// </param>
        /// <param name="command">
        /// The command.
        /// </param>
        /// <param name="args">
        /// The args.
        /// </param>
        public void HandleCommand(LegacyUser source, string destination, string command, string[] args)
        {
            this.Log.Debug("Handling recieved message...");

            // user is null (!)
            if (source == null)
            {
                this.Log.Debug("Ignoring message from null user.");
                return;
            }

            // if on ignore list, ignore!
            if (source.AccessLevel == LegacyUser.UserRights.Ignored)
            {
                this.Log.Debug("Ignoring message from ignored user.");
                return;
            }

            // flip destination over if required
            if (destination == this.commandServiceHelper.Client.Nickname)
            {
                destination = source.Nickname;
            }

            /*
             * check category codes
             */
            if (WatcherController.Instance().IsValidKeyword(command))
            {
                int argsLength = args.SmartLength();

                var newArgs = new string[argsLength + 1];
                int newArrayPos = 1;
                foreach (string t in args)
                {
                    if (!string.IsNullOrEmpty(t))
                    {
                        newArgs[newArrayPos] = t;
                    }

                    newArrayPos++;
                }

                newArgs[0] = command;
                string directedTo = FindRedirection(ref newArgs);
                CommandResponseHandler crh =
                    new CategoryWatcher(source, destination, newArgs, this.commandServiceHelper).RunCommand();
                this.HandleCommandResponseHandler(source, destination, directedTo, crh);
                return;
            }

            /* 
             * Check for a valid command
             * search for a class that can handle this command.
             */

            // Create a new object which holds the type of the command handler, if it exists.
            // if the command handler doesn't exist, then this won't be set to a value
            Type commandHandler =
                Type.GetType(
                    "helpmebot6.Commands." + command.Substring(0, 1).ToUpper() + command.Substring(1).ToLower());

            // check the type exists
            if (commandHandler != null)
            {
                string directedTo = FindRedirection(ref args);

                // create a new instance of the commandhandler.
                // cast to genericcommand (which holds all the required methods to run the command)
                // run the command.
                CommandResponseHandler response =
                    ((GenericCommand)
                     Activator.CreateInstance(commandHandler, source, destination, args, this.commandServiceHelper))
                        .RunCommand();
                this.HandleCommandResponseHandler(source, destination, directedTo, response);
                return;
            }

            /*
             * Check for a learned word
             */
            {
                // FIXME: ServiceLocator - keywordservice
                var keywordService = ServiceLocator.Current.GetInstance<IKeywordService>();

                Keyword keyword = keywordService.Get(command);

                var crh = new CommandResponseHandler();
                string directedTo = string.Empty;
                if (keyword != null)
                {
                    if (source.AccessLevel < LegacyUser.UserRights.Normal)
                    {
                        this.Log.InfoFormat("Access denied for keyword retrieval for {0}", source);

                        var messageService1 = this.commandServiceHelper.MessageService;
                        crh.Respond(
                            messageService1.RetrieveMessage(Messages.OnAccessDenied, destination, null), 
                            CommandResponseDestination.PrivateMessage);

                        string[] accessDeniedArguments = { source.ToString(), MethodBase.GetCurrentMethod().Name };
                        crh.Respond(
                            messageService1.RetrieveMessage("accessDeniedDebug", destination, accessDeniedArguments), 
                            CommandResponseDestination.ChannelDebug);
                    }
                    else
                    {
                        string wordResponse = keyword.Response;

                        IDictionary<string, object> dict = new Dictionary<string, object>();

                        dict.Add("username", source.Username);
                        dict.Add("nickname", source.Nickname);
                        dict.Add("hostname", source.Hostname);
                        dict.Add("AccessLevel", source.AccessLevel);
                        dict.Add("channel", destination);

                        for (int i = 0; i < args.Length; i++)
                        {
                            dict.Add(i.ToString(CultureInfo.InvariantCulture), args[i]);
                            dict.Add(i + "*", string.Join(" ", args, i, args.Length - i));
                        }

                        wordResponse = wordResponse.FormatWith(dict);

                        if (keyword.Action)
                        {
                            crh.Respond(wordResponse.SetupForCtcp("ACTION"));
                        }
                        else
                        {
                            directedTo = FindRedirection(ref args);
                            crh.Respond(wordResponse);
                        }

                        this.HandleCommandResponseHandler(source, destination, directedTo, crh);
                    }
                }
            }
        }
Exemplo n.º 10
0
 /// <summary>
 /// Initialises a new instance of the <see cref="Access"/> class.
 /// </summary>
 /// <param name="source">
 /// The source.
 /// </param>
 /// <param name="channel">
 /// The channel.
 /// </param>
 /// <param name="args">
 /// The args.
 /// </param>
 /// <param name="commandServiceHelper">
 /// The message Service.
 /// </param>
 public Access(LegacyUser source, string channel, string[] args, ICommandServiceHelper commandServiceHelper)
     : base(source, channel, args, commandServiceHelper)
 {
     // FIXME: ServiceLocator - legacydatabase
     this.legacyDatabase = ServiceLocator.Current.GetInstance<ILegacyDatabase>();
 }
Exemplo n.º 11
0
        /// <summary>
        /// Adds the access entry.
        /// </summary>
        /// <param name="newEntry">
        /// The new entry.
        /// </param>
        /// <param name="accessLevel">
        /// The access level.
        /// </param>
        /// <returns>
        /// a response
        /// </returns>
        private CommandResponseHandler AddAccessEntry(LegacyUser newEntry, LegacyUser.UserRights accessLevel)
        {
            string[] messageParams = { newEntry.ToString(), accessLevel.ToString() };
            string message = this.CommandServiceHelper.MessageService.RetrieveMessage(
                "addAccessEntry", 
                this.Channel, 
                messageParams);

            // "Adding access entry for " + newEntry.ToString( ) + " at level " + AccessLevel.ToString( )"
            ServiceLocator.Current.GetInstance<ILogger>()
                .Info(string.Format("Adding access entry for {0} at level {1}", newEntry, accessLevel));

            var command = new MySqlCommand("INSERT INTO user VALUES ( null, @nick, @user, @host, @accesslevel, null );");

            command.Parameters.AddWithValue("@nick", newEntry.Nickname);
            command.Parameters.AddWithValue("@user", newEntry.Username);
            command.Parameters.AddWithValue("@host", newEntry.Hostname);
            command.Parameters.AddWithValue("@accesslevel", accessLevel.ToString());

            this.legacyDatabase.ExecuteCommand(command);

            return new CommandResponseHandler(message);
        }
Exemplo n.º 12
0
 /// <summary>
 /// Initialises a new instance of the <see cref="Electrocute"/> class.
 /// </summary>
 /// <param name="source">
 /// The source.
 /// </param>
 /// <param name="channel">
 /// The channel.
 /// </param>
 /// <param name="args">
 /// The args.
 /// </param>
 /// <param name="commandServiceHelper">
 /// The message Service.
 /// </param>
 public Electrocute(LegacyUser source, string channel, string[] args, ICommandServiceHelper commandServiceHelper)
     : base(source, channel, args, commandServiceHelper)
 {
 }
Exemplo n.º 13
0
 /// <summary>
 /// Initialises a new instance of the <see cref="CategoryWatcher"/> class.
 /// </summary>
 /// <param name="source">
 /// The source.
 /// </param>
 /// <param name="channel">
 /// The channel.
 /// </param>
 /// <param name="args">
 /// The args.
 /// </param>
 /// <param name="commandServiceHelper">
 /// The message Service.
 /// </param>
 public CategoryWatcher(LegacyUser source, string channel, string[] args, ICommandServiceHelper commandServiceHelper)
     : base(source, channel, args, commandServiceHelper)
 {
 }
Exemplo n.º 14
0
 /// <summary>
 /// Initialises a new instance of the <see cref="Delay"/> class.
 /// </summary>
 /// <param name="source">
 /// The source.
 /// </param>
 /// <param name="channel">
 /// The channel.
 /// </param>
 /// <param name="args">
 /// The args.
 /// </param>
 /// <param name="messageService">
 /// The message Service.
 /// </param>
 public Delay(LegacyUser source, string channel, string[] args, ICommandServiceHelper messageService)
     : base(source, channel, args, messageService)
 {
 }
Exemplo n.º 15
0
 /// <summary>
 /// Initialises a new instance of the <see cref="AccessLogEntry"/> struct. 
 /// </summary>
 /// <param name="source">
 /// The source.
 /// </param>
 /// <param name="command">
 /// The command.
 /// </param>
 /// <param name="success">
 /// if set to <c>true</c> [success].
 /// </param>
 /// <param name="channel">
 /// The channel the command was launched from
 /// </param>
 /// <param name="parameters">
 /// The parameters.
 /// </param>
 /// <param name="requiredAccessLevel">
 /// The required Access Level.
 /// </param>
 public AccessLogEntry(
     LegacyUser source, 
     Type command, 
     bool success, 
     string channel, 
     string[] parameters, 
     LegacyUser.UserRights requiredAccessLevel)
 {
     this.id = 0;
     this.date = new DateTime(0);
     this.user = source;
     this.@class = command;
     this.allowed = success;
     this.requiredAccessLevel = requiredAccessLevel;
     this.channel = channel;
     this.parameters = string.Join(" ", parameters);
 }
Exemplo n.º 16
0
 /// <summary>
 /// Initialises a new instance of the <see cref="Notify"/> class.
 /// </summary>
 /// <param name="source">
 /// The source.
 /// </param>
 /// <param name="channel">
 /// The channel.
 /// </param>
 /// <param name="args">
 /// The args.
 /// </param>
 /// <param name="commandServiceHelper">
 /// The message Service.
 /// </param>
 public Notify(LegacyUser source, string channel, string[] args, ICommandServiceHelper commandServiceHelper)
     : base(source, channel, args, commandServiceHelper)
 {
 }
Exemplo n.º 17
0
 /// <summary>
 /// Initialises a new instance of the <see cref="Welcomer"/> class.
 /// </summary>
 /// <param name="source">
 /// The source.
 /// </param>
 /// <param name="channel">
 /// The channel.
 /// </param>
 /// <param name="args">
 /// The args.
 /// </param>
 /// <param name="commandServiceHelper">
 /// The message Service.
 /// </param>
 public Welcomer(LegacyUser source, string channel, string[] args, ICommandServiceHelper commandServiceHelper)
     : base(source, channel, args, commandServiceHelper)
 {
     this.databaseSession = ServiceLocator.Current.GetInstance<ISession>();
 }
Exemplo n.º 18
0
 /// <summary>
 /// Initialises a new instance of the <see cref="Registration"/> class.
 /// </summary>
 /// <param name="source">
 /// The source.
 /// </param>
 /// <param name="channel">
 /// The channel.
 /// </param>
 /// <param name="args">
 /// The args.
 /// </param>
 /// <param name="commandServiceHelper">
 /// The message Service.
 /// </param>
 public Registration(LegacyUser source, string channel, string[] args, ICommandServiceHelper commandServiceHelper)
     : base(source, channel, args, commandServiceHelper)
 {
 }