Beispiel #1
0
        public void Execute(IrcDotNet.IrcClient Client, string Channel, IrcDotNet.IrcUser Sender, string Message)
        {
            try
            {
                if (Message.Trim() == "")
                {
                    Say(Channel, ReadRandomEntry("fi"), Client);
                    return;
                }

                string[] messageAsArray = Message.Trim().Split(' ');

                if (messageAsArray[0].ToLower() == "en")
                {
                    Say(Channel, ReadRandomEntry("en"), Client);
                    return;
                }
                else if (messageAsArray[0].ToLower() == "fi")
                {
                    Say(Channel, ReadRandomEntry("fi"), Client);
                    return;
                }

                string wikiEntry = ReadWikiEntry(Message);

                Say(Channel, wikiEntry, Client);
            }
            catch (Exception e)
            {
                Say(Channel, e.Message, Client);
            }
        }
Beispiel #2
0
        public void handle(RegistrationInfoFactory infoFactory, IrcDotNet.IrcClient client, FehBot bot, IMongoDatabase db, IrcDotNet.IrcUser from, IrcDotNet.IrcChannel channel, string message)
        {
            if (channel == null)
            {
                return;
            }

            if (isKarmaRequest(message))
            {
                var request = parseKarmaRequest(message);
                request.Keys.ForEach(nick => {
                    Karma document = db.UpdateKarma(nick, channel.Name, infoFactory.Server, request[nick]);

                    string template = request[nick] > 0 ? "{0} gained a level! (Karma: {1})":"{0} lost a level! (Karma: {1})";
                    client.LocalUser.SendMessage(channel, String.Format(template, nick, document.Score));
                    JObject body = new JObject();

                    body.Add("nick", document.Nick);
                    body.Add("from", from.NickName);
                    body.Add("score", document.Score);
                    body.Add("channel", document.Channel);
                    body.Add("direction", request[nick]);
                    callWebHook(db, body);
                });
            }
        }
Beispiel #3
0
        public void Execute(IrcDotNet.IrcClient Client, string Channel, IrcDotNet.IrcUser Sender, string Message)
        {
            mainDb           = Convert.ToInt16(configs[Channel]["markovmain"]);
            fastOneWordKeyDb = Convert.ToInt16(configs[Channel]["markovfast"]);

            rclient.Db = mainDb;

            string[] messageAsArray = Message.Trim().Split(' ');
            try
            {
                if (messageAsArray.Length == 1)
                {
                    Client.LocalUser.SendMessage(Channel, getNewMarkov(messageAsArray[0]));
                }
                else if (messageAsArray.Length >= 2)
                {
                    Client.LocalUser.SendMessage(Channel, getNewMarkov(messageAsArray[0] + " " + messageAsArray[1]));
                }
                else
                {
                    Client.LocalUser.SendMessage(Channel, getNewMarkov(""));
                }
            }
            catch (Exception e)
            {
                Client.LocalUser.SendMessage(Channel, e.Message);
            }
        }
Beispiel #4
0
        public void Execute(IrcDotNet.IrcClient Client, string Channel, IrcDotNet.IrcUser Sender, string Message)
        {
            string[] words = Message.Trim().Split(' ');
            if (words.Length < 2 || words.Length > 2)
            {
                Client.LocalUser.SendMessage(Channel, "!random <start> <end>");
                return;
            }

            int start, end;

            try
            {
                start = Convert.ToInt32(words[0]);
                end   = Convert.ToInt32(words[1]);
            }
            catch (Exception)
            {
                Client.LocalUser.SendMessage(Channel, "Numbers please");
                return;
            }

            int random = new Random().Next(start, end + 1);

            Client.LocalUser.SendMessage(Channel, random.ToString());
        }
Beispiel #5
0
        private static void HandleEventLoop(IrcDotNet.IrcClient client)
        {
            bool isExit = false;

            while (!isExit)
            {
                Console.Write("> ");
                var command = Console.ReadLine();
                switch (command)
                {
                case "exit":
                    isExit = true;
                    break;

                default:
                    if (!string.IsNullOrEmpty(command))
                    {
                        if (command.StartsWith("/") && command.Length > 1)
                        {
                            client.SendRawMessage(command.Substring(1));
                        }
                        else
                        {
                            Console.WriteLine("unknown command '{0}'", command);
                        }
                    }
                    break;
                }
            }
            client.Disconnect();
        }
