private void ProcessChatCommandLogIn(IrcClient client, IIrcMessageSource source,
                                             IList <IIrcMessageTarget> targets, string command, IList <string> parameters)
        {
            var sourceUser  = (IrcUser)source;
            var twitterUser = this.twitterUsers.SingleOrDefault(tu => tu.IrcUser == sourceUser);

            if (twitterUser != null)
            {
                throw new InvalidOperationException(string.Format(
                                                        "User '{0}' is already logged in to Twitter as {1}.", sourceUser.NickName,
                                                        twitterUser.TwitterUser.ScreenName));
            }

            if (parameters.Count != 2)
            {
                throw new InvalidCommandParametersException(1);
            }

            // Create new Twitter user and log in to service.
            var twitterBotUser = new TwitterBotUser(sourceUser);
            var success        = twitterBotUser.LogIn(parameters[0], parameters[1]);

            var replyTargets = GetDefaultReplyTarget(client, sourceUser, targets);

            if (success)
            {
                // Log-in succeeded.

                this.twitterUsers.Add(twitterBotUser);

                client.LocalUser.SendMessage(replyTargets, "You are now logged in as {0} / '{1}'.",
                                             twitterBotUser.TwitterUser.ScreenName, twitterBotUser.TwitterUser.Name);
            }
            else
            {
                // Log-in failed.

                client.LocalUser.SendMessage(replyTargets, "Invalid log-in username/password.");
            }
        }
Beispiel #2
0
        private void ProcessChatCommandLogIn(IrcClient client, IIrcMessageSource source,
            IList<IIrcMessageTarget> targets, string command, IList<string> parameters)
        {
            var sourceUser = (IrcUser)source;
            var twitterUser = this.twitterUsers.SingleOrDefault(tu => tu.IrcUser == sourceUser);
            if (twitterUser != null)
                throw new InvalidOperationException(string.Format(
                    "User '{0}' is already logged in to Twitter as {1}.", sourceUser.NickName,
                    twitterUser.TwitterUser.ScreenName));

            if (parameters.Count != 2)
                throw new InvalidCommandParametersException(1);

            // Create new Twitter user and log in to service.
            var twitterBotUser = new TwitterBotUser(sourceUser);
            var success = twitterBotUser.LogIn(parameters[0], parameters[1]);

            var replyTargets = GetDefaultReplyTarget(client, sourceUser, targets);
            if (success)
            {
                // Log-in succeeded.

                this.twitterUsers.Add(twitterBotUser);

                client.LocalUser.SendMessage(replyTargets, "You are now logged in as {0} / '{1}'.",
                    twitterBotUser.TwitterUser.ScreenName, twitterBotUser.TwitterUser.Name);
            }
            else
            {
                // Log-in failed.

                client.LocalUser.SendMessage(replyTargets, "Invalid log-in username/password.");
            }
        }