Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            Console.Title = "Hatman";
            Console.Write("Reading config...");

            if (!File.Exists("Config.txt"))
            {
                Console.WriteLine("Config.txt not found." +
                    " \nPlease ensure the file can be found within the working directory.");
                Console.Read();
                return;
            }

            var email = "";
            var pass = "";
            ReadConfig(out email, out pass);

            Console.Write("done.\nLogging into SE...");
            chatClient = new Client(email, pass);

            Console.Write("done.\nJoining room...");
            chatRoom = chatClient.JoinRoom(roomURL, true);
            Extensions.SelfID = chatRoom.Me.ID;

            ChatEventRouter router = new ChatEventRouter(chatRoom);

            Console.WriteLine("done.\n");
            chatRoom.PostMessageLight("Hiya");

            router.ShutdownMre.WaitOne();

            chatRoom.PostMessageLight("Cya");
            chatRoom.Leave();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Joins the room with the settings passed in.
        /// </summary>
        public void JoinRoom(InstallationSettings settings)
        {
            // Copy over the settings into this class so this class can use it.
            this.settings = settings;

            // Create the ChatMessageProcessor.
            cmp = new ChatMessageProcessor(settings);
            cmp.StopBotCommandIssued += cmp_StopBotCommandIssued;

            // Logic to join the chat room.
            chatClient = new Client(settings.Email, settings.Password);
            cvChatRoom = chatClient.JoinRoom(settings.ChatRoomUrl);
            ChatBotStats.LoginDate = DateTime.Now;
            cvChatRoom.StripMention = false;

            // Say the startup message?
            if (!settings.StartUpMessage.IsNullOrWhiteSpace())
            {
                // This is the one of the few instances to not using the "OrThrow" method.
                var startMessage = cvChatRoom.PostMessage(settings.StartUpMessage);

                if (startMessage == null)
                {
                    throw new InvalidOperationException("Unable to post start up message to room.");
                }
            }

            cvChatRoom.EventManager.ConnectListener(EventType.MessagePosted, new Action<Message>(cvChatRoom_NewMessage));
            cvChatRoom.EventManager.ConnectListener(EventType.MessageEdited, new Action<Message>(cvChatRoom_NewMessage));
        }
Exemplo n.º 3
0
 public Chat()
 {
     chatClient = new Client(Configuration.LoginEmail, Configuration.LoginPassword, Configuration.ProxyUrl, Configuration.ProxyUsername, Configuration.ProxyPassword);
     try
     {
         chatRoom = chatClient.JoinRoom(Configuration.RoomUrl);
     }
     catch (AuthenticationException)
     {
         Console.WriteLine("Cannot Login");
         chatClient.Dispose();
     }
 }
Exemplo n.º 4
0
 public void Execute(string command, string arguments, User user, Room room, Client client)
 {
     if (!AdaPermissions.IsAuthorized(permissionLevel, user))
     {
         var messageBuilder = new MessageBuilder();
         messageBuilder.AppendPing(user);
         messageBuilder.AppendText("You are not authorised to make this command.");
         room.PostMessage(messageBuilder);
     }
     else
     {
         Action(command, arguments, user, room, client);
     }
 }
Exemplo n.º 5
0
        public void Start()
        {
            Log("[…] Starting chat api…");

            exceptionOccurred = false;
            LastChatApiInitializationAttempt = DateTime.Now;

            startTime = DateTime.UtcNow;

            client = new Client(login, pass);

            if (mainRoomID > 0)
            {
                if (!roomTranscriptDic.ContainsKey(mainRoomID))
                    roomTranscriptDic[mainRoomID] = new List<ChatMessage>();
                JoinRoom(mainRoomID);
                Log("[…] Joined main room.");
                if (client.Rooms.Count > 0)
                {
                    botname = client.Rooms[0].Me.Name;
                    userID = client.Rooms[0].Me.ID;
                    client.Rooms[0].WebSocketRecoveryTimeout = new TimeSpan(10, 0, 0, 0);
                    Log("[…] Found bot name in main room.");
                }
                else
                {
                    exceptionOccurred = true;
                    Log("[X] Failed to join main room.");
                }
            }

            if (debugRoomID > 0)
            {
                if (!roomTranscriptDic.ContainsKey(debugRoomID))
                    roomTranscriptDic[debugRoomID] = new List<ChatMessage>();
                JoinRoom(debugRoomID);
                Log("[…] Joined debug room.");
                if (client.Rooms.Count > 1)
                    client.Rooms[0].WebSocketRecoveryTimeout = new TimeSpan(10, 0, 0, 0);
                else
                {
                    exceptionOccurred = true;
                    Log("[X] Failed to join debug room.");
                }
            }

            Log("[.] Started chat api.");
        }
Exemplo n.º 6
0
        private static void AuthenticateChatClient()
        {
            var cr = new ConfigReader();

            var email = cr.GetSetting("se email");
            var pwd = cr.GetSetting("se pass");

            chatClient = new Client(email, pwd);
        }
