public Extension_GetConfig ( string key, string missing = null ) : string | ||
key | string | |
missing | string | |
리턴 | string |
private static void ChannelOverview(CommandParams parameters) { if (string.IsNullOrEmpty(parameters.Parameters)) { IRC.DeliverMessage("You need to provide exactly 1 parameter", parameters.SourceChannel); return; } string channel_name = parameters.Parameters.Trim(); Channel channel = Core.GetChannel(channel_name); if (channel == null) { IRC.DeliverMessage("Unknown channel: " + channel_name, parameters.SourceChannel); return; } string founder = channel.Extension_GetConfig("generic.owner"); if (founder != null) { founder += " (original founder: " + channel.Extension_GetConfig("generic.founder", "N/A") + ")"; } else { founder = channel.Extension_GetConfig("generic.founder"); } if (founder == null) { founder = "N/A"; } IRC.DeliverMessage("Channel " + channel.Name + " was joined " + channel.Extension_GetConfig("generic.joindate", "unknown time") + ", requested by " + founder, parameters.SourceChannel); }
/// <summary> /// Get config /// </summary> /// <param name="chan"></param> /// <param name="name"></param> /// <param name="invalid"></param> /// <returns></returns> public static string GetConfig(Channel chan, string name, string invalid) { try { if (chan != null) { string result = chan.Extension_GetConfig(name); if (result == null) { return(invalid); } return(result); } } catch (Exception fail) { Core.HandleException(fail); } return(invalid); }
/// <summary> /// Get a config /// </summary> /// <param name="chan"></param> /// <param name="name"></param> /// <param name="invalid"></param> /// <returns></returns> public static int GetConfig(Channel chan, string name, int invalid) { try { if (chan != null) { string value = chan.Extension_GetConfig(name); int result; if (int.TryParse(value, out result)) { return(result); } } } catch (Exception fail) { Core.HandleException(fail); } return(invalid); }
/// <summary> /// Join channel /// </summary> public static void AddChannel(CommandParams parameters) { if (!String.IsNullOrEmpty(parameters.Parameters)) { while (!IRC.FinishedJoining) { Syslog.Log("Postponing request to join " + parameters.Parameters + " because bot is still loading", true); Thread.Sleep(2000); } List <string> pm = new List <string>(parameters.Parameters.Trim().Split(' ')); if (pm.Count > 2 || pm.Count == 0) { IRC.DeliverMessage("Invalid number of parameters, please provide up to 2 parameters (name, password)", parameters.SourceChannel); return; } string channel_name = pm[0]; string password = null; if (pm.Count > 1) { password = pm[1]; } if (!Core.ValidFile(channel_name) || !channel_name.StartsWith("#")) { IRC.DeliverMessage(messages.Localize("InvalidName", parameters.SourceChannel.Language, new List <string> { channel_name }), parameters.SourceChannel); return; } lock (Configuration.Channels) { foreach (Channel cu in Configuration.Channels) { if (channel_name == cu.Name) { IRC.DeliverMessage(messages.Localize("ChannelIn", parameters.SourceChannel.Language), parameters.SourceChannel); return; } } } bool existing = Channel.ConfigExists(channel_name); Channel channel = new Channel(channel_name) { Password = password }; lock (Configuration.Channels) { Configuration.Channels.Add(channel); } IRC.DeliverMessage("Attempting to join " + channel_name + " using " + channel.PrimaryInstance.Nick, parameters.SourceChannel.Name); Configuration.Save(); Syslog.DebugLog("Sending join " + channel_name); channel.PrimaryInstance.Network.Join(channel_name, password); Channel Chan = Core.GetChannel(channel_name); if (!existing) { Chan.SystemUsers.AddUser("admin", Security.EscapeUser(parameters.User.Nick) + "!.*@" + Security.EscapeUser(parameters.User.Host)); } if (Chan.Extension_GetConfig("generic.founder") == null) { Chan.Extension_SetConfig("generic.founder", parameters.User.ToString()); Chan.Extension_SetConfig("generic.owner", parameters.User.ToString()); } else { Chan.Extension_SetConfig("generic.owner", parameters.User.ToString()); } Chan.Extension_SetConfig("generic.joindate", DateTime.Now.ToString()); Chan.SaveConfig(); return; } IRC.DeliverMessage(messages.Localize("InvalidName", parameters.SourceChannel.Language), parameters.SourceChannel); return; }
/// <summary> /// Get a bool from config of channel /// </summary> /// <param name="chan"></param> /// <param name="name"></param> /// <param name="invalid"></param> /// <returns></returns> public static bool GetConfig(Channel chan, string name, bool invalid) { try { if (chan != null) { string value = chan.Extension_GetConfig(name); bool result = false; if (bool.TryParse(value, out result)) { return result; } } return invalid; } catch (Exception fail) { Core.HandleException(fail); return invalid; } }
/// <summary> /// Get config /// </summary> /// <param name="chan"></param> /// <param name="name"></param> /// <param name="invalid"></param> /// <returns></returns> public static string GetConfig(Channel chan, string name, string invalid) { try { if (chan != null) { string result = chan.Extension_GetConfig(name); if (result == null) { return invalid; } return result; } } catch (Exception fail) { Core.HandleException(fail); } return invalid; }
/// <summary> /// Get a config /// </summary> /// <param name="chan"></param> /// <param name="name"></param> /// <param name="invalid"></param> /// <returns></returns> public static int GetConfig(Channel chan, string name, int invalid) { try { if (chan != null) { string value = chan.Extension_GetConfig(name); int result = 0; if (int.TryParse(value, out result)) { return result; } } } catch (Exception fail) { Core.HandleException(fail); } return invalid; }