예제 #1
0
파일: Chat.cs 프로젝트: yvettec/Dupes
 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();
     }
 }
예제 #2
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();
        }
예제 #3
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();
 }