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)); }
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)); }
/// <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; }
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]); } }
/// <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; }
/// <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); }
/// <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); }
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()); }
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); }
/// <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); }
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(); }
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); } }
/// <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); }
/// <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)); }
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]); } }
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); }
/// <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; }
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); } }
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; }
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); }
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); }
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); } }