Beispiel #6
0
        public void Execute(IrcDotNet.IrcClient Client, string Channel, IrcDotNet.IrcUser Sender, string Message)
        {
            WebClient client = new WebClient();
            string    nixi   = client.DownloadString("http://thermopylas.fi/ws/nicksit.php");

            byte[] bytes = Encoding.Default.GetBytes(nixi);
            nixi = Encoding.UTF8.GetString(bytes);
            nixi = nixi.Replace('\n', ' ').Trim();
            Client.LocalUser.SendMessage(Channel, nixi);
        }
Beispiel #7
0
        public void Execute(IrcDotNet.IrcClient client, string channel, IrcDotNet.IrcUser sender, string message)
        {
            if (words == null)
            {
                client.LocalUser.SendMessage(channel, "salkkari data base not initialized :<");
                return;
            }
            int index = new Random().Next(words.Count);

            client.LocalUser.SendMessage(channel, words[index]);
        }
Beispiel #8
0
        // The parameter 'message' contains the whole message without the command part ("!this" thing)

        // 'client' is used to send messages to the channel like I've done here.
        // You can also use it to get a list of nicks in the channel, topic of the channel, etc.

        // 'channel' just contains the name of the channel.

        // Please don't hardcode channel names or anything similar in here,
        // save the stuff in the configuration file and then use a variable to use it where necessary
        public void Execute(IrcDotNet.IrcClient client, string channel, IrcDotNet.IrcUser sender, string message)
        {
            // Do whatever you need to here
            string reverse = "";

            char[] cArray = message.ToCharArray();
            Array.Reverse(cArray);
            reverse = new string(cArray);

            // You can send a message to the channel from here.
            client.LocalUser.SendMessage(channel, reverse);
        }
Beispiel #9
0
 public void ExecuteUnignore(IrcDotNet.IrcClient Client, string channel, IrcDotNet.IrcUser Sender, string message)
 {
     message = message.Trim();
     if (message == "")
     {
         Client.LocalUser.SendMessage(channel, unignoreHelpMsg());
     }
     else
     {
         unignore(Client, channel, Sender, message);
     }
 }
Beispiel #10
0
        public void Execute(IrcDotNet.IrcClient Client, string Channel, IrcDotNet.IrcUser Sender, string Message)
        {
            string helpString = "";

            foreach (string command in features.commands.Keys)
            {
                helpString += command + " ";
            }

            helpString = "Available commands: " + helpString;

            Client.LocalUser.SendMessage(Channel, helpString);
        }
Beispiel #11
0
        public void ExecuteAdd(IrcDotNet.IrcClient Client, string Channel, IrcDotNet.IrcUser Sender, string Message)
        {
            ReadFromFile();
            string[] messageAsArray = Message.Trim().Split(' ');
            string   name           = messageAsArray[0].Trim();
            string   expl           = "";

            for (int i = 1; i < messageAsArray.Length; i++)
            {
                expl += messageAsArray[i] + " ";
            }
            expl = expl.Trim();

            Client.LocalUser.SendMessage(Channel, addExpl(name, expl, explDictionaries[Channel], configs[Channel][configExplNameKey]));
        }
Beispiel #12
0
        public void ExecuteRemove(IrcDotNet.IrcClient Client, string Channel, IrcDotNet.IrcUser Sender, string Message)
        {
            string message = Message.Trim();

            if (message.IndexOf(' ') == -1)
            {
                remove(Message, explDictionaries[Channel], configs[Channel][configExplNameKey]);
            }
            else
            {
                remove(message.Substring(0, message.IndexOf(' ')),
                       message.Substring(message.IndexOf(' ') + 1),
                       explDictionaries[Channel], configs[Channel][configExplNameKey]);
            }
        }
Beispiel #13
0
        public void Execute(IrcDotNet.IrcClient Client, string channel, IrcDotNet.IrcUser Sender, string message)
        {
            ReadFromFile();
            message = message.Trim();
            string expl = "";

            if (message.Trim() == "")
            {
                expl = explain(explDictionaries[channel]);
            }
            else
            {
                expl = explain(message, explDictionaries[channel]);
            }

            Client.LocalUser.SendMessage(channel, expl);
        }
