Ejemplo n.º 1
0
        public string getChannelId(string channel)
        {
            DAL.Select q = new DAL.Select("channel_id");
            q.setFrom("channel");
            q.addWhere(new DAL.WhereConds("channel_name", channel));

            return(this._dbal.executeScalarSelect(q));
        }
Ejemplo n.º 2
0
        private string getOptionId(string optionName)
        {
            DAL.Select q = new DAL.Select("configuration_id");
            q.setFrom("configuration");
            q.addWhere(new DAL.WhereConds("configuration_name", optionName));

            return(this._dbal.executeScalarSelect(q));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Forgets the specified word.
        /// </summary>
        /// <param name="word">The word.</param>
        /// <returns></returns>
        public static bool forget(string word)
        {
            DAL.Select q = new DAL.Select("COUNT(*)");
            q.setFrom("keywords");
            q.addWhere(new DAL.WhereConds("keyword_name", word));

            if (DAL.singleton().executeScalarSelect(q) == "0")
                return false;

            DAL.singleton().delete("keywords", 0, new DAL.WhereConds("keyword_name", word));
            return true;
        }
Ejemplo n.º 4
0
        private static void joinChannels()
        {
            irc.ircJoin(debugChannel);

            DAL.Select q = new DAL.Select("channel_name");
            q.setFrom("channel");
            q.addWhere(new DAL.WhereConds("channel_enabled", 1));
            q.addWhere(new DAL.WhereConds("channel_network", _ircNetwork.ToString()));
            foreach (object[] item in _dbal.executeSelect(q))
            {
                irc.ircJoin((string)(item)[0]);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Learns the specified word.
        /// </summary>
        /// <param name="word">The word.</param>
        /// <param name="phrase">The phrase.</param>
        /// <param name="action">if set to <c>true</c> [action].</param>
        /// <returns></returns>
        public static bool learn(string word, string phrase, bool action)
        {
            DAL.Select q = new DAL.Select("COUNT(*)");
            q.setFrom("keywords");
            q.addLimit(1, 0);
            q.addWhere(new DAL.WhereConds("keyword_name", word));

            if (DAL.singleton().executeScalarSelect(q) != "0")
                return false;

            DAL.singleton().insert("keywords", "", word, phrase, (action ? "1" : "0 "));
            return true;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Forgets the specified word.
        /// </summary>
        /// <param name="word">The word.</param>
        /// <returns></returns>
        public static bool forget(string word)
        {
            DAL.Select q = new DAL.Select("COUNT(*)");
            q.setFrom("keywords");
            q.addWhere(new DAL.WhereConds("keyword_name", word));

            if (DAL.singleton().executeScalarSelect(q) == "0")
            {
                return(false);
            }

            DAL.singleton().delete("keywords", 0, new DAL.WhereConds("keyword_name", word));
            return(true);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Learns the specified word.
        /// </summary>
        /// <param name="word">The word.</param>
        /// <param name="phrase">The phrase.</param>
        /// <param name="action">if set to <c>true</c> [action].</param>
        /// <returns></returns>
        public static bool learn(string word, string phrase, bool action)
        {
            DAL.Select q = new DAL.Select("COUNT(*)");
            q.setFrom("keywords");
            q.addLimit(1, 0);
            q.addWhere(new DAL.WhereConds("keyword_name", word));


            if (DAL.singleton().executeScalarSelect(q) != "0")
            {
                return(false);
            }

            DAL.singleton().insert("keywords", "", word, phrase, (action ? "1" : "0 "));
            return(true);
        }
Ejemplo n.º 8
0
        public static SerializableArrayList retrieve(string blobName)
        {
            var q = new DAL.Select("bin_blob");

            q.setFrom("binary_store");
            q.addWhere(new DAL.WhereConds("bin_desc", blobName));
            var result = DAL.singleton().executeSelect(q);

            var serializationStream = new MemoryStream(((byte[])(((object[])(result[0]))[0])));

            if (serializationStream.Length != 0)
            {
                return((SerializableArrayList) new BinaryFormatter().Deserialize(serializationStream));
            }
            return(new SerializableArrayList());
        }
Ejemplo n.º 9
0
        private string retrieveOptionFromDatabase(string optionName)
        {
            try
            {
                DAL.Select q = new DAL.Select("configuration_value");
                q.setFrom("configuration");
                q.addLimit(1, 0);
                q.addWhere(new DAL.WhereConds("configuration_name", optionName));

                string result = this._dbal.executeScalarSelect(q) ?? "";
                return(result);
            }
            catch (Exception ex)
            {
                GlobalFunctions.errorLog(ex);
            }
            return(null);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Remembers the specified word.
        /// </summary>
        /// <param name="word">The word.</param>
        /// <returns></returns>
        public static RemeberedWord remember(string word)
        {
            DAL.Select q = new DAL.Select("keyword_action");
            q.setFrom("keywords");
            q.addWhere(new DAL.WhereConds("keyword_name", word));

            string action = DAL.singleton().executeScalarSelect(q);

            q = new DAL.Select("keyword_response");
            q.setFrom("keywords");
            q.addWhere(new DAL.WhereConds("keyword_name", word));
            string result = DAL.singleton().executeScalarSelect(q);

            RemeberedWord rW = new RemeberedWord
            {
                action = (action == "1" ? true : false),
                phrase = result
            };

            return(rW);
        }
Ejemplo n.º 11
0
        public IAL(uint ircNetwork)
        {
            this.floodProtectionWaitTime = 500;
            this.clientVersion           = "Helpmebot IRC Access Layer 1.0";
            _networkId = ircNetwork;

            DAL db = DAL.singleton();


            DAL.Select q = new DAL.Select("in_host", "in_port", "in_nickname", "in_password", "in_username",
                                          "in_realname", "in_log", "in_nickserv");
            q.setFrom("ircnetwork");
            q.addLimit(1, 0);
            q.addWhere(new DAL.WhereConds("in_id", ircNetwork.ToString()));

            ArrayList configSettings = db.executeSelect(q);

            _ircServer = (string)(((object[])configSettings[0])[0]);
            _ircPort   = (uint)((object[])configSettings[0])[1];

            _myNickname = (string)(((object[])configSettings[0])[2]);
            _myPassword = (string)(((object[])configSettings[0])[3]);
            _myUsername = (string)(((object[])configSettings[0])[4]);
            _myRealname = (string)(((object[])configSettings[0])[5]);

            this.logEvents = (bool)(((object[])configSettings[0])[6]);

            _nickserv = (string)(((object[])configSettings[0])[7]);

            if (/*recieveWallops*/ true)
            {
                this.connectionUserModes += 4;
            }
            if (/*invisible*/ true)
            {
                this.connectionUserModes += 8;
            }

            initialiseEventHandlers();
        }
Ejemplo n.º 12
0
        private void setLocalOption(string channel, string optionName, string newValue)
        {
            string channelId = this.getChannelId(channel);

            string configId = this.getOptionId(optionName);

            // does setting exist in local table?
            //  INNER JOIN `channel` ON `channel_id` = `cc_channel` WHERE `channel_name` = '##helpmebot' AND `configuration_name` = 'silence'


            if (newValue == null)
            {
                this._dbal.delete("channelconfig", 1, new DAL.WhereConds("cc_config", getOptionId(optionName)),
                                  new DAL.WhereConds("cc_channel", getChannelId(channelId)));
                return;
            }

            DAL.Select q = new DAL.Select("COUNT(*)");
            q.setFrom("channelconfig");
            q.addWhere(new DAL.WhereConds("cc_channel", channelId));
            q.addWhere(new DAL.WhereConds("cc_config", configId));
            string count = this._dbal.executeScalarSelect(q);

            if (count == "1")
            {
                //yes: update
                Dictionary <string, string> vals = new Dictionary <string, string>
                {
                    { "cc_value", newValue }
                };
                this._dbal.update("channelconfig", vals, 1, new DAL.WhereConds("cc_channel", channelId),
                                  new DAL.WhereConds("cc_config", configId));
            }
            else
            {
                // no: insert
                this._dbal.insert("channelconfig", channelId, configId, newValue);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Shortens the specified long URL.
        /// </summary>
        /// <param name="longUrl">The long URL.</param>
        /// <returns></returns>
        public static Uri shorten(Uri longUrl)
        {
            DAL.Select q = new DAL.Select("suc_shorturl");
            q.setFrom("shorturlcache");
            q.addWhere(new DAL.WhereConds("suc_fullurl", longUrl.ToString()));
            string cachelookup = DAL.singleton().executeScalarSelect(q);

            if (cachelookup == "")
            {
                try
                {
                    string shorturl = getShortUrl(longUrl);
                    DAL.singleton().insert("shorturlcache", "", longUrl.ToString(), shorturl);
                    return new Uri(shorturl);
                }
                catch(WebException ex)
                {
                    GlobalFunctions.errorLog(ex);
                    return null;
                }
            }
            return new Uri(cachelookup);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Shortens the specified long URL.
        /// </summary>
        /// <param name="longUrl">The long URL.</param>
        /// <returns></returns>
        public static Uri shorten(Uri longUrl)
        {
            DAL.Select q = new DAL.Select("suc_shorturl");
            q.setFrom("shorturlcache");
            q.addWhere(new DAL.WhereConds("suc_fullurl", longUrl.ToString()));
            string cachelookup = DAL.singleton().executeScalarSelect(q);

            if (cachelookup == "")
            {
                try
                {
                    string shorturl = getShortUrl(longUrl);
                    DAL.singleton().insert("shorturlcache", "", longUrl.ToString(), shorturl);
                    return(new Uri(shorturl));
                }
                catch (WebException ex)
                {
                    GlobalFunctions.errorLog(ex);
                    return(longUrl);
                }
            }

            return(new Uri(cachelookup));
        }
Ejemplo n.º 15
0
        private static void joinChannels()
        {
            irc.ircJoin(debugChannel);

            DAL.Select q = new DAL.Select("channel_name");
            q.setFrom("channel");
            q.addWhere(new DAL.WhereConds("channel_enabled", 1));
            q.addWhere(new DAL.WhereConds("channel_network", _ircNetwork.ToString()));
            foreach (object[] item in _dbal.executeSelect(q))
            {
                irc.ircJoin((string) (item)[0]);
            }
        }
Ejemplo n.º 16
0
            public static           AccessLogEntry[] get(params DAL.WhereConds[] conditions)
            {
                DAL.Select q = new DAL.Select("*");
                q.addWhere(conditions);
                q.setFrom("accesslog");

                List <string> columns;
                ArrayList     al = DAL.singleton().executeSelect(q, out columns);

                AccessLogEntry[] entries = new AccessLogEntry[al.Count];

                for (int j = 0; j < al.Count; j++)
                {
                    string[] row = (string[])al[j];

                    AccessLogEntry entry = new AccessLogEntry();

                    string          usermask   = string.Empty;
                    User.UserRights useraccess = User.UserRights.Normal;
                    #region parse
                    for (int i = 0; i < row.Length; i++)
                    {
                        switch (columns[i])
                        {
                        case ACCESSLOG_ID:
                            entry._alId = int.Parse(row[i]);
                            break;

                        case ACCESSLOG_USER:
                            usermask = row[i];
                            break;

                        case ACCESSLOG_USER_ACCESS:
                            useraccess = (User.UserRights)Enum.Parse(typeof(User.UserRights), row[i]);
                            break;

                        case ACCESSLOG_COMMAND_ACCESS:
                            entry._alReqaccesslevel = (User.UserRights)Enum.Parse(typeof(User.UserRights), row[i]);
                            break;

                        case ACCESSLOG_DATE:
                            entry._alDate = DateTime.Parse(row[i]);
                            break;

                        case ACCESSLOG_COMMAND_CLASS:
                            entry._alClass = Type.GetType(row[i]);
                            break;

                        case ACCESSLOG_ALLOWED:
                            entry._alAllowed = row[i] == "0" ? false : true;
                            break;

                        case ACCESSLOG_CHANNEL:
                            entry._channel = row[i];
                            break;

                        case ACCESSLOG_ARGS:
                            entry._params = row[i];
                            break;
                        }

                        entry._alUser = User.newFromStringWithAccessLevel(usermask, useraccess);
                    }
                    #endregion

                    entries[j] = entry;
                }
                return(entries);
            }
Ejemplo n.º 17
0
        /// <summary>
        /// Remembers the specified word.
        /// </summary>
        /// <param name="word">The word.</param>
        /// <returns></returns>
        public static RemeberedWord remember(string word)
        {
            DAL.Select q = new DAL.Select("keyword_action");
            q.setFrom("keywords");
            q.addWhere(new DAL.WhereConds("keyword_name", word));

            string action = DAL.singleton().executeScalarSelect(q);
            q = new DAL.Select("keyword_response");
            q.setFrom("keywords");
            q.addWhere(new DAL.WhereConds("keyword_name", word));
            string result = DAL.singleton().executeScalarSelect(q);

            RemeberedWord rW = new RemeberedWord
                                   {
                                       action = ( action == "1" ? true : false ),
                                       phrase = result
                                   };

            return rW;
        }
Ejemplo n.º 18
0
        private void setLocalOption( string channel, string optionName, string newValue )
        {
            string channelId = this.getChannelId(channel);

            string configId = this.getOptionId(optionName);

            // does setting exist in local table?
            //  INNER JOIN `channel` ON `channel_id` = `cc_channel` WHERE `channel_name` = '##helpmebot' AND `configuration_name` = 'silence'

            if(newValue == null)
            {
                this._dbal.delete( "channelconfig", 1, new DAL.WhereConds( "cc_config", getOptionId( optionName ) ),
                                   new DAL.WhereConds( "cc_channel", getChannelId( channelId ) ) );
                return;
            }

            DAL.Select q = new DAL.Select("COUNT(*)");
            q.setFrom("channelconfig");
            q.addWhere(new DAL.WhereConds("cc_channel", channelId));
            q.addWhere(new DAL.WhereConds("cc_config", configId));
            string count = this._dbal.executeScalarSelect(q);

            if (count == "1")
            {
                //yes: update
                Dictionary<string, string> vals = new Dictionary<string, string>
                                                      {
                                                          { "cc_value", newValue }
                                                      };
                this._dbal.update("channelconfig", vals, 1, new DAL.WhereConds("cc_channel", channelId),
                                  new DAL.WhereConds("cc_config", configId));
            }
            else
            {
                // no: insert
                this._dbal.insert("channelconfig", channelId, configId, newValue);
            }
        }
Ejemplo n.º 19
0
        private string retrieveOptionFromDatabase(string optionName)
        {
            try
            {
                DAL.Select q = new DAL.Select("configuration_value");
                q.setFrom("configuration");
                q.addLimit(1, 0);
                q.addWhere(new DAL.WhereConds("configuration_name", optionName));

                string result = this._dbal.executeScalarSelect(q) ?? "";
                return result;
            }
            catch (Exception ex)
            {
                GlobalFunctions.errorLog(ex);
            }
            return null;
        }
Ejemplo n.º 20
0
        private string getOptionId(string optionName)
        {
            DAL.Select q = new DAL.Select("configuration_id");
            q.setFrom("configuration");
            q.addWhere(new DAL.WhereConds("configuration_name", optionName));

            return this._dbal.executeScalarSelect(q);
        }
Ejemplo n.º 21
0
        public string getChannelId(string channel)
        {
            DAL.Select q = new DAL.Select("channel_id");
            q.setFrom("channel");
            q.addWhere(new DAL.WhereConds("channel_name", channel));

            return this._dbal.executeScalarSelect(q);
        }
Ejemplo n.º 22
0
        private static void pageWatcherNotificationEvent(PageWatcherController.RcPageChange rcItem)
        {
            string[] messageParams = {
                                         rcItem.title, rcItem.user, rcItem.comment, rcItem.diffUrl, rcItem.byteDiff,
                                         rcItem.flags
                                     };
            string message = new Message().get("pageWatcherEventNotification", messageParams);

            DAL.Select q = new DAL.Select("channel_name");
            q.addJoin("channel", DAL.Select.JoinTypes.Inner,
                      new DAL.WhereConds(false, "pwc_channel", "=", false, "channel_id"));
            q.addJoin("watchedpages", DAL.Select.JoinTypes.Inner,
                      new DAL.WhereConds(false, "pw_id", "=", false, "pwc_pagewatcher"));
            q.addWhere(new DAL.WhereConds("pw_title", rcItem.title));
            q.setFrom("pagewatcherchannels");

            ArrayList channels = DAL.singleton().executeSelect(q);

            foreach (object[] item in channels)
            {
                string channel = (string) item[0];
                if (Configuration.singleton()["silence",channel] == "false")
                    irc.ircPrivmsg(channel, message);
            }
        }