Inheritance: INotifyPropertyChanged, IIrcMessageTarget, IIrcMessageReceiveHandler, IIrcMessageReceiver
Ejemplo n.º 1
0
		private void ShowScores(IrcChannel channel)
		{
			foreach(var score in _scores.OrderBy(s => s.Points).Reverse().Take(5))
			{
				_bot.Say(channel.Name, string.Format("{0}: {1} points", score.Nickname, score.Points));
			}
		}
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the IrcChannelViewModel class
        /// </summary>
        public IrcChannelViewModel(IrcChannel channel, string networkName, Settings settings)
        {
            this.Settings = settings;
              this.Message = string.Empty;
              this.Messages = new BindableCollection<Message>();
              this.Closable = true;
              this.DisplayName = channel.Name;
              this.networkName = networkName;
              this.personalHistory = new List<string>();
              this.events = IoC.Get<IEventAggregator>();
              this.filterService = IoC.Get<FilterService>();
              this.Channel = channel;
              this.Channel.ModesChanged += this.channelModesChanged;
              this.Channel.UsersListReceived += this.channelUsersListReceived;
              this.Channel.MessageReceived += this.channelMessageReceived;
              this.Channel.UserJoined += this.channelUserJoined;
              this.Channel.UserLeft += this.channelUserLeft;
              this.Channel.NoticeReceived += this.channelNoticeReceived;
              this.Channel.TopicChanged += this.channelTopicChanged;

              DirectoryInfo di = new DirectoryInfo(Settings.PATH + "\\logs\\");
              if (!di.Exists)
            di.Create();
              if (this.Settings.CanLog)
            this.logger = new Logger(String.Format("{0}\\logs\\{1}.{2}.txt",
                                 Settings.PATH,
                                 channel.Name,
                                 networkName));

              this.Channel.GetTopic();
              this.Users = new List<IrcChannelUser>();
        }
Ejemplo n.º 3
0
        protected override void OnChannelMessageReceived(IrcChannel channel, IrcMessageEventArgs e)
        {
            var client = channel.Client;

            if (e.Source is IrcUser)
            {
                // Train Markov generator from received message text.
                // Assume it is composed of one or more coherent sentences that are themselves are composed of words.
                var sentences = e.Text.Split(sentenceSeparators);
                foreach (var s in sentences)
                {
                    string lastWord = null;
                    foreach (var w in s.Split(' ').Select(w => cleanWordRegex.Replace(w, string.Empty)))
                    {
                        if (w.Length == 0)
                            continue;
                        // Ignore word if it is first in sentence and same as nick name.
                        if (lastWord == null && channel.Users.Any(cu => cu.User.NickName.Equals(w,
                            StringComparison.InvariantCultureIgnoreCase)))
                            break;

                        markovChain.Train(lastWord, w);
                        lastWord = w;
                        this.numTrainingWordsReceived++;
                    }
                    markovChain.Train(lastWord, null);
                }

                this.numTrainingMessagesReceived++;
            }
        }
Ejemplo n.º 4
0
        /// <inheritdoc/>
        /// <summary>
        /// Initializes a new instance of the <see cref="IrcChannelEventArgs"/> class.
        /// </summary>
        /// <param name="channel">The channel that the event concerns.</param>
        public IrcChannelEventArgs(IrcChannel channel, string comment = null)
            : base(comment)
        {
            if (channel == null)
                throw new ArgumentNullException("channel");

            this.Channel = channel;
        }