Beispiel #14
0
        public void Execute(IrcDotNet.IrcClient Client, string Channel, IrcDotNet.IrcUser Sender, string Message)
        {
            string question = UrlEncode(Message, Encoding.Default);
            string url      = "http://www.lintukoto.net/viihde/oraakkeli/index.php?kysymys_24171206=" + question + "&rnd=24171206";

            string html = getUrlHtmlContent(url);

            string sstring = "<p class='vastaus'>";
            int    index   = html.IndexOf(sstring);

            string restOfString = html.Substring(index + sstring.Length);

            restOfString = restOfString.Substring(0, restOfString.IndexOf("</p>"));
            string answer = restOfString;

            Client.LocalUser.SendMessage(Channel, answer);
        }
Beispiel #15
0
        public void handle(RegistrationInfoFactory infoFactory, IrcDotNet.IrcClient client, FehBot bot, MongoDB.Driver.IMongoDatabase db, IrcDotNet.IrcUser from, IrcDotNet.IrcChannel to, string message)
        {
            if (to == null && isCode(message))
            {
                string code     = parseCodeRequest(message);
                string nick     = from.NickName;
                var    document = getForCode(nick.Trim(), code.Trim(), db);
                if (document != null)
                {
                    addListener(document, db);
                    var link = new JObject();

                    link.Add("nick", document.Nick);
                    link.Add("remoteUserName", document.RemoteUserName);

                    callWebHook(db, link);
                }
            }
        }
Beispiel #16
0
 private IrcDotNet.IrcUser getUserByName(IrcDotNet.IrcClient Client, string channel, string nick)
 {
     IrcDotNet.IrcUser user = null;
     foreach (IrcDotNet.IrcChannel c in Client.Channels)
     {
         if (c.Name == channel)
         {
             foreach (IrcDotNet.IrcChannelUser u in c.Users)
             {
                 if (u.User.NickName == nick)
                 {
                     user = u.User;
                     break;
                 }
             }
             break;
         }
     }
     return(user);
 }
Beispiel #17
0
        public void handle(RegistrationInfoFactory infoFactory, IrcDotNet.IrcClient client, FehBot bot, MongoDB.Driver.IMongoDatabase db, IrcDotNet.IrcUser from, IrcDotNet.IrcChannel to, string message)
        {
            var nickName          = infoFactory.NickName;
            var messageCollection = db.GetCollection <BsonDocument> ("Message");

            if (isTellMessage(message, nickName))
            {
                Tuple <string, string> request = parseRequest(HandlerUtils.removeMention(message, nickName));
                if (!request.Item1.Equals(nickName))
                {
                    messageCollection.InsertOne(new BsonDocument {
                        { "network", infoFactory.Server },
                        { "channel", to.Name.ToLower() },
                        { "recipient", request.Item1 },
                        { "sender", from.NickName },
                        { "message", request.Item2 }
                    });
                    client.LocalUser.SendMessage(to, from.NickName + ": kk");
                    var messageObject = new JObject();

                    messageObject.Add("channel", to.Name.ToLower());
                    messageObject.Add("recipient", request.Item1);
                    messageObject.Add("sender", from.NickName);
                    messageObject.Add("message", request.Item2);
                    callWebHook(db, messageObject);
                }
            }
            else
            {
                var builder = Builders <BsonDocument> .Filter;
                var filter  = builder.Eq("recipient", from.NickName) & builder.Eq("channel", to.Name.ToLower()) & builder.Eq("network", infoFactory.Server);
                messageCollection.Find(filter).ForEachAsync((document) => {
                    var objectId    = document.GetValue("_id").AsObjectId;
                    var createdDate = objectId.CreationTime;
                    DateDiff diff   = new DateDiff(createdDate, DateTime.Now.ToUniversalTime());
                    client.LocalUser.SendMessage(to, String.Format("({0} ago) {1} => {2}, {3}", diff.GetDescription(6), document.GetValue("sender").AsString, document.GetValue("recipient").AsString, document.GetValue("message").AsString));
                    messageCollection.DeleteOne(document);
                });
            }
        }
