示例#1
0
 private void OnCallAlias(IrcMessageEventArgs e, string name, string[] arguments)
 {
     var evt = this.CallAlias;
     if (evt != null)
     {
         evt(this, new AliasEventArgs(name, arguments, e.From, e.To, e.To.IsChannel ? e.To : new IrcTarget(e.From)));
     }
 }
示例#2
0
		private void Session_PrivateMessaged(object sender, IrcMessageEventArgs e)
		{
			if (App.IsIgnoreMatch(e.From, e.To.IsChannel ? IgnoreActions.Channel : IgnoreActions.Private))
			{
				return;
			}

			if (!this.IsServer)
			{
				if ((this.Target.IsChannel && this.Target.Equals(e.To)) ||
					(!this.Target.IsChannel && this.Target.Equals(new IrcTarget(e.From)) && !e.To.IsChannel))
				{
					bool attn = false;
					if (App.IsAttentionMatch(this.Session.Nickname, e.Text))
					{
						attn = true;
						if (_window != null)
						{
							App.Alert(_window, string.Format("You received an alert from {0}", this.Target.Name));
						}
						if (this.VisualParent == null)
						{
							this.NotifyState = NotifyState.Alert;
							App.DoEvent("inactiveAlert");
						}
						else if (_window != null && !_window.IsActive)
						{
							App.DoEvent("inactiveAlert");
						}
						else
						{
							App.DoEvent("activeAlert");
						}
					}

					this.Write("Default", e.From, e.Text, attn);
					if (!this.Target.IsChannel)
					{
						if (e.From.Prefix != _prefix)
						{
							_prefix = e.From.Prefix;
							this.SetTitle();
						}
						Interop.WindowHelper.FlashWindow(_window);
						if (this.VisualParent == null)
						{
							App.DoEvent("privateMessage");
						}
					}
				}
			}
		}
示例#3
0
		private void Session_Noticed(object sender, IrcMessageEventArgs e)
		{
			if (App.IsIgnoreMatch(e.From, IgnoreActions.Notice))
			{
				return;
			}

			if (this.IsServer)
			{
				if (e.From is IrcPeer)
				{
					this.Write("Notice", (IrcPeer)e.From, e.Text, false);
				}
				else if (this.IsServer)
				{
					this.Write("Notice", e.Text);
				}
				App.DoEvent("notice");
			}
		}
示例#4
0
        private void Irc_PrivateMessaged(object sender, IrcMessageEventArgs e)
        {
            if (string.Compare(e.From.Nickname, this.Irc.Nickname, true) == 0)
            {
                return;
            }

            string line = e.Text.Trim();

            if (line.StartsWith(this.Prefix, StringComparison.Ordinal) && line.Length > this.Prefix.Length)
            {
                string aliasName = line.Substring(this.Prefix.Length).Split(' ')[0];
                string paramString = "";
                int firstSpace = line.IndexOf(' ');
                if (firstSpace >= 0 && line.Length > firstSpace + 1)
                {
                    paramString = line.Substring(firstSpace + 1);
                }
                this.OnCallAlias(e, aliasName, StringTokenizer.Tokenize(paramString).ToArray());
            }
        }
