Exemple #1
0
        public void StartGame()
        {
            this.OnStart();

            Response reponse = new Response("Game started", new[] { this.channel }, MessageFormat.Notice, MessageType.Both);
            this.ircClient.SendResponse(reponse);
        }
 /// <summary>
 /// Shortens the URL.
 /// </summary>
 /// <param name="user">The user.</param>
 /// <param name="channel">The channel.</param>
 /// <param name="messageType">Type of the message.</param>
 /// <param name="messageFormat">The message format.</param>
 /// <param name="message">The message.</param>
 /// <param name="arguments">The arguments.</param>
 private void ShortenUrl(User user, string channel, MessageType messageType, MessageFormat messageFormat, string message, Dictionary<string, string> arguments)
 {
     foreach (IUrlShortenerProvider provider in this.providers)
     {
         if(arguments.ContainsKey(provider.Trigger))
         {
             try
             {
                 var url = UrlRegex.Match(message).Groups["url"].Value;
                 string shortUrl;
                 shortUrl = this.GetShortUrl(url, provider);
                 var response = new Response(shortUrl, new[] { channel ?? user.Nick }, messageFormat, messageType);
                 this.SendResponse(response);
             }
             catch (Exception e)
             {
                 Trace.TraceError(e.Source);
                 Trace.TraceError(e.Message);
             }
         }
     }
 }
Exemple #3
0
        /// <summary>
        /// Lists the admins.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="channel">The channel.</param>
        /// <param name="messageType">Type of the message.</param>
        /// <param name="messageFormat">The message format.</param>
        /// <param name="message">The message.</param>
        /// <param name="arguments">The arguments.</param>
        private void ListAdmins(User user, string channel, MessageType messageType, MessageFormat messageFormat, string message, Dictionary<string, string> arguments)
        {
            var admins = this.userService.ListAdmins().Select(a => string.Format("{0} : {1}", a.Nick, a.Email));

            foreach (var admin in admins)
            {
                var response = new Response(admin, new[] { channel ?? user.Nick }, MessageFormat.Message, MessageType.Both);
                this.IrcClient.SendResponse(response);
            }
        }
        /// <summary>
        /// Sends the conditions.
        /// </summary>
        /// <param name="targets">The targets.</param>
        /// <param name="messageFormat">The message format.</param>
        /// <param name="messageType">Type of the message.</param>
        /// <param name="currentObservation">The current observation.</param>
        /// <returns>
        /// The <see cref="IEnumerable" />.
        /// </returns>
        private static IEnumerable<IResponse> CreateConditionsResponse(IEnumerable<string> targets, MessageFormat messageFormat, MessageType messageType, ICurrentObservation currentObservation)
        {
            try
            {
                var conditions = "{0}. {1}. {2}, feels like {2}, wind chill {3}.".FormatWith(
                    currentObservation.DisplayLocation.Full,
                    currentObservation.ObservationTime,
                    currentObservation.Temperature,
                    currentObservation.FeelsLike,
                    currentObservation.Wind);

                var response = new Response(conditions, targets, messageFormat, messageType);

                return new[] { response };
            }
            catch (Exception e)
            {
                Trace.TraceError(e.TargetSite.Name);
                Trace.TraceError(e.Message);
            }

            return Enumerable.Empty<IResponse>();
        }
Exemple #5
0
        /// <summary>
        /// Called when [roll].
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="channel">The channel.</param>
        /// <param name="type">The type.</param>
        /// <param name="format">The format.</param>
        /// <param name="message">The message.</param>
        /// <param name="arguments">The arguments.</param>
        private void OnRoll(User user, string channel, MessageType type, MessageFormat format, string message, Dictionary<string, string> arguments)
        {
            Match match = DiceRegex.Match(message);

            if (match.Success)
            {
                var group = match.Groups["times"];

                if (group.Success)
                {
                    int value = int.Parse(group.Value);
                    var results = new List<int>();
                    value.Times(() => results.Add(this.random.Next(1, 6)));

                    var response = new Response(string.Join(", ", results), new [] { channel ?? user.Nick }, MessageFormat.Message, MessageType.Both);
                    response.MessageType = MessageType.Both;
                    this.SendResponse(response);
                }
                else
                {
                    var response = new Response(string.Join(", ", this.random.Next(1, 6)), new[] { channel ?? user.Nick }, MessageFormat.Message, MessageType.Both);
                    response.MessageType = MessageType.Both;
                    this.SendResponse(response);
                }
            }
        }
 /// <summary>
 /// Creates the urban message.
 /// </summary>
 /// <param name="user">The user.</param>
 /// <param name="channel">The channel.</param>
 /// <param name="messageType">Type of the message.</param>
 /// <param name="messageFormat">The message format.</param>
 /// <param name="task">The task.</param>
 private void SendUrbanResponse(User user, string channel, MessageType messageType, MessageFormat messageFormat, Task<IUrbanResponse> task)
 {
     if (task.Result.Results.Any())
     {
         var targets = new[] { channel ?? user.Nick };
         IResult result = task.Result.Results.First();
         Response response = new Response(result.Definition, targets, messageFormat, messageType);
         this.SendResponse(response);
     }
 }
