Ejemplo n.º 1
0
        /// <summary>
        /// The main.
        /// </summary>
        /// <param name="args">
        /// The args.
        /// </param>
        internal static void Main(string[] args)
        {
            ServerUser serverUser = null;
            Channel channel = null;

            Commands.Register();

            var isRunning = true;
            var answer = "My name is Batman";
            while (isRunning)
            {
                try
                {
                    Console.Write("> ");
                    string line = Console.ReadLine();
                    if (line == null)
                    {
                        break;
                    }

                    if (line.Length == 0)
                    {
                        continue;
                    }

                    string[] parts = line.Split(' ');
                    string command = parts[0].ToLower();
                    string[] parameters = parts.Skip(1).ToArray();

                    switch (command)
                    {
                        case "j":
                            serverUser = new ServerUser(
                                ConfigurationManager.AppSettings.Get("HostName"),
                                ConfigurationManager.AppSettings.Get("UserName"),
                                ConfigurationManager.AppSettings.Get("TheWord"),
                                ConfigurationManager.AppSettings.Get("NickName"),
                                ConfigurationManager.AppSettings.Get("RealName"),
                                int.Parse(ConfigurationManager.AppSettings.Get("MillisecondsBetweenCommands")))
                                             {
                                                 CommandPrefix = "+"
                                             };
                            string channelName = ConfigurationManager.AppSettings.Get("ChannelName");
                            if (parameters.Length > 0)
                            {
                                channelName = parameters[0];
                            }

                            channel = new Channel(serverUser, channelName)
                                          {
                                              KickBots = true
                                          };

                            channel.SendMessage(string.Format(
                                "Hello everyone! Write \"+hello\" if you would like me to respond to your chat messages. :) For other commands - try \"+help\"."));
                            break;
                        case "q":
                        case "l":
                            if (null != channel)
                            {
                                channel.SendMessage("I'm leaving for now, see you again!");
                                channel.Leave();
                                serverUser.LogOut();
                            }

                            if (command == "q")
                            {
                                isRunning = false;
                            }

                            break;
                        case "t":
                            if (channel == null)
                            {
                                break;
                            }

                            if (parameters.Length == 1)
                            {
                                channel.DoInterpreteMessages = parameters[0] == "on";
                            }
                            else
                            {
                                Console.WriteLine("Usage: t on|off");
                            }

                            break;
                        case "r":
                            var question = parameters.Length == 0 ? answer : string.Join(" ", parameters);
                            answer = Commands.AskBot(Commands.ChatBot.Chato, question, "zenioxbottest", "Dr. Test");
                            Console.WriteLine(answer);
                            break;
                        case "e":
                            var a = Services.DetectLanguage("Hej");
                            break;
                            //case "e":
                            //TranslateCommand(new CommandParameters
                            //                     {
                            //                         Command = c,
                            //                         CommandName = c.Name,
                            //                         Parameters = "sv|en Hej, jag heter Lars".Split(' ')
                            //                     });
                            //break;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Fatal error {0}\r{1}", e.Message, e.StackTrace);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The interprete.
        /// </summary>
        /// <param name="message">
        /// The message.
        /// </param>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="serverUser">
        /// The server user.
        /// </param>
        /// <param name="channel">
        /// The channel.
        /// </param>
        internal static void Interprete(string message, IrcIdentity sender, ServerUser serverUser, Channel channel)
        {
            if (null == sender)
            {
                return;
            }

            var user = User.GetOrCreate(sender);

            if (user.Translate)
            {
                var language = Services.DetectLanguage(message, false, user.Language == null ? 0.1 : 0.3);

                if ((language != null) && (language != "en"))
                {
                    user.Language = language;
                }

                if (user.Language != null)
                {
                    message = Services.Translate(user.Language, "en", message);
                    channel.SendMessage(string.Format("{0} ({1}): {2}", user.NickName, user.Language, message));
                }
            }

            if (!user.TalkTo)
            {
                return;
            }

            var answer = AskBot(
                ChatBot.Romulus,
                message,
                sender.Username,
                serverUser.NickName);

            if (channel != null)
            {
                answer = string.Format("-> {0}: {1}", sender.Nickname, answer);
            }

            serverUser.SendMessage(Command.GetReceiver(sender, channel), answer);
        }