Beispiel #18
0
        public void Execute(IrcDotNet.IrcClient Client, string Channel, IrcDotNet.IrcUser Sender, string Message)
        {
            if (Message.Trim().Length == 0)
            {
                Client.LocalUser.SendMessage(Channel, getCompoundWord());
                return;
            }

            int num = 0;

            try
            {
                num = Convert.ToInt32(Message);
            }
            catch (Exception e)
            {
                Client.LocalUser.SendMessage(Channel, getCompoundWord(Message));
                return;
            }

            Client.LocalUser.SendMessage(Channel, getCompoundWord(num));
        }
Beispiel #19
0
        private void ignore(IrcDotNet.IrcClient Client, string channel, IrcDotNet.IrcUser Sender, string message)
        {
            if (!nickRegex.IsMatch(message))
            {
                Client.LocalUser.SendMessage(channel, "Messing around, eh?");
                ignore(Client, channel, Sender, Sender.NickName);
                return;
            }

            IrcDotNet.IrcUser user = getUserByName(Client, channel, message);
            if (user == null)
            {
                Client.LocalUser.SendMessage(channel, "Who now?");
                return;
            }

            if (IsIgnored(user, channel))
            {
                Client.LocalUser.SendMessage(channel, "They're already ignored");
                return;
            }
            user.NickNameChanged += (b, d) =>
            {
                ignoredHosts[channel].Add(user.NickName);
                if (!nowrite)
                {
                    refreshFile(configs[channel][configIgnoNameKey], channel);
                }
            };

            Client.LocalUser.SendMessage(channel, "Ignored " + message + " ^o^");
            ignoredHosts[channel].Add(user.NickName);


            if (!nowrite)
            {
                refreshFile(configs[channel][configIgnoNameKey], channel);
            }
        }
Beispiel #20
0
        private void unignore(IrcDotNet.IrcClient Client, string channel, IrcDotNet.IrcUser Sender, string message)
        {
            if (!nickRegex.IsMatch(message))
            {
                Client.LocalUser.SendMessage(channel, "Messing around, eh?");
                ignore(Client, channel, Sender, Sender.NickName);
                return;
            }

            if (!ignoredHosts[channel].Contains(message))
            {
                Client.LocalUser.SendMessage(channel, "They're not ignored");
                return;
            }

            Client.LocalUser.SendMessage(channel, "Unignored " + message);
            ignoredHosts[channel].Remove(message);

            if (!nowrite)
            {
                refreshFile(configs[channel][configIgnoNameKey], channel);
            }
        }
        internal void Connect()
        {
            DebugLogging.Log("Connecting", true);

            if (_irc == null)
            {
                _irc = new IrcDotNet.IrcClient();
            }
            else
            {
                Disconnect();
            }

            _irc.Connect(_connectionData.Address, _connectionData.Port, new IrcDotNet.IrcUserRegistrationInfo()
            {
                NickName = _connectionData.Username, UserName = _connectionData.Username, RealName = _connectionData.Username, Password = "******" + _connectionData.Oauth
            });
            _irc.ErrorMessageReceived += _irc_ErrorMessageReceived;
            _irc.Connected            += _irc_Connected;
            _irc.Disconnected         += _irc_Disconnected;
            _irc.ClientInfoReceived   += _irc_ClientInfoReceived;
            _irc.RawMessageReceived   += _irc_RawMessageReceived;
            _irc.Registered           += _irc_Registered;
        }