Exemple #7
0
        /// <summary>
        /// Reads from session.
        /// </summary>
        /// <param name="irb">The irb.</param>
        /// <param name="user">The user.</param>
        /// <param name="channel">The channel.</param>
        private void ReadFromSession(Process irb, User user, string channel)
        {
            // Read all standard output
            Task.Factory.StartNew(() =>
                {
                    while (!irb.StandardError.EndOfStream)
                    {
                        string line = irb.StandardError.ReadLine();
                        var response = new Response(line, new[] { channel ?? user.Nick }, MessageFormat.Message, MessageType.Both);
                        this.ircClient.SendResponse(response);
                    }
                });

            // Read all error output
            Task.Factory.StartNew(() =>
                {
                    while (!irb.StandardOutput.EndOfStream)
                    {
                        string line = irb.StandardOutput.ReadLine();
                        var response = new Response(line, new[] { channel ?? user.Nick }, MessageFormat.Message, MessageType.Both);
                        this.ircClient.SendResponse(response);
                    }
                });
        }
Exemple #8
0
        /// <summary>
        /// Sends the module commands.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="messageType">Type of the message.</param>
        /// <param name="module">The module.</param>
        /// <param name="targets">The targets.</param>
        private void SendModuleCommands(User user, MessageType messageType, IModule module, string[] targets)
        {
            var response = new Response("{0} has the following commands: ".FormatWith(module.Name), targets, MessageFormat.Notice, messageType);
            this.SendResponse(response);

            // For each possible command where the command is accessible
            foreach (var command in module.Commands.Where(c => c.LevelRequired <= user.AccessLevel))
            {
                response = new Response("{0}: {1}".FormatWith(command.Trigger, command.Description), targets, MessageFormat.Notice, messageType);
                this.SendResponse(response);

                response.Message = string.Empty;

                foreach (var argument in command.KnownArguments)
                {
                    response.Message += "{0}{1} {2}".FormatWith(command.ArgumentSplitter, argument.Key, argument.Value);
                }

                this.SendResponse(response);

                this.SendCommandUsageExamples(module, targets, messageType, MessageFormat.Notice);
            }
        }
Exemple #9
0
        /// <summary>
        /// Sends the usage example.
        /// </summary>
        /// <param name="module">The module.</param>
        /// <param name="targets">The targets.</param>
        /// <param name="messageType">Type of the message.</param>
        /// <param name="messageFormat">The message format.</param>
        private void SendCommandUsageExamples(IModule module, IEnumerable<string> targets, MessageType messageType, MessageFormat messageFormat)
        {
            var response = new Response("{0} command usage examples: ".FormatWith(module.Name), targets, messageFormat, messageType);
            this.SendResponse(response);

            foreach (var command in module.Commands)
            {
                foreach (var example in command.Examples)
                {
                    response.Message = "{0}".FormatWith(example);
                    this.SendResponse(response);
                }
            }
        }
Exemple #10
0
        /// <summary>
        /// Lists the modules.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="channel">The channel.</param>
        /// <param name="messageType">Type of the message.</param>
        /// <param name="messageFormat">The message format.</param>
        /// <param name="message">The message.</param>
        /// <param name="arguments">The arguments.</param>
        private void ListModules(User user, string channel, MessageType messageType, MessageFormat messageFormat, string message, Dictionary<string, string> arguments)
        {
            var targets = new[] { user.Nick };

            if (arguments.None())
            {
                this.SendCommandUsageExamples(this, targets, messageType, messageFormat);
            }

            foreach (var key in arguments.Keys)
            {
                AccessLevel level;

                if (Enum.TryParse(key, ignoreCase: true, result: out level))
                {
                    foreach (var module in this.IrcClient.Modules.Where(m => m.Commands.Any(c => c.LevelRequired <= level && c.LevelRequired <= user.AccessLevel)))
                    {
                        var moduleInfoResponse = new Response("{0}: {1}".FormatWith(module.Name, module.Description), targets, MessageFormat.Notice, messageType);
                        this.SendResponse(moduleInfoResponse);
                    }
                }
            }

            if (arguments.ContainsKey("list"))
            {
                #region Send all Module descriptions

                foreach (var module in this.IrcClient.Modules.Where(m => m.Commands.Any(c => c.LevelRequired <= user.AccessLevel)))
                {
                    var moduleInfoResponse = new Response("{0}: {1}".FormatWith(module.Name, module.Description), targets, MessageFormat.Notice, messageType);
                    this.SendResponse(moduleInfoResponse);
                }

                #endregion

                this.GetMoreInformation(messageType, targets);
            }

            if (arguments.ContainsKey("examples"))
            {
                // For each module where the module has a command that is accessible by this user
                foreach (var module in this.IrcClient.Modules.Where(m => m.Commands.Any(c => c.LevelRequired <= user.AccessLevel)))
                {
                    #region Module Description

                    var response = new Response("{0}: {1}".FormatWith(module.Name, module.Description), targets, MessageFormat.Notice, messageType);
                    this.SendResponse(response);

                    #endregion

                    #region Usage Examples

                    response.Message = "Usage Examples: ";
                    this.SendResponse(response);
                    this.SendCommandUsageExamples(module, targets, messageType, MessageFormat.Notice);

                    #endregion
                }
            }
        }
Exemple #11
0
        /// <summary>
        /// Sends a message about how to get more information on a module.
        /// </summary>
        /// <param name="messageType">Type of the message.</param>
        /// <param name="targets">The targets.</param>
        private void GetMoreInformation(MessageType messageType, IEnumerable<string> targets)
        {
            var response = new Response("For more information: ", targets, MessageFormat.Notice, messageType);

            var command = this.Commands.FirstOrDefault(c => c.Trigger.Equals("!module", StringComparison.OrdinalIgnoreCase));
            response.Message += "Use the command {0} followed by argument --module name to receive more information about that module.".FormatWith(command.Trigger);

            this.SendResponse(response);
        }