Exemplo n.º 7
0
        static void Main()
        {
            Console.WriteLine("This is a ChatExchange.Net demonstration. Press the 'Q' key to exit...\n\n");

            // Create a client to authenticate the user (which will then allow us to interact with chat).
            var client = new Client("*****@*****.**", "MySuperStr0ngPa55word");

            // Join a room by specifying its URL (returns a Room object).
            var sandbox = client.JoinRoom("http://chat.stackexchange.com/rooms/1/sandbox");

            // Post a new message in the room (if successful, returns a Message object, otherwise returns null).
            // (If you have no use of the returned Message object, I'd recommend using .PostMessageFast() instead.)
            var myMessage = sandbox.PostMessage("Hello world!");

            // Listen to the InternalException event for any exceptions that may arise during execution.
            // See our wiki for examples of other events
            // (https://github.com/ArcticEcho/ChatExchange.Net/wiki/Hooking-up-chat-events).
            sandbox.EventManager.ConnectListener(EventType.InternalException, new Action<Exception>(ex => Console.WriteLine("[ERROR] " + ex)));

            // Listen to the MessagePosted event for new messages.
            sandbox.EventManager.ConnectListener(EventType.MessagePosted, new Action<Message>(message =>
            {
                // Print the new message (with the author's name).
                Console.WriteLine(message.Author.Name + ": " + message.Content);

                // If the message contains "3... 2... 1...", post "KA-BOOM!" (this is simply an [awful] example).
                if (message.Content.Contains("3... 2... 1..."))
                {
                    // Create a new MessageBuilder to format our message.
                    var msgBuilder = new MessageBuilder();

                    // Append the text "KA-BOOM!" (formatted in bold).
                    msgBuilder.AppendText("KA-BOOM!", TextFormattingOptions.Bold);

                    // Finally post the formatted message.
                    // (PostMessage() internally calls the message's ToString() method.)
                    var success = sandbox.PostMessage(msgBuilder) != null;

                    Console.WriteLine("'KA-BOOM' message successfully posted: " + success);
                }
            }));

            // Listen to the UserEntered event and post a welcome message when the event is fired.
            sandbox.EventManager.ConnectListener(EventType.UserEntered, new Action<User>(user =>
            {
                var success = sandbox.PostMessage("Hello " + user + "!") != null;

                Console.WriteLine("'Welcome' message successfully posted: " + success);
            }));

            // Wait for the user to press the "Q" key before we exit (not the best way to do this, but it'll suffice).
            while (char.ToLower(Console.ReadKey(true).KeyChar) != 'q')
            {
                Thread.Sleep(500);
            }

            // Not necessary for safe disposal, but still, it's nice to "physically"
            // leave the room rather than letting timeouts figure out that we've gone.
            sandbox.Leave();

            // Safely dispose of the client object (which'll also clean up all created room instances).
            client.Dispose();
        }
Exemplo n.º 8
0
 public static void LeaveChat(string command, string arguments, User user, Room room, Client client)
 {
     room.PostMessageLight("Bye, sleeps for me!");
     room.Leave();
     client.Dispose();
     AdaRunner.Shutdown();
 }
Exemplo n.º 9
0
 public static void EchoMessage(string command, string arguments, User user, Room room, Client client)
 {
     var messageBuilder = new MessageBuilder();
     messageBuilder.PingAndMessage(user, command + "!! :D");
     room.PostMessageLight(messageBuilder);
 }
Exemplo n.º 10
0
 /// <summary>
 /// Continue Post hunting.
 /// </summary>
 public static void Continue(string command, string arguments, User user, Room room, Client client)
 {
     var messageBuilder = new MessageBuilder();
     messageBuilder.PingAndMessage(user, "Placeholder for future unpausing of dupe search.");
     room.PostMessageLight(messageBuilder);
 }
Exemplo n.º 11
0
 /// <summary>
 /// Give user permissions.
 /// </summary>
 public static void AddUser(string command, string arguments, User user, Room room, Client client)
 {
     var messageBuilder = new MessageBuilder();
     messageBuilder.PingAndMessage(user, "Placeholder for future adding users.");
     room.PostMessageLight(messageBuilder);
 }
Exemplo n.º 12
0
 private static void Sleep(string command, string arguments, User user, Room room, Client client)
 {
     var messageBuilder = new MessageBuilder();
     messageBuilder.AppendText("leave");
     room.PostMessageLight(messageBuilder);
 }
Exemplo n.º 13
0
 /// <summary>
 /// Show list of commands. duh
 /// </summary>
 private static void ShowCommands(string command, string arguments, User user, Room room, Client client)
 {
     var messageBuilder = new MessageBuilder();
     messageBuilder.PingAndMessage(user, "Here is a list of my commands:\n");
     var commands = AdaCommands.Where(kvp => kvp.Value.IsCommand).Select(kvp => kvp.Key);
     messageBuilder.AppendText(string.Join(Environment.NewLine, commands));
     room.PostMessageLight(messageBuilder);
 }
Exemplo n.º 14
0
 /// <summary>
 /// No where near having  ready.
 /// </summary>
 public static void SummaryReport(string command, string arguments, User user, Room room, Client client)
 {
     var messageBuilder = new MessageBuilder();
     messageBuilder.PingAndMessage(user, "Placeholder for future summary reports");
     room.PostMessageLight(messageBuilder);
 }