Ejemplo n.º 1
0
        private void Aliases_CallAlias(object sender, AliasEventArgs e)
        {
            if (e.Name == AliasName && e.To.IsChannel && e.Arguments.Count > 0)
            {
                var    nick = e.Arguments[0];
                string msg  = null;
                if (string.Compare(nick, e.From.Nickname, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    msg = "Don't be so hard on yourself.";
                }
                else
                {
                    if (reflect.Contains(nick, StringComparer.OrdinalIgnoreCase))
                    {
                        nick = e.From.Nickname;
                    }

                    var insult = this.GenerateInsult();
                    if (insult.Length > 0)
                    {
                        msg = string.Format("{0} is a{1} {2}", nick, Vowels.Contains(char.ToLower(insult[0])) ? "n" : "", insult);
                    }
                }
                this.Irc.PrivateMessage(e.ReplyTo, msg);
            }
        }
Ejemplo n.º 2
0
        public void LinkRequest(object sender, AliasEventArgs e)
        {
            if (e.Name == LinkAliasName || e.Name == LinkDescName)
            {
                int idx = 0;
                if (e.Arguments.Count > 0)
                {
                    int.TryParse(e.Arguments[0], out idx);
                }
                if (idx < 0 || idx > _allItems.Count - 1)
                {
                    this.Irc.PrivateMessage(e.ReplyTo, "No such item exists.");
                }
                else
                {
                    var item = _allItems.Last;
                    while (--idx >= 0)
                    {
                        item = item.Previous;
                    }

                    if (e.Name == LinkAliasName)
                    {
                        this.Irc.PrivateMessage(e.ReplyTo, item.Value.Link);
                    }
                    else
                    {
                        foreach (var s in item.Value.Description.StripHtml().WordBreak(LineLength))
                        {
                            this.Irc.PrivateMessage(e.ReplyTo, s);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void LinkRequest(object sender, AliasEventArgs e)
        {
            if (e.Name == LinkAliasName || e.Name == LinkDescName)
            {
                int idx = 0;
                if (e.Arguments.Count > 0)
                {
                    int.TryParse(e.Arguments[0], out idx);
                }
                if (idx < 0 || idx > _allItems.Count - 1)
                {
                    this.Irc.PrivateMessage(e.ReplyTo, "No such item exists.");
                }
                else
                {
                    var item = _allItems.Last;
                    while (--idx >= 0)
                    {
                        item = item.Previous;
                    }

                    if (e.Name == LinkAliasName)
                    {
                        this.Irc.PrivateMessage(e.ReplyTo, item.Value.Link);
                    }
                    else
                    {
                        foreach (var s in item.Value.Description.StripHtml().WordBreak(LineLength))
                        {
                            this.Irc.PrivateMessage(e.ReplyTo, s);
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
 private void Aliases_CallAlias(object sender, AliasEventArgs e)
 {
     if (e.Name.ToLower() == "quit")
     {
         try
         {
             Security.Demand(e.From, "bot");
         }
         catch (System.Security.SecurityException)
         {
             return;
         }
         this.Stop();
     }
 }
Ejemplo n.º 5
0
        private void Aliases_CallAlias(object sender, AliasEventArgs e)
        {
            if (e.Name == AliasName && e.To.IsChannel && e.Arguments.Count > 0)
            {
                var nick = e.Arguments[0];
                string msg = null;
                if (string.Compare(nick, e.From.Nickname, StringComparison.OrdinalIgnoreCase) == 0) {
                    msg = "Don't be so hard on yourself.";
                } else {
                    if (reflect.Contains(nick, StringComparer.OrdinalIgnoreCase))
                        nick = e.From.Nickname;

                    var insult = this.GenerateInsult();
                    if (insult.Length > 0)
                        msg = string.Format("{0} is a{1} {2}", nick, Vowels.Contains(char.ToLower(insult[0])) ? "n" : "", insult);
                }
                this.Irc.PrivateMessage(e.ReplyTo, msg);
            }
        }
Ejemplo n.º 6
0
 private void AliasModule_CallAlias(object sender, AliasEventArgs e)
 {
     if (e.Name == TrainAlias && e.Arguments.Count == 1)
     {
         try
         {
             this.Train(e.Arguments[0]);
             Irc.PrivateMessage(e.ReplyTo, TrainComplete);
         }
         catch (IOException ex)
         {
             Irc.PrivateMessage(e.ReplyTo, string.Format(TrainFailed, ex.Message));
         }
     }
     else if (e.Name == StatsAlias)
     {
         Irc.PrivateMessage(e.ReplyTo, "Total unique symbols: " + _model.SymbolCount);
         Irc.PrivateMessage(e.ReplyTo, "Total unique tuples: " + _model.TotalTupleCount);
         Irc.PrivateMessage(e.ReplyTo, "Total nodes: " + _model.TotalNodeCount);
         Irc.PrivateMessage(e.ReplyTo, "Memory usage: " + _model.TotalBytesUsed);
     }
 }
Ejemplo n.º 7
0
 private void AliasModule_CallAlias(object sender, AliasEventArgs e)
 {
     if (e.Name == TrainAlias && e.Arguments.Count == 1)
     {
         try
         {
             this.Train(e.Arguments[0]);
             Irc.PrivateMessage(e.ReplyTo, TrainComplete);
         }
         catch (IOException ex)
         {
             Irc.PrivateMessage(e.ReplyTo, string.Format(TrainFailed, ex.Message));
         }
     }
     else if (e.Name == StatsAlias)
     {
         Irc.PrivateMessage(e.ReplyTo, "Total unique symbols: " + _model.SymbolCount);
         Irc.PrivateMessage(e.ReplyTo, "Total unique tuples: " + _model.TotalTupleCount);
         Irc.PrivateMessage(e.ReplyTo, "Total nodes: " + _model.TotalNodeCount);
         Irc.PrivateMessage(e.ReplyTo, "Memory usage: " + _model.TotalBytesUsed);
     }
 }
Ejemplo n.º 8
0
        private void TriviaRequest(object sender, AliasEventArgs e)
        {
            if (!e.To.IsChannel)
            {
                return;
            }

            var chan = e.To.Name;
            string user = e.From.Prefix;

            switch (e.Name)
            {
                case AbortName:
                    {
                        if (!_games.ContainsKey(chan) || _games[chan].Aborts.Contains(user))
                        {
                            return;
                        }
                        _games[chan].Aborts.Add(user);
                        if (_games[chan].Aborts.Count >= this.RequestThreshold)
                        {
                            this.TriviaGameOver(e.To);
                        }
                    }
                    break;
                case SkipName:
                    {
                        if (!_games.ContainsKey(chan) || _games[chan].Skips.Contains(user))
                        {
                            return;
                        }
                        _games[chan].Skips.Add(user);
                        if (_games[chan].Skips.Count >= this.SkipThreshold)
                        {
                            this.TriviaNextQuestion(e.To, false);
                        }
                    }
                    break;
                case TriviaName:
                    {
                        if (_games.ContainsKey(chan))
                        {
                            return;
                        }

                        if (!_requests.ContainsKey(chan))
                        {
                            _requests.Add(chan, new HashSet<string>());
                        }
                        if (!_requests[chan].Contains(user))
                        {
                            _requests[chan].Add(user);
                        }
                        else
                        {
                            return;
                        }

                        if (_requests[chan].Count >= this.RequestThreshold)
                        {
                            this.Irc.PrivateMessage(e.To, TriviaServedMessage);
                            _requests[chan].Clear();
                            if (_reqTimers.ContainsKey(chan))
                            {
                                if (_reqTimers[chan] != null)
                                {
                                    _reqTimers[chan].Cancel();
                                }
                                _reqTimers.Remove(chan);
                            }
                            TriviaStart(e.To);
                        }
                        else
                        {
                            string s = string.Format(TriviaRequestMessage, e.From.Nickname, chan);
                            if (this.RequestThreshold - _requests[chan].Count == 1)
                            {
                                s += " " + TriviaOneMore;
                            }
                            this.Irc.PrivateMessage(e.To, s);
                            if (!_reqTimers.ContainsKey(chan))
                            {
                                _reqTimers.Add(chan,
                                    new Timer(this.Dispatcher, (EventHandler)((s2, o) =>
                                    {
                                        this.Irc.PrivateMessage(e.To, TriviaReqExpire);
                                        _requests[chan].Clear();
                                        _reqTimers.Remove(chan);
                                    }
                                ), this.RequestExpire * 1000, chan));
                            }
                        }
                    }
                    break;
            }
        }
Ejemplo n.º 9
0
 private void Aliases_CallAlias(object sender, AliasEventArgs e)
 {
     if (e.Name.ToLower() == "quit")
     {
         try
         {
             Security.Demand(e.From, "bot");
         }
         catch (System.Security.SecurityException)
         {
             return;
         }
         this.Stop();
     }
 }