Ejemplo n.º 1
0
 ///<summary>
 ///Constructor
 ///</summary>
 public Channel(IrcDotNet.IrcChannel NewChannel)
 {
     IrcChannelPointer = NewChannel;
     Name = NewChannel.Name.Substring(1);
     Filesystem.Folders.InitChannel(this);
     Filesystem.Files.InitChannel(this);
     LUAContainer  = new LUA(this);
     CommandPrefix = Config.Channel.GetCommandPrefix(this);
 }
Ejemplo n.º 2
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));
                }
            }
        }
Ejemplo n.º 3
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);
                }
            }
        }
Ejemplo n.º 4
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();
 }
Ejemplo n.º 5
0
 public IrcChannel(IrcDotNet.IrcChannel inner, IUploader uploader)
 {
     _inner    = inner;
     _uploader = uploader;
 }
Ejemplo n.º 6
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);
                });
            }
        }
Ejemplo n.º 7
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);
                });
            }
        }