Beispiel #1
0
        public Token(MessageSource source)
        {
            Expiration = DateTime.Now.AddMinutes(1);

            byte[] rnd = new byte[8];
            Random.GetBytes(rnd);

            byte[] key = new byte[16];
            source.GetHash().CopyTo(key, 0);
            rnd.CopyTo(key, 8);

            Key = BitConverter.ToString(key).ToLower().Replace("-", "");

            if (source.Notice)
            {
                Key = Key.Substring(0, Key.Length - 1) + 'n';
            }

            Source = source;
        }
Beispiel #2
0
        private void ChannelMessage(object sender, PrivateMessageEventArgs e)
        {
            IrcClient client = (IrcClient)sender;

            if (!client.authed)
            {
                client.authact();
            }

            var    source = new MessageSource(client, e.PrivateMessage.Source);
            string id     = BitConverter.ToString(source.GetHash()).ToLower().Replace("-", "");

            if ((Config.Contains("ignored", e.PrivateMessage.User.Nick) || Config.Contains("ignored", id + "/" + e.PrivateMessage.User.Nick)) && e.PrivateMessage.User.Nick != client.Owner)
            {
                return;
            }

            //Triggers.ForEach(t => t.ExecuteIfMatches(e.IrcMessage, client));

            string msg    = e.PrivateMessage.Message;
            bool   authed = e.PrivateMessage.User.Nick == client.Owner;

            if (msg.StartsWith("$rehash") && authed)
            {
                foreach (string str in Program.GetModules())
                {
                    Program.Connection.SendMessage("", "rehash", str);
                }

                Config.Load();

                client.SendMessage("done", e.PrivateMessage.Source);
            }

            bool quiet_mode = ((ConnectionOptions)source.Client.Options).Quiet;

            if (!quiet_mode)
            {
                if (msg.StartsWith("$whatmatches") && authed)
                {
                    string args = msg.Substring("$whatmatches".Length).Trim();

                    foreach (Trigger t in Triggers)
                    {
                        if (t.Matches(args))
                        {
                            client.SendMessage(string.Format("{0}: matches {1}", t.ID, t), e.PrivateMessage.Source);
                        }
                    }

                    return;
                }
            }

            if (!(authed && msg.StartsWith("$")))
            {
                foreach (Trigger t in Triggers)
                {
                    string result = t.ExecuteIfMatches(e.IrcMessage, client);
                    if (result != "")
                    {
                        msg = result;
                        if (result.StartsWith("$"))
                        {
                            authed = true;
                        }

                        if (t.StopExecution)
                        {
                            break;
                        }
                    }
                }
            }

            if (!quiet_mode)
            {
                if (msg.StartsWith("$ignoremodule"))
                {
                    if (authed)
                    {
                        IgnoreModules.Add(new KeyValuePair <string, string>(msg.Substring("$ignoremodule".Length), e.PrivateMessage.Source));
                    }
                    return;
                }
                else if (msg.StartsWith("$meow"))
                {
                    if (authed)
                    {
                        int count = int.Parse(msg.Split(' ')[1]);

                        client.SendMessage(MacBotGen.GenerateMacBot(count, true), e.PrivateMessage.Source);
                    }
                    return;
                }
                else if (msg.StartsWith("$registered"))
                {
                    if (authed)
                    {
                        Task.Factory.StartNew(delegate
                        {
                            client.SendMessage(IsRegistered(client, msg.Substring("$registered".Length).Trim()).ToString(), e.PrivateMessage.Source);
                            return;
                        });
                    }
                }
                else if (msg.StartsWith(".bang"))
                {
                    client.KickUser(e.PrivateMessage.Source, e.PrivateMessage.User.Nick, "There you f*****g go");
                }
                else if (msg.StartsWith(".permabang"))
                {
                    Task.Factory.StartNew(delegate
                    {
                        client.SendRawMessage("MODE {0} +b *!*@{1}", e.PrivateMessage.Source, e.PrivateMessage.User.Hostname);
                        client.KickUser(e.PrivateMessage.Source, e.PrivateMessage.User.Nick, "Consequences will never be the same");

                        Thread.Sleep(10000);

                        client.SendRawMessage("MODE {0} -b *!*@{1}", e.PrivateMessage.Source, e.PrivateMessage.User.Hostname);
                        client.InviteUser(e.PrivateMessage.Source, e.PrivateMessage.User.Nick);
                    });
                }
                else if (msg.StartsWith("$unignoremodule"))
                {
                    if (authed)
                    {
                        IgnoreModules.RemoveAll(p => p.Value == e.PrivateMessage.Source && p.Key == msg.Substring("$unignoremodule".Length));
                    }
                    return;
                }
                else if (msg.StartsWith(".prebots"))
                {
                    if (authed)
                    {
                        client.SendMessage("Reporting in! [C#] https://github.com/hexafluoride/topkek", msg.Split(' ')[1]);
                        LastBots = DateTime.Now;
                    }
                    return;
                }
                else if (msg.StartsWith("$addtrigger"))
                {
                    if (authed)
                    {
                        Trigger trigger = Trigger.ParseTrigger(msg.Substring("$addtrigger".Length));
                        Triggers.Add(trigger);

                        client.SendMessage(string.Format("Use 11$removetrigger {0} to remove this trigger.", trigger.ID), e.PrivateMessage.Source);
                    }
                    return;
                }
                else if (msg.StartsWith("$removetrigger"))
                {
                    if (authed)
                    {
                        string ID = msg.Substring("$removetrigger".Length).Trim();

                        Triggers.RemoveAll(t => t.ID == ID);
                        client.SendMessage(string.Format("Removed trigger 11{0}.", ID), e.PrivateMessage.Source);
                    }
                    return;
                }
                else if (msg.StartsWith(".bots"))
                {
                    if ((DateTime.Now - LastBots).TotalSeconds < 3)
                    {
                        return;
                    }
                    client.SendMessage("Reporting in! [C#]", e.PrivateMessage.Source);
                    return;
                }
                else if (msg == "$leave")
                {
                    if (authed)
                    {
                        client.PartChannel(e.PrivateMessage.Source, "Bye!");
                    }
                    return;
                }
                else if (msg.StartsWith("$say"))
                {
                    if (authed)
                    {
                        client.SendMessage(msg.Substring("$say".Length).Trim(), e.PrivateMessage.Source);
                    }
                    return;
                }
                else if (msg.StartsWith("$raw"))
                {
                    if (authed)
                    {
                        client.SendRawMessage(msg.Substring("$raw".Length).Trim());
                    }
                    return;
                }
                else if (msg == "^")
                {
                    client.SendMessage("can confirm", e.PrivateMessage.Source);
                    return;
                }
                else if (msg.StartsWith("$join"))
                {
                    if (authed)
                    {
                        client.JoinChannel(msg.Substring(".join".Length).Trim());
                    }
                    return;
                }
                else if (msg.StartsWith("$macbot"))
                {
                    if (authed)
                    {
                        int count = int.Parse(msg.Split(' ')[1]);

                        client.SendMessage(MacBotGen.GenerateMacBot(count), e.PrivateMessage.Source);
                    }
                    return;
                }
                else if (msg.StartsWith("rape"))
                {
                    msg = msg.Trim();

                    if (!msg.Contains(" "))
                    {
                        return;
                    }

                    if (!client.Channels[e.PrivateMessage.Source].Users.Any(user => user.Nick == msg.Split(' ')[1]))
                    {
                        return;
                    }

                    string nick = msg.Split(' ')[1];

                    client.SendAction(string.Format("rapes {0}", nick), e.PrivateMessage.Source);
                }
                else if (msg.ToLower() == "who's a healer s**t" || msg.ToLower() == "who's the healer s**t")
                {
                    client.SendMessage(string.Format("I-I am, {0}~", e.PrivateMessage.User.Nick), e.PrivateMessage.Source);
                }
                else if (MatchesHealRequest(msg) && !dontheal.Contains(e.PrivateMessage.User.Nick))
                {
                    msg = msg.Trim();

                    string nick = e.PrivateMessage.User.Nick;

                    if (msg.Contains(" "))
                    {
                        if (client.Channels[e.PrivateMessage.Source].Users.Any(user => user.Nick == msg.Split(' ')[1] && !dontheal.Contains(user.Nick)))
                        {
                            nick = msg.Split(' ')[1];
                        }
                    }
                    double rnd = MacBotGen.Random.NextDouble();
                    if (msg.ToLower().EndsWith("s**t") || msg.ToLower().EndsWith("w***e") || msg.ToLower().EndsWith("bıtch") || msg.ToLower().EndsWith("bitch"))
                    {
                        if (rnd < 0.9 && !authed)
                        {
                            client.SendAction(string.Format("h-heals {0} (3+{1} HP~!)", nick, MacBotGen.Random.Next(90, 110)), e.PrivateMessage.Source);
                        }
                        else
                        {
                            client.SendAction(string.Format("h-heals {0} (3+{1} HP~! Critical heal~!)", nick, MacBotGen.Random.Next(250, 300)), e.PrivateMessage.Source);
                        }
                    }
                    else
                    {
                        if (rnd < 0.9 && !authed)
                        {
                            client.SendAction(string.Format("heals {0} (3+{1} HP!)", nick, MacBotGen.Random.Next(90, 110)), e.PrivateMessage.Source);
                        }
                        else
                        {
                            client.SendAction(string.Format("heals {0} (3+{1} HP! Critical heal!)", nick, MacBotGen.Random.Next(250, 300)), e.PrivateMessage.Source);
                        }
                    }

                    return;
                }
                else if (msg.StartsWith("$spam"))
                {
                    if (authed)
                    {
                        int amount = int.Parse(msg.Split(' ')[1]);

                        Task.Factory.StartNew(delegate
                        {
                            for (int i = 0; i < amount; i++)
                            {
                                client.SendMessage(GenerateRandom(), e.PrivateMessage.Source);
                                System.Threading.Thread.Sleep(1000);
                            }
                        });
                    }
                }

                if (msg.StartsWith("$ignore"))
                {
                    if (authed)
                    {
                        string nick = msg.Substring(".ignore".Length).Trim();

                        Config.Add("ignored", id + "/" + nick);
                        Config.Save();
                        //Ignore.Add(msg.Substring(".ignore".Length).Trim());
                    }
                    return;
                }
                else if (msg.StartsWith("$unignore"))
                {
                    if (authed)
                    {
                        string nick = msg.Substring(".unignore".Length).Trim();

                        Config.Remove("ignored", id + "/" + nick);
                        Config.Save();
                    }
                    return;
                }
            }

            Token token = TokenManager.GetToken(new MessageSource(client, e.PrivateMessage.Source));

            e.PrivateMessage.Message = msg;

            if (OnMessage != null)
            {
                OnMessage(e.PrivateMessage, token);
            }
        }