Ejemplo n.º 5
0
 protected override void OnChannelMessageReceived(IrcChannel channel, IrcMessageEventArgs e)
 {
     var client = channel.Client;
     if (e.Source is IrcUser)
     {
         // TODO: keep log of recent chats?
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IrcChannelInvitationEventArgs"/> class.
        /// </summary>
        /// <param name="channel">The channel to which the recipient user is invited.</param>
        /// <param name="inviter">The user inviting the recipient user to the channel.</param>
        public IrcChannelInvitationEventArgs(IrcChannel channel, IrcUser inviter)
            : base(channel)
        {
            if (inviter == null)
                throw new ArgumentNullException("inviter");

            this.Inviter = inviter;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IrcChannelInvitationEventArgs"/> class.
        /// </summary>
        /// <param name="channel">The channel to which the recipient user is invited.</param>
        /// <param name="inviter">The user inviting the recipient user to the channel.</param>
        public IrcChannelInvitationEventArgs(IrcChannel channel, IrcUser inviter)
            : base(channel)
        {
            if (inviter == null)
            {
                throw new ArgumentNullException("inviter");
            }

            this.Inviter = inviter;
        }
Ejemplo n.º 8
0
        public ChannelBot(IrcChannel channel)
        {
            Channel = channel;

            Channel.UsersListReceived += ChannelOnUsersListReceived;
            Channel.UserJoined += ChannelOnUserJoined;
            Channel.UserLeft += ChannelOnUserLeft;
            Channel.MessageReceived += ChannelOnMessageReceived;
            Channel.Client.RawMessageSent += ClientOnRawMessageSent;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IrcChannelEventArgs"/> class.
        /// </summary>
        /// <param name="channel">The channel that the event concerns.</param>
        public IrcChannelEventArgs(IrcChannel channel, string comment)
            : base(comment)
        {
            if (channel == null)
            {
                throw new ArgumentNullException("channel");
            }

            this.Channel = channel;
        }
 protected override void OnChannelModeChanged(IrcChannel channel, IrcUser source, string newModes, IEnumerable<string> newModeParameters) { 
     // Twitch doesn't actually send JOIN messages. This means we need to add users
     // to the channel when changing their mode if we haven't already.
     foreach (string username in newModeParameters)
     {
         IrcUser user = GetUserFromNickName(username);
         if (channel.GetChannelUser(user) == null)
             channel.HandleUserJoined(new IrcChannelUser(user));
     }
 }
Ejemplo n.º 11
0
		private void MessageReceived(IrcChannel channel, string source, string text)
		{
			if(text.StartsWith("!scores"))
				ShowScores(channel);

			if(text.StartsWith("!trivia") && _currentQuestion == null)
				StartQuestion(channel);

			if(_currentQuestion != null)
				CheckForCorrectAnswer(text, channel, source);
		}
Ejemplo n.º 12
0
        public ChannelBot(IrcChannel channel)
        {
            Channel = channel;

            Channel.UsersListReceived += ChannelOnUsersListReceived;
            Channel.UserJoined += ChannelOnUserJoined;
            Channel.UserLeft += ChannelOnUserLeft;
            Channel.MessageReceived += ChannelOnMessageReceived;
            var b = new ChatterBotAPI.ChatterBotFactory().Create(ChatterBotType.CLEVERBOT);
            Bot = b.CreateSession();
            //HelloTimerOnElapsed(null, null);
        }
Ejemplo n.º 13
0
 protected override void OnChannelModeChanged(IrcChannel channel, IrcUser source, string newModes, IEnumerable <string> newModeParameters)
 {
     // Twitch doesn't actually send JOIN messages. This means we need to add users
     // to the channel when changing their mode if we haven't already.
     foreach (string username in newModeParameters)
     {
         IrcUser user = GetUserFromNickName(username);
         if (channel.GetChannelUser(user) == null)
         {
             channel.HandleUserJoined(new IrcChannelUser(user));
         }
     }
 }
Ejemplo n.º 14
0
 public static bool CheckOp(string UserNick, IrcChannel Channel)
 {
     foreach (IrcChannelUser user in Channel.Users)
     {
         if (user.User.NickName == UserNick && (user.Modes.Contains('o') || user.Modes.Contains('h')))
         {
             return true;
         }//if (user.User.NickName == e.Source.Name && (user.Modes.Contains('o') || user.Modes.Contains('h')))
         else if (user.User.NickName == UserNick && (!user.Modes.Contains('o') && !user.Modes.Contains('h')))
         {
             return false;
         }
     }//foreach (IrcChannelUser user in Channel.Users)
     return false;
 }
Ejemplo n.º 15
0
 public static bool CheckOwner(string OwnerIdentity, IrcChannel Channel)
 {
     foreach(IrcChannelUser user in Channel.Users)
     {
         if (user.User.HostName == OwnerIdentity)
         {
             return true;
         }
         else
         {
             return false;
         }
     }
     return false;
 }
Ejemplo n.º 16
0
		private void CheckForCorrectAnswer(string text, IrcChannel channel, string source)
		{
			if (_currentQuestion.Answers.Contains(text.ToLower()))
			{
				_bot.Say(channel.Name, source + " rocks!");
				_currentQuestion = null;

				AddToScores(source);
				
				if(_scores.Sum(x => x.Points) == 10)
				{
					_bot.Say(channel.Name, _scores.OrderBy(s => s.Points).Reverse().First().Nickname + " is the winner");
					ShowScores(channel);
					_scores.Clear();
				}
				else
				{
					StartQuestion(channel);
				}
			}
		}
Ejemplo n.º 17
0
        private void ChannelOnMessageReceived(object sender, IrcMessageEventArgs e, IrcDotNet.IrcChannel channel)
        {
            IrcLocalUser localUser = sender as IrcLocalUser;

            if (localUser == null)
            {
                return;
            }

            MessageEventArgs args = new MessageEventArgs(new IrcMessage(e.Text), new IrcServer(_clients.Keys.First(x => x.LocalUser.Equals(localUser)), _uploader),
                                                         new IrcChannel(channel, _uploader),
                                                         new IrcUser(channel.Users.FirstOrDefault(x => x.User.NickName == e.Source.Name)?.User, _uploader));

            // Since we can't really listen to outgoing accurately, we can abuse this to get our message sent event.
            if (e.Source.Name == localUser.NickName)
            {
                MessageSent?.Invoke(this, args);
                return;
            }

            MessageReceived?.Invoke(this, args);
        }
Ejemplo n.º 18
0
 private void SubscribeToChannelEvents(IrcChannel channel)
 {
     channel.MessageReceived += OnChannelMessageReceived;
     channel.UserLeft += OnUserLeft;
 }
Ejemplo n.º 19
0
 internal IrcChannelUserCollection(IrcChannel channel, ObservableCollection <IrcChannelUser> list)
     : base(list)
 {
     this.channel = channel;
 }
Ejemplo n.º 20
0
 internal void HandleInviteReceived(IrcUser inviter, IrcChannel channel)
 {
     OnInviteReceived(new IrcChannelInvitationEventArgs(channel, inviter));
 }
Ejemplo n.º 21
0
 internal void HandleInviteReceived(IrcUser inviter, IrcChannel channel)
 {
     OnInviteReceived(new IrcChannelInvitationEventArgs(channel, inviter));
 }
Ejemplo n.º 22
0
 internal void SetChannelModes(IrcChannel channel, string modes, IEnumerable<string> modeParameters = null)
 {
     SendMessageChannelMode(channel.Name, modes, modeParameters);
 }
Ejemplo n.º 23
0
        /// <summary>
        /// Gets the channel with the specified name, creating it if necessary.
        /// </summary>
        /// <param name="channelName">The name of the channel.</param>
        /// <param name="createdNew"><see langword="true"/> if the channel object was created during the call;
        /// <see langword="false"/>, otherwise.</param>
        /// <returns>The channel object that corresponds to the specified name.</returns>
        protected IrcChannel GetChannelFromName(string channelName, out bool createdNew)
        {
            if (channelName == null)
                throw new ArgumentNullException("channelName");
            if (channelName.Length == 0)
                throw new ArgumentException(Properties.Resources.MessageValueCannotBeEmptyString, "channelName");

            // Search for channel with given name in list of known channel. If it does not exist, add it.
            lock (((ICollection)this.channelsReadOnly).SyncRoot)
            {
                var channel = this.channels.SingleOrDefault(c => c.Name == channelName);
                if (channel == null)
                {
                    channel = new IrcChannel(channelName);
                    channel.Client = this;
                    this.channels.Add(channel);

                    createdNew = true;
                }
                else
                {
                    createdNew = false;
                }

                return channel;
            }
        }
Ejemplo n.º 24
0
 internal void Invite(IrcChannel channel, string userNickName)
 {
     SendMessageInvite(channel.Name, userNickName);
 }
Ejemplo n.º 25
0
 internal void Kick(IrcChannel channel, IEnumerable<string> usersNickNames, string comment = null)
 {
     SendMessageKick(channel.Name, usersNickNames, comment);
 }
 internal IrcChannelUserCollection(IrcChannel channel, IList <IrcChannelUser> list)
     : base(list)
 {
     this.channel = channel;
 }
Ejemplo n.º 27
0
 protected virtual void OnChannelModeChanged(IrcChannel channel, IrcUser source, string newModes,
                                             IEnumerable <string> newModeParameters)
 {
 }
Ejemplo n.º 28
0
 protected virtual void OnChannelUserJoined(IrcChannel channel, IrcChannelUserEventArgs e)
 {
 }
Ejemplo n.º 29
0
 protected override void OnChannelMessageReceived(IrcChannel channel, IrcMessageEventArgs e)
 {
     using (var logger = new StatsLogger()) {
         logger.LogMessage(e.Text, e.Source.Name, DateTime.UtcNow, channel.Name);
     }
 }
Ejemplo n.º 30
0
 protected virtual void OnChannelMessageReceived(IrcChannel channel, IrcMessageEventArgs e)
 {
 }
Ejemplo n.º 31
0
 internal void HandleJoinedChannel(IrcChannel channel)
 {
     OnJoinedChannel(new IrcChannelEventArgs(channel, null));
 }
Ejemplo n.º 32
0
 protected override void OnChannelTopicChanged(IrcChannel channel, EventArgs e)
 {
     using (var logger = new StatsLogger()) {
         logger.LogTopicChange(channel.Topic, channel.Name, DateTime.UtcNow);
     }
 }
Ejemplo n.º 33
0
 protected virtual void OnChannelUserLeft(IrcChannel channel, IrcChannelUserEventArgs e)
 {
 }
Ejemplo n.º 34
0
 protected override void OnChannelUserLeft(IrcChannel channel, IrcChannelUserEventArgs e)
 {
     //
 }
Ejemplo n.º 35
0
 /// <summary>
 /// </summary>
 /// <param name="channel">
 /// </param>
 /// <param name="e">
 /// </param>
 protected override void OnChannelMessageReceived(IrcChannel channel, IrcMessageEventArgs e)
 {
     this.RelayedChannel.ChannelMessage(this.nickname + "-" + e.Source.Name, e.Text);
 }
Ejemplo n.º 36
0
 /// <summary>
 /// </summary>
 /// <param name="channel">
 /// </param>
 /// <param name="e">
 /// </param>
 protected abstract void OnChannelNoticeReceived(IrcChannel channel, IrcMessageEventArgs e);
Ejemplo n.º 37
0
 internal void HandleLeftChannel(IrcChannel channel)
 {
     OnLeftChannel(new IrcChannelEventArgs(channel, null));
 }
Ejemplo n.º 38
0
 /// <summary>
 /// </summary>
 /// <param name="channel">
 /// </param>
 /// <param name="e">
 /// </param>
 protected abstract void OnChannelUserLeft(IrcChannel channel, IrcChannelUserEventArgs e);
 protected virtual void OnChannelModeChanged(IrcChannel channel, IrcUser source, string newModes,
     IEnumerable<string> newModeParameters)
 {
 }
Ejemplo n.º 40
0
 protected override void OnChannelUserJoined(IrcChannel channel, IrcChannelUserEventArgs e)
 {
     SendGreeting(channel.Client.LocalUser, e.ChannelUser.User);
 }
Ejemplo n.º 41
0
 /// <summary>
 /// </summary>
 /// <param name="channel">
 /// </param>
 /// <param name="e">
 /// </param>
 protected abstract void OnChannelUserJoined(IrcChannel channel, IrcChannelUserEventArgs e);
Ejemplo n.º 42
0
 protected override void OnChannelUserLeft(IrcChannel channel, IrcChannelUserEventArgs e)
 {
     //
 }
Ejemplo n.º 43
0
 protected override void OnChannelUserJoined(IrcChannel channel, IrcChannelUserEventArgs e)
 {
     SendGreeting(channel.Client.LocalUser, e.ChannelUser.User);
 }
Ejemplo n.º 44
0
 protected override void OnChannelMessageReceived(IrcChannel channel, IrcMessageEventArgs e)
 {
     //
 }
Ejemplo n.º 45
0
 protected override void OnChannelMessageReceived(IrcChannel channel, IrcMessageEventArgs e)
 {
     //
 }
Ejemplo n.º 46
0
 internal void GetChannelModes(IrcChannel channel, string modes = null)
 {
     SendMessageChannelMode(channel.Name, modes);
 }