示例#5
0
        private void Session_PrivateMessaged(object sender, IrcMessageEventArgs e)
        {
            if (App.IsIgnoreMatch(e.From, e.To.IsChannel ? IgnoreActions.Channel : IgnoreActions.Private))
            {
                return;
            }

            if (!this.IsServer)
            {
                if ((this.Target.IsChannel && this.Target.Equals(e.To)) ||
                    (!this.Target.IsChannel && this.Target.Equals(new IrcTarget(e.From)) && !e.To.IsChannel))
                {
                    bool attn = false;
                    if (App.IsAttentionMatch(this.Session.Nickname, e.Text))
                    {
                        attn = true;
                        if (_window != null)
                        {
                            App.Alert(_window, string.Format("You received an alert from {0}", this.Target.Name));
                        }
                        if (this.VisualParent == null)
                        {
                            this.NotifyState = NotifyState.Alert;
                            App.DoEvent("inactiveAlert");
                        }
                        else if (_window != null && !_window.IsActive)
                        {
                            App.DoEvent("inactiveAlert");
                        }
                        else
                        {
                            App.DoEvent("activeAlert");
                        }
                    }

                    if (e.From.Prefix.Equals("*[email protected]"))
                    {
                        int space = e.Text.IndexOf(' ');
                        String subject = e.Text.Substring(0, space);
                        String text = e.Text.Substring(space + 1);

                        IrcPeer peer = new IrcPeer(subject);
                        String styleKey = "Default";

                        // TODO: Rewrite text if it doesn't match how Floe writes it.
                        if (text.StartsWith("set mode")) // sNickMask + " set mode: " + sModes + " " + sArgs
                        {
                            styleKey = "Mode";
                        }
                        else if (text.StartsWith("kicked")) // OpNick.GetNickMask() + " kicked " + sKickedNick + " Reason: [" + sMessage + "]"
                        {
                            styleKey = "Kick";
                        }
                        else if (text.StartsWith("quit")) // Nick.GetNickMask() + " quit with message: [" + sMessage + "]"
                        {
                            styleKey = "Quit";
                        }
                        else if (text.StartsWith("joined")) // Nick.GetNickMask() + " joined"
                        {
                            styleKey = "Join";
                        }
                        else if (text.StartsWith("parted")) // Nick.GetNickMask() + " parted with message: [" + sMessage + "]"
                        {
                            styleKey = "Part";
                        }
                        else if (text.StartsWith("is now known as")) // OldNick.GetNickMask() + " is now known as " + sNewNick
                        {
                            styleKey = "Nick";
                        }
                        else if (text.StartsWith("changed the topic")) // Nick.GetNickMask() + " changed the topic to: " + sTopic
                        {
                            styleKey = "Topic";
                        }
                        this.Write(styleKey, e.Message.Time, string.Format("{0} {1}", peer.Nickname, text));
                    }
                    else
                    {
                        this.Write("Default", e.Message.Time, e.From, e.Text, attn);

                        if (!this.Target.IsChannel)
                        {
                            if (e.From.Prefix != _prefix)
                            {
                                _prefix = e.From.Prefix;
                                this.SetTitle();
                            }
                            Interop.WindowHelper.FlashWindow(_window);
                            if (this.VisualParent == null)
                            {
                                App.DoEvent("privateMessage");
                            }
                        }
                    }
                }
            }
        }
示例#6
0
        private void TriviaGuess(object sender, IrcMessageEventArgs e)
        {
            if (!e.To.IsChannel || !_games.ContainsKey(e.To.Name))
            {
                return;
            }

            string chan = e.To.Name;
            if (_games[chan].State != GameState.Asked)
            {
                return;
            }
            if (_games[chan].Provider.CheckAnswer(e.Text.Trim().ToLower()))
            {
                this.Irc.PrivateMessage(e.To, string.Format(QuestionCorrect, e.From.Nickname, _games[chan].Provider.PrimaryAnswer));
                if (!_games[chan].Scores.ContainsKey(e.From.Nickname))
                {
                    _games[chan].Scores.Add(e.From.Nickname, 0);
                }
                _games[chan].Scores[e.From.Nickname]++;
                TriviaNextQuestion(e.To, true);
            }
        }
示例#7
0
        private void Irc_PrivateMessage(object sender, IrcMessageEventArgs e)
        {
            if (string.Compare(e.From.Nickname, this.Irc.Nickname, true) == 0)
            {
                return;
            }

            string line = e.Text.Trim();
            if (line.StartsWith(this.Prefix) && line.Length > this.Prefix.Length)
            {
                try
                {
                    this.Security.Demand(e.From, this.ExecutePermission);
                }
                catch (System.Security.SecurityException)
                {
                    // Just ignore unauthorized commands.
                    return;
                }

                this.Execute(e.To.IsChannel ? e.To : new IrcTarget(e.From), line.Substring(this.Prefix.Length));
            }
        }
示例#8
0
 private void PrivateMessage(object sender, IrcMessageEventArgs e)
 {
     if (e.To.IsChannel)
     {
         string raw = e.Text.Trim();
         if (raw.Length > this.Irc.Nickname.Length &&
             raw.StartsWith(this.Irc.Nickname, StringComparison.CurrentCultureIgnoreCase) &&
             AttnChars.IndexOf(raw[this.Irc.Nickname.Length]) >= 0)
         {
             string text = raw.Substring(this.Irc.Nickname.Length + 1).Trim();
             string reply = _model.Query(text);
             if (!string.IsNullOrEmpty(reply))
             {
                 this.Irc.PrivateMessage(e.To, reply);
             }
             else
             {
                 if (!string.IsNullOrEmpty(NoReply))
                     this.Irc.PrivateMessage(e.To, NoReply);
             }
         }
         else
         {
             _model.Learn(raw);
         }
     }
 }