Beispiel #22
0
        public void handle(RegistrationInfoFactory infoFactory, IrcDotNet.IrcClient client, FehBot bot, MongoDB.Driver.IMongoDatabase db, IrcDotNet.IrcUser from, IrcDotNet.IrcChannel to, string message)
        {
            if (isFactoidMentionRequest(message))
            {
                Tuple <string, string> request = ParseFactionMention(message);
                var term   = request.Item1.Trim();
                var target = request.Item2.Trim();

                var factoid = db.GetCollection <BsonDocument>("factoid");
                var builder = Builders <BsonDocument> .Filter;
                var filter  = builder.Eq("term", term) & builder.Eq("channel", to.Name.ToLower()) & builder.Eq("network", infoFactory.Server);

                var document = factoid.Find(filter).FirstOrDefault();

                if (document == null)
                {
                    string template = "{0}, Huh?";
                    client.LocalUser.SendMessage(to, String.Format(template, from.NickName));
                }
                else
                {
                    string template = "{0}, {1}.";
                    client.LocalUser.SendMessage(to, String.Format(template, target, document.GetValue("meaning").AsString));
                }
            }
            else if (isFactoidGetRequest(message))
            {
                var term    = parseFactoidGet(message);
                var factoid = db.GetCollection <BsonDocument>("factoid");
                var builder = Builders <BsonDocument> .Filter;
                var filter  = builder.Eq("term", term) & builder.Eq("channel", to.Name.ToLower()) & builder.Eq("network", infoFactory.Server);

                var document = factoid.Find(filter).FirstOrDefault();

                if (document == null)
                {
                    string template = "{0}, Huh?";
                    client.LocalUser.SendMessage(to, String.Format(template, from.NickName));
                }
                else
                {
                    string template = "{0}, {1}";
                    client.LocalUser.SendMessage(to, String.Format(template, from.NickName, document.GetValue("meaning").AsString));
                }
            }
            else if (isFactoidStoreRequest(message, infoFactory.NickName))
            {
                message = HandlerUtils.removeMention(message, infoFactory.NickName);
                var request    = parseFactoidStoreRequest(message);
                var term       = request.Item1;
                var definition = request.Item2;

                var factoid = db.GetCollection <BsonDocument>("factoid");
                var builder = Builders <BsonDocument> .Filter;
                var filter  = builder.Eq("term", term) & builder.Eq("channel", to.Name.ToLower()) & builder.Eq("network", infoFactory.Server);

                var document = factoid.Find(filter).FirstOrDefault();
                if (document == null)
                {
                    factoid.InsertOne(new BsonDocument {
                        { "term", term },
                        { "channel", to.Name.ToLower() },
                        { "network", infoFactory.Server },
                        { "meaning", definition }
                    });
                }
                else
                {
                    var update = Builders <BsonDocument> .Update.Set("meaning", definition);

                    factoid.UpdateOne(filter, update);
                }
                string template = "{0}, Got it!";
                client.LocalUser.SendMessage(to, String.Format(template, from.NickName));
            }
            else if (isFactoidRemoveRequest(message, infoFactory.NickName))
            {
                message = HandlerUtils.removeMention(message, infoFactory.NickName);
                string term = parseFactoidRemoveRequest(message);

                var factoid = db.GetCollection <BsonDocument>("factoid");
                var builder = Builders <BsonDocument> .Filter;
                var filter  = builder.Eq("term", term) & builder.Eq("channel", to.Name.ToLower()) & builder.Eq("network", infoFactory.Server);

                var document = factoid.Find(filter).FirstOrDefault();
                if (document == null)
                {
                    string template = "{0}, Huh?";
                    client.LocalUser.SendMessage(to, String.Format(template, from.NickName));
                }
                else
                {
                    factoid.DeleteOne(filter);
                    string template = "{0}, It never happened.";
                    client.LocalUser.SendMessage(to, String.Format(template, from.NickName));
                }
            }
        }
Beispiel #23
0
 public void handle(RegistrationInfoFactory infoFactory, IrcDotNet.IrcClient client, FehBot bot, MongoDB.Driver.IMongoDatabase db, IrcDotNet.IrcUser from, IrcDotNet.IrcChannel to, string message)
 {
     throw new NotImplementedException();
 }
Beispiel #24
0
 private static void Say(string channel, string msg, IrcDotNet.IrcClient client)
 {
     client.LocalUser.SendMessage(channel, msg);
 }
Beispiel #25
0
 public void Execute(IrcDotNet.IrcClient Client, string Channel, IrcDotNet.IrcUser Sender, string Message)
 {
     Client.LocalUser.SendMessage(Channel, getURLTitle(Message));
 }
Beispiel #26
0
        public void Execute(IrcDotNet.IrcClient Client, string Channel, IrcDotNet.IrcUser Sender, string Message)
        {
            string stuff = runNP(Message, Sender.NickName);

            Client.LocalUser.SendMessage(Channel, stuff);
        }