public override bool Hook_SetConfig(Channel chan, libirc.UserInfo invoker, string config, string value) { if (config == "default-link-wiki") { if (value != "") { SetConfig(chan, "Link.Default", value); chan.SaveConfig(); IRC.DeliverMessage(messages.Localize("configuresave", chan.Language, new List <string> { value, config }), chan.Name); return(true); } IRC.DeliverMessage(messages.Localize("configure-va", chan.Language, new List <string> { config, value }), chan.Name); return(true); } return(false); }
private static void Instance(CommandParams parameters) { if (string.IsNullOrEmpty(parameters.Parameters) || !parameters.Parameters.Contains(" ")) { IRC.DeliverMessage("This command needs 2 parameters", parameters.SourceChannel); return; } string channel = parameters.Parameters.Substring(parameters.Parameters.IndexOf(" ") + 1); string instance = parameters.Parameters.Substring(0, parameters.Parameters.IndexOf(" ")); Channel ch = Core.GetChannel(channel); if (ch == null) { IRC.DeliverMessage("This channel I never heard of :'(", parameters.SourceChannel); return; } if (!wmib.Instance.Instances.ContainsKey(instance)) { IRC.DeliverMessage("This instance I never heard of :'(", parameters.SourceChannel); return; } Instance _instance = wmib.Instance.Instances[instance]; if (_instance == ch.PrimaryInstance) { IRC.DeliverMessage("This channel is already in this instance", parameters.SourceChannel); return; } ch.PrimaryInstance.Network.Transfer("PART " + ch.Name + " :Switching instance"); ch.PrimaryInstance = _instance; ch.PrimaryInstance.Network.Transfer("JOIN " + ch.Name); ch.DefaultInstance = ch.PrimaryInstance.Nick; ch.SaveConfig(); IRC.DeliverMessage("Changed default instance of " + channel + " to " + instance, parameters.SourceChannel); }
public override bool Hook_SetConfig(Channel chan, User invoker, string config, string value) { switch (config) { case "recent-changes-template": if (value != "null") { Module.SetConfig(chan, "RC.Template", value); Core.irc.Queue.DeliverMessage(messages.Localize("configuresave", chan.Language, new List<string> { value, config }), chan); chan.SaveConfig(); return true; } else { Module.SetConfig(chan, "RC.Template", ""); Core.irc.Queue.DeliverMessage(messages.Localize("configuresave", chan.Language, new List<string> { "null", config }), chan); chan.SaveConfig(); return true; } } return false; }
public override void Hook_PRIV(Channel channel, User invoker, string message) { if (message.StartsWith(Configuration.System.CommandPrefix + "RC-")) { if (channel.SystemUsers.IsApproved(invoker, "trust")) { if (GetConfig(channel, "RC.Enabled", false)) { string[] a = message.Split(' '); if (a.Length < 3) { Core.irc.Queue.DeliverMessage(messages.Localize("Feed8", channel.Language, new List<string> { invoker.Nick }), channel.Name); return; } string wiki = a[1]; string Page = a[2]; RecentChanges rc = (RecentChanges)channel.RetrieveObject("RC"); if (rc != null) { rc.removeString(wiki, Page); } return; } else { Core.irc.Queue.DeliverMessage(messages.Localize("Feed3", channel.Language), channel.Name); return; } } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } return; } if (message.StartsWith(Configuration.System.CommandPrefix + "recentchanges- ")) { if (channel.SystemUsers.IsApproved(invoker, "root")) { if (GetConfig(channel, "RC.Enabled", false)) { if (!message.Contains(" ")) { if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("InvalidWiki", channel.Language), channel.Name); } return; } string _channel = message.Substring(message.IndexOf(" ") + 1); if (RecentChanges.DeleteChannel(channel, _channel)) { Core.irc.Queue.DeliverMessage(messages.Localize("Wiki-", channel.Language), channel.Name, IRC.priority.high); } return; } else { Core.irc.Queue.DeliverMessage(messages.Localize("Feed3", channel.Language), channel.Name); return; } } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } return; } if (message.StartsWith(Configuration.System.CommandPrefix + "RC+ ")) { if (channel.SystemUsers.IsApproved(invoker, "trust")) { if (GetConfig(channel, "RC.Enabled", false)) { string[] a = message.Split(' '); if (a.Length < 3) { Core.irc.Queue.DeliverMessage(messages.Localize("Feed4", channel.Language) + invoker.Nick + messages.Localize("Feed5", channel.Language), channel.Name); return; } string wiki = a[1]; string Page = a[2]; RecentChanges rc = (RecentChanges)channel.RetrieveObject("RC"); if (rc != null) { rc.insertString(wiki, Page); } return; } else { Core.irc.Queue.DeliverMessage(messages.Localize("Feed3", channel.Language), channel.Name); return; } } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } return; } if (message == Configuration.System.CommandPrefix + "recentchanges-off") { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (!GetConfig(channel, "RC.Enabled", false)) { Core.irc.Queue.DeliverMessage(messages.Localize("Feed6", channel.Language), channel.Name); return; } else { Core.irc.Queue.DeliverMessage(messages.Localize("Feed7", channel.Language), channel.Name); SetConfig(channel, "RC.Enabled", false); channel.SaveConfig(); return; } } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } return; } if (message == Configuration.System.CommandPrefix + "recentchanges-on") { if (channel.SystemUsers.IsApproved(invoker, "recentchanges-manage")) { if (GetConfig(channel, "RC.Enabled", false)) { Core.irc.Queue.DeliverMessage(messages.Localize("Feed1", channel.Language), channel.Name); return; } else { Core.irc.Queue.DeliverMessage(messages.Localize("Feed2", channel.Language), channel.Name); SetConfig(channel, "RC.Enabled", true); channel.SaveConfig(); return; } } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } return; } if (message.StartsWith(Configuration.System.CommandPrefix + "recentchanges+")) { if (channel.SystemUsers.IsApproved(invoker, "recentchanges-manage")) { if (GetConfig(channel, "RC.Enabled", false)) { if (!message.Contains(" ")) { if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("InvalidWiki", channel.Language), channel.Name); } return; } string _channel = message.Substring(message.IndexOf(" ") + 1); if (RecentChanges.InsertChannel(channel, _channel)) { Core.irc.Queue.DeliverMessage(messages.Localize("Wiki+", channel.Language), channel.Name); } return; } else { Core.irc.Queue.DeliverMessage(messages.Localize("Feed3", channel.Language), channel.Name); return; } } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } return; } }
public override void Hook_PRIV(Channel channel, User invoker, string message) { if (Module.GetConfig(channel, "Statistics.Enabled", false)) { Statistics st = (Statistics)channel.RetrieveObject("Statistics"); if (st != null) { st.Stat(invoker.Nick, message, invoker.Host); } } if (message == Configuration.System.CommandPrefix + "statistics-off") { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (!Module.GetConfig(channel, "Statistics.Enabled", false)) { Core.irc.Queue.DeliverMessage(messages.Localize("StatE2", channel.Language), channel); return; } else { Module.SetConfig(channel, "Statistics.Enabled", false); channel.SaveConfig(); Core.irc.Queue.DeliverMessage(messages.Localize("Stat-off", channel.Language), channel); return; } } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message == Configuration.System.CommandPrefix + "statistics-reset") { if (channel.SystemUsers.IsApproved(invoker, "admin")) { Statistics st = (Statistics)channel.RetrieveObject("Statistics"); if (st != null) { st.Delete(); } Core.irc.Queue.DeliverMessage(messages.Localize("Statdt", channel.Language), channel); return; } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message == Configuration.System.CommandPrefix + "statistics-on") { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (Module.GetConfig(channel, "Statistics.Enabled", false)) { Core.irc.Queue.DeliverMessage(messages.Localize("StatE1", channel.Language), channel); return; } else { Module.SetConfig(channel, "Statistics.Enabled", true); channel.SaveConfig(); Core.irc.Queue.DeliverMessage(messages.Localize("Stat-on", channel.Language), channel); return; } } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } return; } }
/// <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; }
public override bool Hook_SetConfig(Channel chan, User invoker, string config, string value) { bool _temp_a; switch (config) { case "infobot-trim-white-space-in-name": if (bool.TryParse(value, out _temp_a)) { Module.SetConfig(chan, "Infobot.Trim-white-space-in-name", _temp_a); Core.irc.Queue.DeliverMessage(messages.Localize("configuresave", chan.Language, new List<string> { value, config }), chan.Name); chan.SaveConfig(); return true; } Core.irc.Queue.DeliverMessage(messages.Localize("configure-va", chan.Language, new List<string> { config, value }), chan.Name); return true; case "infobot-auto-complete": if (bool.TryParse(value, out _temp_a)) { Module.SetConfig(chan, "Infobot.auto-complete", _temp_a); Core.irc.Queue.DeliverMessage(messages.Localize("configuresave", chan.Language, new List<string> { value, config }), chan.Name); chan.SaveConfig(); return true; } Core.irc.Queue.DeliverMessage(messages.Localize("configure-va", chan.Language, new List<string> { config, value }), chan.Name); return true; case "infobot-sorted": if (bool.TryParse(value, out _temp_a)) { Module.SetConfig(chan, "Infobot.Sorted", _temp_a); Core.irc.Queue.DeliverMessage(messages.Localize("configuresave", chan.Language, new List<string> { value, config }), chan.Name); chan.SaveConfig(); return true; } Core.irc.Queue.DeliverMessage(messages.Localize("configure-va", chan.Language, new List<string> { config, value }), chan.Name); return true; case "infobot-help": if (bool.TryParse(value, out _temp_a)) { Module.SetConfig(chan, "Infobot.Help", _temp_a); Core.irc.Queue.DeliverMessage(messages.Localize("configuresave", chan.Language, new List<string> { value, config }), chan.Name); chan.SaveConfig(); return true; } Core.irc.Queue.DeliverMessage(messages.Localize("configure-va", chan.Language, new List<string> { config, value }), chan.Name); return true; case "infobot-case": if (bool.TryParse(value, out _temp_a)) { Module.SetConfig(chan, "Infobot.Case", _temp_a); Core.irc.Queue.DeliverMessage(messages.Localize("configuresave", chan.Language, new List<string> { value, config }), chan.Name); chan.SaveConfig(); Infobot infobot = (Infobot)chan.RetrieveObject("Infobot"); if (infobot != null) { infobot.Sensitive = _temp_a; } return true; } Core.irc.Queue.DeliverMessage(messages.Localize("configure-va", chan.Language, new List<string> { config, value }), chan.Name); return true; } return false; }
public override void Hook_PRIV(Channel channel, User invoker, string message) { if (message.StartsWith(Configuration.System.CommandPrefix + "optools-on")) { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (GetConfig(channel, "OP.Enabled", false)) { Core.irc.Queue.DeliverMessage(messages.Localize("OpE1", channel.Language), channel); return; } else { Core.irc.Queue.DeliverMessage(messages.Localize("OpM1", channel.Language), channel.Name); SetConfig(channel, "OP.Enabled", true); channel.SaveConfig(); return; } } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } return; } if (message == Configuration.System.CommandPrefix + "optools-permanent-off") { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (!GetConfig(channel, "OP.Permanent", false)) { Core.irc.Queue.DeliverMessage(messages.Localize("OpE2", channel.Language), channel); return; } else { Core.irc.Queue.DeliverMessage(messages.Localize("OpM2", channel.Language), channel); SetConfig(channel, "OP.Permanent", false); channel.SaveConfig(); return; } } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message == Configuration.System.CommandPrefix + "optools-permanent-on") { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (GetConfig(channel, "OP.Permanent", false)) { Core.irc.Queue.DeliverMessage(messages.Localize("OpE3", channel.Language), channel); return; } else { Core.irc.Queue.DeliverMessage(messages.Localize("OpM3", channel.Language), channel); SetConfig(channel, "OP.Permanent", true); channel.SaveConfig(); return; } } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message == Configuration.System.CommandPrefix + "optools-off") { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (!GetConfig(channel, "OP.Enabled", false)) { Core.irc.Queue.DeliverMessage(messages.Localize("OpE4", channel.Language), channel); return; } else { Core.irc.Queue.DeliverMessage(messages.Localize("OpM4", channel.Language), channel); SetConfig(channel, "OP.Enabled", false); channel.SaveConfig(); return; } } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message.StartsWith(Configuration.System.CommandPrefix + "kick ")) { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (GetConfig(channel, "OP.Enabled", false)) { string nick = message.Substring(6); string reason = "Removed from the channel"; if (nick.Contains(" ")) { reason = nick.Substring(nick.IndexOf(" ") + 1); nick = nick.Substring(0, nick.IndexOf(" ")); } User user = getUser(nick, channel); if (user == null) { Core.irc.Queue.DeliverMessage(messages.Localize("OpE5", channel.Language), channel, IRC.priority.high); return; } // op self GetOp(channel); channel.PrimaryInstance.irc.Queue.Send("KICK " + channel.Name + " " + user.Nick + " :" + reason, IRC.priority.high); if (!GetConfig(channel, "OP.Permanent", false)) { channel.PrimaryInstance.irc.Queue.Send("MODE " + channel.Name + " -o " + channel.PrimaryInstance.Nick, IRC.priority.low); } return; } return; } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } return; } if (message.StartsWith(Configuration.System.CommandPrefix + "kb ")) { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (GetConfig(channel, "OP.Enabled", false)) { string nick = message.Substring(4); string reason = "Removed from the channel"; if (nick.Contains(" ")) { reason = nick.Substring(nick.IndexOf(" ") + 1); nick = nick.Substring(0, nick.IndexOf(" ")); } User user = getUser(nick, channel); if (user == null) { Core.irc.Queue.DeliverMessage(messages.Localize("OpE5", channel.Language), channel, IRC.priority.high); return; } // op self GetOp(channel); if (string.IsNullOrEmpty(user.Host)) { Core.irc.Queue.DeliverMessage(messages.Localize("OpE6", channel.Language), channel, IRC.priority.high); } else { channel.PrimaryInstance.irc.Queue.Send("MODE " + channel.Name + " +b *!*@" + user.Host, IRC.priority.high); } channel.PrimaryInstance.irc.Queue.Send("KICK " + channel.Name + " " + user.Nick + " :" + reason, IRC.priority.high); if (!GetConfig(channel, "OP.Permanent", false)) { channel.PrimaryInstance.irc.Queue.Send("MODE " + channel.Name + " -o " + channel.PrimaryInstance.Nick, IRC.priority.low); } return; } return; } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } return; } if (message.StartsWith(Configuration.System.CommandPrefix + "unkb ")) { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (GetConfig(channel, "OP.Enabled", false)) { string nick = message.Substring(6); GetOp(channel); channel.PrimaryInstance.irc.Queue.Send("MODE " + channel.Name + " -b *!*@" + nick, IRC.priority.high); if (!GetConfig(channel, "OP.Permanent", false)) { channel.PrimaryInstance.irc.Queue.Send("MODE " + channel.Name + " -o " + channel.PrimaryInstance.Nick, IRC.priority.low); } return; } return; } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } return; } if (message.StartsWith(Configuration.System.CommandPrefix + "unq ")) { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (GetConfig(channel, "OP.Enabled", false)) { string nick = message.Substring(5); if (nick.Contains(" ")) { nick = nick.Substring(0, nick.IndexOf(" ")); } User user = getUser(nick, channel); if (user == null) { Core.irc.Queue.DeliverMessage(messages.Localize("OpE5", channel.Language), channel, IRC.priority.high); return; } if (string.IsNullOrEmpty(user.Host)) { Core.irc.Queue.DeliverMessage(messages.Localize("OpE6", channel.Language), channel, IRC.priority.high); return; } // op self GetOp(channel); channel.PrimaryInstance.irc.Queue.Send("MODE " + channel.Name + " -q *!*@" + user.Host, IRC.priority.high); if (!GetConfig(channel, "OP.Permanent", false)) { channel.PrimaryInstance.irc.Queue.Send("MODE " + channel.Name + " -o " + channel.PrimaryInstance.Nick, IRC.priority.low); } return; } return; } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } return; } if (message.StartsWith(Configuration.System.CommandPrefix + "q ")) { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (GetConfig(channel, "OP.Enabled", false)) { string nick = message.Substring(3); if (nick.Contains(" ")) { nick = nick.Substring(0, nick.IndexOf(" ")); } User user = getUser(nick, channel); if (user == null) { Core.irc.Queue.DeliverMessage(messages.Localize("OpE5", channel.Language), channel, IRC.priority.high); return; } if (string.IsNullOrEmpty(user.Host)) { Core.irc.Queue.DeliverMessage(messages.Localize("OpE6", channel.Language), channel, IRC.priority.high); return; } GetOp(channel); channel.PrimaryInstance.irc.Queue.Send("MODE " + channel.Name + " +q *!*@" + user.Host, IRC.priority.high); if (!GetConfig(channel, "OP.Permanent", false)) { channel.PrimaryInstance.irc.Queue.Send("MODE " + channel.Name + " -o " + channel.PrimaryInstance.Nick, IRC.priority.low); } return; } return; } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } return; } if (message.StartsWith(Configuration.System.CommandPrefix + "jb ")) { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (GetConfig(channel, "OP.Enabled", false)) { string nick = message.Substring(4); if (nick.Contains(" ")) { nick = nick.Substring(0, nick.IndexOf(" ")); } User user = getUser(nick, channel); if (user != null) { nick = user.Nick; } // op self GetOp(channel); channel.PrimaryInstance.irc.Queue.Send("MODE " + channel.Name + " +b " + nick + "!*@*$##fix_your_connection", IRC.priority.high); if (!GetConfig(channel, "OP.Permanent", false)) { channel.PrimaryInstance.irc.Queue.Send("MODE " + channel.Name + " -o " + channel.PrimaryInstance.Nick, IRC.priority.low); } return; } return; } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } return; } if (message.StartsWith(Configuration.System.CommandPrefix + "unjb ")) { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (GetConfig(channel, "OP.Enabled", false)) { string nick = message.Substring(6); if (nick.Contains(" ")) { nick = nick.Substring(0, nick.IndexOf(" ")); } User user = getUser(nick, channel); if (user != null) { nick = user.Nick; } // op self GetOp(channel); channel.PrimaryInstance.irc.Queue.Send("MODE " + channel.Name + " -b " + nick + "!*@*$##fix_your_connection", IRC.priority.high); if (!GetConfig(channel, "OP.Permanent", false)) { channel.PrimaryInstance.irc.Queue.Send("MODE " + channel.Name + " -o " + channel.PrimaryInstance.Nick, IRC.priority.low); } return; } return; } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } return; } }
public override void Hook_PRIV(Channel channel, libirc.UserInfo invoker, string message) { if (channel.Name != RequestChannel) { return; } if (message == Configuration.System.CommandPrefix + "requests-off") { if (channel.SystemUsers.IsApproved(invoker.Nick, invoker.Host, "admin")) { if (!GetConfig(channel, "Requests.Enabled", false)) { IRC.DeliverMessage("Requests are already disabled", channel.Name); return; } IRC.DeliverMessage("Requests were disabled", channel.Name); SetConfig(channel, "Requests.Enabled", false); channel.SaveConfig(); return; } if (!channel.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel); } return; } if (message == Configuration.System.CommandPrefix + "requests-on") { if (channel.SystemUsers.IsApproved(invoker.Nick, invoker.Host, "admin")) { if (GetConfig(channel, "Requests.Enabled", false)) { IRC.DeliverMessage("Requests system is already enabled", channel); return; } SetConfig(channel, "Requests.Enabled", true); channel.SaveConfig(); IRC.DeliverMessage("Requests were enabled", channel); return; } if (!channel.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel); } return; } if (message == Configuration.System.CommandPrefix + "requests") { if (!GetConfig(channel, "Requests.Enabled", false)) { IRC.DeliverMessage("You need to enable requests in this channel for this command to work", channel); return; } lock (this.WaitingRequests) { if (this.WaitingRequests.Contains(channel.Name)) { IRC.DeliverMessage("I am already fetching the list of waiting users for this channel", channel); return; } IRC.DeliverMessage("I am fetching the list of waiting users...", channel); this.WaitingRequests.Add(channel.Name); } } }
public override void Hook_PRIV(Channel channel, User invoker, string message) { if (message == Configuration.System.CommandPrefix + "relay-off") { if (channel.SystemUsers.IsApproved(invoker.Nick, invoker.Host, "admin")) { if (!GetConfig(channel, "NetCat.Enabled", false)) { Core.irc.Queue.DeliverMessage("Relay is already disabled", channel.Name); return; } SetConfig(channel, "NetCat.Enabled", false); channel.SaveConfig(); Core.irc.Queue.DeliverMessage("Relay was disabled", channel.Name); return; } else { if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } } return; } if (message == Configuration.System.CommandPrefix + "token-on") { if (channel.SystemUsers.IsApproved(invoker.Nick, invoker.Host, "admin")) { string token = GenerateToken(); SetConfig(channel, "NetCat.Token", true); SetConfig(channel, "NetCat.TokenData", token); channel.SaveConfig(); Core.irc.Queue.DeliverMessage("New token was generated for this channel, and it was sent to you in a private message", channel.Name); Core.irc.Queue.DeliverMessage("Token for " + channel.Name + " is: " + token, invoker.Nick, IRC.priority.normal); return; } else { if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } } return; } if (message == Configuration.System.CommandPrefix + "token-off") { if (channel.SystemUsers.IsApproved(invoker.Nick, invoker.Host, "admin")) { SetConfig(channel, "NetCat.Token", false); channel.SaveConfig(); Core.irc.Queue.DeliverMessage("This channel will no longer require a token in order to relay messages into it", channel.Name); return; } else { if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } } return; } if (message == Configuration.System.CommandPrefix + "token-remind") { if (channel.SystemUsers.IsApproved(invoker.Nick, invoker.Host, "admin")) { if (!GetConfig(channel, "NetCat.Token", false)) { Core.irc.Queue.DeliverMessage("This channel doesn't require a token", channel.Name); return; } string token = GetConfig(channel, "NetCat.TokenData", "<invalid>"); Core.irc.Queue.DeliverMessage("Token for " + channel.Name + " is: " + token, invoker.Nick, IRC.priority.normal); return; } else { if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } } return; } if (message == Configuration.System.CommandPrefix + "relay-on") { if (channel.SystemUsers.IsApproved(invoker.Nick, invoker.Host, "admin")) { if (GetConfig(channel, "NetCat.Enabled", false)) { Core.irc.Queue.DeliverMessage("Relay is already enabled", channel.Name); return; } SetConfig(channel, "NetCat.Enabled", true); channel.SaveConfig(); Core.irc.Queue.DeliverMessage("Relay was enabled", channel.Name); return; } else { if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } } return; } }
/// <summary> /// Display admin command /// </summary> /// <param name="chan">Channel</param> /// <param name="user">User name</param> /// <param name="host">Host</param> /// <param name="message">Message</param> public static void ParseAdmin(Channel chan, string user, string host, string message) { libirc.UserInfo invoker = new libirc.UserInfo(user, "", host); if (message == Configuration.System.CommandPrefix + "reload") { if (chan.SystemUsers.IsApproved(invoker, "admin")) { chan.LoadConfig(); SystemHooks.IrcReloadChannelConf(chan); IRC.DeliverMessage(messages.Localize("Config", chan.Language), chan); return; } if (!chan.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("PermissionDenied", chan.Language), chan); } return; } if (message == Configuration.System.CommandPrefix + "info") { IRC.DeliverMessage(Configuration.WebPages.WebpageURL + Configuration.Paths.DumpDir + "/" + HttpUtility.UrlEncode(chan.Name) + ".htm", chan); return; } if (message.StartsWith(Configuration.System.CommandPrefix + "part ")) { string channel = message.Substring(6); if (channel != "") { Channel _Channel = Core.GetChannel(channel); if (_Channel == null) { IRC.DeliverMessage(messages.Localize("UnknownChan", chan.Language), chan, libirc.Defs.Priority.Low); return; } PartChannel(_Channel, invoker.Nick, invoker.Host, Configuration.System.CommandPrefix + "part", chan.Name); return; } IRC.DeliverMessage(messages.Localize("Responses-PartFail", chan.Language), chan, libirc.Defs.Priority.Low); return; } if (message.StartsWith(Configuration.System.CommandPrefix + "drop ")) { string channel = message.Substring(6); if (channel != "") { Channel _Channel = Core.GetChannel(channel); if (_Channel == null) { IRC.DeliverMessage(messages.Localize("UnknownChan", chan.Language), chan, libirc.Defs.Priority.Low); return; } PartChannel(_Channel, invoker.Nick, invoker.Host, Configuration.System.CommandPrefix + "drop", chan.Name); return; } IRC.DeliverMessage(messages.Localize("Responses-PartFail", chan.Language), chan, libirc.Defs.Priority.Low); return; } if (message.StartsWith(Configuration.System.CommandPrefix + "language")) { if (chan.SystemUsers.IsApproved(invoker, "admin")) { string parameter = ""; if (message.Contains(" ")) { parameter = message.Substring(message.IndexOf(" ") + 1).ToLower(); } if (parameter != "") { if (messages.Exists(parameter)) { chan.Language = parameter; IRC.DeliverMessage(messages.Localize("Language", chan.Language), chan); chan.SaveConfig(); return; } if (!chan.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("InvalidCode", chan.Language), chan); } return; } IRC.DeliverMessage(messages.Localize("LanguageInfo", chan.Language), chan); return; } if (!chan.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("PermissionDenied", chan.Language), chan, libirc.Defs.Priority.Low); } return; } if (message.StartsWith(Configuration.System.CommandPrefix + "help")) { string parameter = ""; if (message.Contains(" ")) { parameter = message.Substring(message.IndexOf(" ") + 1); } if (parameter != "") { Core.ShowHelp(parameter, chan); return; } IRC.DeliverMessage("I am running http://meta.wikimedia.org/wiki/WM-Bot version " + Configuration.System.Version + " my source code is licensed " + "under GPL and located at https://github.com/benapetr/wikimedia-bot " + "I will be very happy if you fix my bugs or implement new features", chan); return; } if (message == Configuration.System.CommandPrefix + "suppress-off") { if (chan.SystemUsers.IsApproved(invoker, "admin")) { if (!chan.Suppress) { IRC.DeliverMessage(messages.Localize("Silence1", chan.Language), chan); return; } chan.Suppress = false; IRC.DeliverMessage(messages.Localize("Silence2", chan.Language), chan); chan.SaveConfig(); Configuration.Save(); return; } if (!chan.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("PermissionDenied", chan.Language), chan, libirc.Defs.Priority.Low); } return; } if (message == Configuration.System.CommandPrefix + "suppress-on") { if (chan.SystemUsers.IsApproved(invoker, "admin")) { if (chan.Suppress) { //Message("Channel had already quiet mode disabled", chan.name); return; } IRC.DeliverMessage(messages.Localize("SilenceBegin", chan.Language), chan); chan.Suppress = true; chan.SaveConfig(); return; } if (!chan.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("PermissionDenied", chan.Language), chan, libirc.Defs.Priority.Low); } return; } if (message == Configuration.System.CommandPrefix + "whoami") { SystemUser current = chan.SystemUsers.GetUser(user + "!@" + host); if (current.Role == "null") { IRC.DeliverMessage(messages.Localize("Unknown", chan.Language), chan); return; } IRC.DeliverMessage(messages.Localize("usr1", chan.Language, new List<string> { current.Role, current.Name }), chan); return; } if (message.StartsWith(Configuration.System.CommandPrefix + "instance ")) { if (chan.SystemUsers.IsApproved(invoker, "root")) { message = message.Substring(".instance ".Length); if (!message.Contains(" ")) { IRC.DeliverMessage("This command need 2 parameters", chan); return; } string channel = message.Substring(message.IndexOf(" ") + 1); string instance = message.Substring(0, message.IndexOf(" ")); Channel ch = Core.GetChannel(channel); if (ch == null) { IRC.DeliverMessage("This channel I never heard of :'(", chan); return; } Instance _instance; lock (Instance.Instances) { if (!Instance.Instances.ContainsKey(instance)) { IRC.DeliverMessage("This instance I never heard of :'(", chan); return; } _instance = Instance.Instances[instance]; } if (_instance == ch.PrimaryInstance) { IRC.DeliverMessage("This channel is already in this instance", chan); return; } ch.PrimaryInstance.Network.Transfer("PART " + ch.Name + " :Switching instance"); ch.PrimaryInstance = _instance; ch.PrimaryInstance.Network.Transfer("JOIN " + ch.Name); ch.DefaultInstance = ch.PrimaryInstance.Nick; ch.SaveConfig(); IRC.DeliverMessage("Changed default instance of " + channel + " to " + instance, chan); return; } if (!chan.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("PermissionDenied", chan.Language), chan, libirc.Defs.Priority.Low); } } if (message == Configuration.System.CommandPrefix + "traffic-off") { if (chan.SystemUsers.IsApproved(invoker, "root")) { Configuration.Network.Logging = false; IRC.DeliverMessage("Logging stopped", chan); return; } if (!chan.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("PermissionDenied", chan.Language), chan, libirc.Defs.Priority.Low); } } if (message == Configuration.System.CommandPrefix + "traffic-on") { if (chan.SystemUsers.IsApproved(invoker, "root")) { Configuration.Network.Logging = true; IRC.DeliverMessage("Logging traf", chan.Name); return; } if (!chan.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("PermissionDenied", chan.Language), chan, libirc.Defs.Priority.Low); } } if (message == Configuration.System.CommandPrefix + "restart") { if (chan.SystemUsers.IsApproved(invoker, "root")) { IRC.DeliverMessage("System is shutting down, requested by " + invoker.Nick + " from " + chan.Name, Configuration.System.DebugChan, libirc.Defs.Priority.High); Syslog.Log("System is shutting down, requested by " + invoker.Nick + " from " + chan.Name); Core.Kill(); return; } if (!chan.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("PermissionDenied", chan.Language), chan.Name, libirc.Defs.Priority.Low); } } if (message == Configuration.System.CommandPrefix + "channellist") { IRC.DeliverMessage(messages.Localize("Responses-List", chan.Language, new List<string> { Configuration.Channels.Count.ToString() }), chan); return; } if (message.StartsWith(Configuration.System.CommandPrefix + "configure ")) { if (chan.SystemUsers.IsApproved(invoker, "admin")) { string text = message.Substring("@configure ".Length); if (string.IsNullOrEmpty(text)) { return; } if (text.Contains("=") && !text.EndsWith("=")) { string name = text.Substring(0, text.IndexOf("=")); string value = text.Substring(text.IndexOf("=") + 1); bool _temp_a; switch (name) { case "ignore-unknown": if (bool.TryParse(value, out _temp_a)) { chan.IgnoreUnknown = _temp_a; IRC.DeliverMessage(messages.Localize("configuresave", chan.Language, new List<string> { value, name }), chan); chan.SaveConfig(); return; } IRC.DeliverMessage(messages.Localize("configure-va", chan.Language, new List<string> { name, value }), chan); return; case "respond-wait": int _temp_b; if (int.TryParse(value, out _temp_b)) { if (_temp_b > 1 && _temp_b < 364000) { chan.RespondWait = _temp_b; IRC.DeliverMessage(messages.Localize("configuresave", chan.Language, new List<string> { value, name }), chan); chan.SaveConfig(); return; } } IRC.DeliverMessage(messages.Localize("configure-va", chan.Language, new List<string> { name, value }), chan); return; case "respond-message": if (bool.TryParse(value, out _temp_a)) { chan.RespondMessage = _temp_a; IRC.DeliverMessage(messages.Localize("configuresave", chan.Language, new List<string> { value, name }), chan); chan.SaveConfig(); return; } IRC.DeliverMessage(messages.Localize("configure-va", chan.Language, new List<string> { name, value }), chan); return; case "suppress-warnings": if (bool.TryParse(value, out _temp_a)) { chan.SuppressWarnings = _temp_a; IRC.DeliverMessage(messages.Localize("configuresave", chan.Language, new List<string> { value, name }), chan); chan.SaveConfig(); return; } IRC.DeliverMessage(messages.Localize("configure-va", chan.Language, new List<string> { name, value }), chan); return; } bool exist = false; lock (ExtensionHandler.Extensions) { foreach (Module curr in ExtensionHandler.Extensions) { try { if (curr.IsWorking) { if (curr.Hook_SetConfig(chan, invoker, name, value)) { exist = true; } } } catch (Exception fail) { Syslog.Log("Error on Hook_SetConfig module " + curr.Name); Core.HandleException(fail, curr.Name); } } } if (!chan.SuppressWarnings && !exist) { IRC.DeliverMessage(messages.Localize("configure-wrong", chan.Language), chan); } return; } if (!text.Contains(" ")) { switch (text) { case "ignore-unknown": IRC.DeliverMessage(messages.Localize("Responses-Conf", chan.Language, new List<string> { text, chan.IgnoreUnknown.ToString() } ), chan); return; case "respond-message": IRC.DeliverMessage(messages.Localize("Responses-Conf", chan.Language, new List<string> { text, chan.RespondMessage.ToString() }), chan); return; case "suppress-warnings": IRC.DeliverMessage(messages.Localize("Responses-Conf", chan.Language, new List<string> { text, chan.SuppressWarnings.ToString() } ), chan); return; } bool exist = false; lock (ExtensionHandler.Extensions) { foreach (Module curr in ExtensionHandler.Extensions) { try { if (curr.IsWorking) { if (curr.Hook_GetConfig(chan, invoker, text)) { exist = true; } } } catch (Exception fail) { Syslog.Log("Error on Hook_GetConfig module " + curr.Name); Core.HandleException(fail); } } } if (exist) { return; } } if (!chan.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("configure-wrong", chan.Language), chan); } return; } if (!chan.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("PermissionDenied", chan.Language), chan, libirc.Defs.Priority.Low); } return; } #if FALSE if (message.StartsWith(Configuration.System.CommandPrefix + "system-lm ")) { if (chan.SystemUsers.IsApproved(invoker, "root")) { string module = message.Substring("@system-lm ".Length); if (module.EndsWith(".bin")) { Module _m = ExtensionHandler.RetrieveModule(module); if (_m != null) { Core.irc.Queue.DeliverMessage("This module was already loaded and you can't load one module twice," +" module will be reloaded now", chan, IRC.priority.high); _m.Exit(); } if (module.EndsWith(".bin")) { module = "modules" + Path.DirectorySeparatorChar + module; if (File.Exists(module)) { if (ExtensionHandler.LoadAllModulesInLibrary(module)) { Core.irc.Queue.DeliverMessage("Loaded module " + module, chan, IRC.priority.high); return; } Core.irc.Queue.DeliverMessage("Unable to load module " + module, chan, IRC.priority.high); return; } Core.irc.Queue.DeliverMessage("File not found " + module, chan, IRC.priority.high); return; } Core.irc.Queue.DeliverMessage("Loaded module " + module, chan, IRC.priority.high); return; } Core.irc.Queue.DeliverMessage("This module is not currently loaded in core", chan, IRC.priority.high); return; } } #endif if (message == Configuration.System.CommandPrefix + "verbosity--") { if (chan.SystemUsers.IsApproved(invoker, "root")) { if (Configuration.System.SelectedVerbosity > 0) { Configuration.System.SelectedVerbosity--; } IRC.DeliverMessage("Verbosity: " + Configuration.System.SelectedVerbosity, chan, libirc.Defs.Priority.High); } } if (message == Configuration.System.CommandPrefix + "verbosity++") { if (chan.SystemUsers.IsApproved(invoker, "root")) { Configuration.System.SelectedVerbosity++; IRC.DeliverMessage("Verbosity: " + Configuration.System.SelectedVerbosity, chan, libirc.Defs.Priority.High); } } if (message.StartsWith(Configuration.System.CommandPrefix + "system-rm ")) { if (chan.SystemUsers.IsApproved(invoker, "root")) { string module = message.Substring("@system-lm ".Length); Module _m = ExtensionHandler.RetrieveModule(module); if (_m == null) { IRC.DeliverMessage("This module is not currently loaded in core", chan, libirc.Defs.Priority.High); return; } _m.Exit(); IRC.DeliverMessage("Unloaded module " + module, chan, libirc.Defs.Priority.High); } } if (message == Configuration.System.CommandPrefix + "commands") { IRC.DeliverMessage("Commands: there is too many commands to display on one line," + " see http://meta.wikimedia.org/wiki/wm-bot for a list of" + " commands and help", chan); } }
public override bool Hook_SetConfig(Channel chan, User invoker, string config, string value) { if (config == "style-rss") { if (value != "") { SetConfig(chan, "Rss.Style", value); chan.SaveConfig(); Core.irc.Queue.DeliverMessage(messages.Localize("configuresave", chan.Language, new List<string> { value, config }), chan.Name); return true; } Core.irc.Queue.DeliverMessage(messages.Localize("configure-va", chan.Language, new List<string> { config, value }), chan.Name); return true; } return false; }
public override void Hook_PRIV(Channel channel, User invoker, string message) { if (message.StartsWith(Configuration.System.CommandPrefix + "rss- ")) { if (channel.SystemUsers.IsApproved(invoker, "trust")) { string item = message.Substring("@rss+ ".Length); Feed feed = (Feed)channel.RetrieveObject("rss"); if (feed != null) { feed.RemoveItem(item); } return; } else { if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } } } if (message.StartsWith(Configuration.System.CommandPrefix + "rss-setstyle ")) { if (channel.SystemUsers.IsApproved(invoker, "trust")) { string item = message.Substring("@rss-setstyle ".Length); if (item.Contains(" ")) { string id = item.Substring(0, item.IndexOf(" ")); string ur = item.Substring(item.IndexOf(" ") + 1); Feed feed = (Feed)channel.RetrieveObject("rss"); if (feed != null) { feed.StyleItem(id, ur); } return; } if (item != "") { Feed feed = (Feed)channel.RetrieveObject("rss"); if (feed != null) { feed.StyleItem(item, ""); } return; } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("Rss5", channel.Language), channel.Name, IRC.priority.low); } } else { if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } } } if (message.StartsWith(Configuration.System.CommandPrefix + "rss-search+ ")) { if (channel.SystemUsers.IsApproved(invoker, "trust")) { string item = message.Substring("@rss-search+ ".Length); Feed feed = (Feed)channel.RetrieveObject("rss"); if (feed != null) { lock (feed.ScannerMatches) { if (feed.ScannerMatches.Contains(item)) { Core.irc.Queue.DeliverMessage("This item is already being searched", channel); return; } Core.irc.Queue.DeliverMessage("This item is now searched", channel); feed.ScannerMatches.Add(item); return; } } Core.irc.Queue.DeliverMessage("Error, this channel doesn't have RC feed", channel); return; } else { if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel, IRC.priority.low); } } } if (message.StartsWith(Configuration.System.CommandPrefix + "rss-search- ")) { if (channel.SystemUsers.IsApproved(invoker, "trust")) { string item = message.Substring("@rss-search+ ".Length); Feed feed = (Feed)channel.RetrieveObject("rss"); if (feed != null) { lock (feed.ScannerMatches) { if (feed.ScannerMatches.Contains(item)) { feed.ScannerMatches.Remove(item); Core.irc.Queue.DeliverMessage("This item was removed", channel); return; } Core.irc.Queue.DeliverMessage("This item was not being searched", channel); return; } } Core.irc.Queue.DeliverMessage("Error, this channel doesn't have RC feed", channel); return; } else { if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel, IRC.priority.low); } } } if (message.StartsWith(Configuration.System.CommandPrefix + "rss+ ")) { if (channel.SystemUsers.IsApproved(invoker, "trust")) { string item = message.Substring("@rss+ ".Length); if (item.Contains(" ")) { string id = item.Substring(0, item.IndexOf(" ")); string ur = item.Substring(item.IndexOf(" ") + 1); Feed feed = (Feed)channel.RetrieveObject("rss"); if (feed != null) { feed.InsertItem(id, ur); } return; } if (item != "") { Feed feed = (Feed)channel.RetrieveObject("rss"); if (feed != null) { feed.InsertItem(item, ""); } return; } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("Rss5", channel.Language), channel.Name, IRC.priority.low); } } else { if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } } } if (message.StartsWith("@rss-scanner+ ")) { if (channel.SystemUsers.IsApproved(invoker, "trust")) { string item = message.Substring("@rss-scanner+ ".Length); if (item.Contains(" ")) { string id = item.Substring(0, item.IndexOf(" ")); string ur = item.Substring(item.IndexOf(" ") + 1); Feed feed = (Feed)channel.RetrieveObject("rss"); if (feed != null) { feed.InsertItem(id, ur, true); } return; } if (item != "") { Feed feed = (Feed)channel.RetrieveObject("rss"); if (feed != null) { feed.InsertItem(item, "", true); } return; } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("Rss5", channel.Language), channel.Name, IRC.priority.low); } } else { if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } } } if (message.StartsWith("@rss-scanner- ")) { if (channel.SystemUsers.IsApproved(invoker, "trust")) { string item = message.Substring("@rss-scannerx ".Length); Feed feed = (Feed)channel.RetrieveObject("rss"); if (feed != null) { feed.RemoveItem(item); } return; } else { if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } } } if (message == "@rss-off") { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (!GetConfig(channel, "Rss.Enable", false)) { Core.irc.Queue.DeliverMessage(messages.Localize("Rss1", channel.Language), channel.Name); return; } else { SetConfig(channel, "Rss.Enable", false); Core.irc.Queue.DeliverMessage(messages.Localize("Rss2", channel.Language), channel.Name); channel.SaveConfig(); return; } } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } return; } if (message == "@rss-on") { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (GetConfig(channel, "Rss.Enable", false)) { Core.irc.Queue.DeliverMessage(messages.Localize("Rss3", channel.Language), channel.Name); return; } else { Core.irc.Queue.DeliverMessage(messages.Localize("Rss4", channel.Language), channel.Name); SetConfig(channel, "Rss.Enable", true); channel.SaveConfig(); return; } } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } return; } }
public override void Hook_PRIV(Channel channel, libirc.UserInfo invoker, string message) { if (message.StartsWith("@labs-off")) { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (!GetConfig(channel, "LABS.Enabled", false)) { IRC.DeliverMessage("Labs utilities are already disabled", channel.Name); return; } SetConfig(channel, "LABS.Enabled", false); channel.SaveConfig(); IRC.DeliverMessage("Labs utilities were disabled", channel.Name); return; } else { if (!channel.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name); } } return; } if (message.StartsWith("@labs-on")) { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (GetConfig(channel, "LABS.Enabled", false)) { IRC.DeliverMessage("Labs utilities are already enabled", channel.Name); return; } SetConfig(channel, "LABS.Enabled", true); channel.SaveConfig(); IRC.DeliverMessage("Labs utilities were enabled", channel.Name); return; } else { if (!channel.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name); } } return; } if (message.StartsWith("@labs-user ")) { if (GetConfig(channel, "LABS.Enabled", false)) { string user = message.Substring(11); string result = getProjects(user); int list = getNumbers(user); if (result != "") { IRC.DeliverMessage(user + " is member of " + list.ToString() + " projects: " + result, channel.Name); return; } IRC.DeliverMessage("That user is not a member of any project", channel.Name); return; } } if (message.StartsWith("@labs-info ")) { if (GetConfig(channel, "LABS.Enabled", false)) { string host = message.Substring("@labs-info ".Length); string results = ""; if (!OK) { IRC.DeliverMessage("Please wait, I still didn't retrieve the labs datafile containing the list of instances", channel.Name); return; } Instance instance = getInstance(host); if (instance == null) { instance = resolve(host); if (instance != null) { results = "[Name " + host + " doesn't exist but resolves to " + instance.OriginalName + "] "; } } if (instance != null) { results += instance.OriginalName + " is Nova Instance with name: " + instance.Name + ", host: " + instance.Host + ", IP: " + instance.IP + " of type: " + instance.Type + ", with number of CPUs: " + instance.NumberOfCpu + ", RAM of this size: " + instance.Ram + "M, member of project: " + instance.Project + ", size of storage: " + instance.Storage + " and with image ID: " + instance.ImageID; IRC.DeliverMessage(results, channel.Name); return; } IRC.DeliverMessage("I don't know this instance, sorry, try browsing the list by hand, but I can guarantee there is no such instance matching this name, host or Nova ID unless it was created less than " + time().Seconds.ToString() + " seconds ago", channel.Name); } } if (message.StartsWith("@labs-resolve ")) { if (GetConfig(channel, "LABS.Enabled", false)) { string host = message.Substring("@labs-resolve ".Length); if (!OK) { IRC.DeliverMessage("Please wait, I still didn't retrieve the labs datafile containing the list of instances", channel); return; } Instance instance = resolve(host); if (instance != null) { string d = "The " + host + " resolves to instance " + instance.OriginalName + " with a fancy name " + instance.Name + " and IP " + instance.IP; IRC.DeliverMessage(d, channel); return; } string names = ""; lock (Instances) { foreach (Instance instance2 in Instances) { if (instance2.Name.Contains(host) || instance2.OriginalName.Contains(host)) { names += instance2.OriginalName + " (" + instance2.Name + "), "; if (names.Length > 210) { break; } } } } if (names != "") { IRC.DeliverMessage("I don't know this instance - aren't you are looking for: " + names, channel); } else { IRC.DeliverMessage("I don't know this instance, sorry, try browsing the list by hand, but I can guarantee there is no such instance matching this name, host or Nova ID unless it was created less than " + time().Seconds.ToString() + " seconds ago", channel); } } } if (message.StartsWith("@labs-project-users ")) { if (GetConfig(channel, "LABS.Enabled", false)) { string host = message.Substring("@labs-project-users ".Length); if (!OK) { IRC.DeliverMessage("Please wait, I still didn't retrieve the labs datafile containing the list of projects", channel); return; } Nova project = getProject(host); if (project != null) { string instances = ""; int trimmed = 0; lock (project.instances) { foreach (string x in project.users) { if (instances.Length > 180) { break; } trimmed++; instances = instances + x + ", "; } if (trimmed == project.users.Count) { IRC.DeliverMessage("Following users are in this project (showing all " + project.users.Count.ToString() + " members): " + instances, channel); return; } IRC.DeliverMessage("Following users are in this project (displaying " + trimmed.ToString() + " of " + project.users.Count.ToString() + " total): " + instances, channel); return; } } string names = getProjectsList(host); if (names != "") { IRC.DeliverMessage("I don't know this project, did you mean: " + names + "? I can guarantee there is no such project matching this name unless it has been created less than " + time().Seconds.ToString() + " seconds ago", channel.Name); return; } IRC.DeliverMessage("I don't know this project, sorry, try browsing the list by hand, but I can guarantee there is no such project matching this name unless it has been created less than " + time().Seconds.ToString() + " seconds ago", channel.Name); } } if (message.StartsWith("@labs-project-instances ")) { if (GetConfig(channel, "LABS.Enabled", false)) { string host = message.Substring("@labs-project-instances ".Length); if (!OK) { IRC.DeliverMessage("Please wait, I still didn't retrieve the labs datafile containing the list of projects", channel.Name); return; } Nova project = getProject(host); if (project != null) { string instances = ""; lock (project.instances) { foreach (Instance x in project.instances) { instances = instances + x.Name + ", "; } IRC.DeliverMessage("Following instances are in this project: " + instances, channel.Name); return; } } string names = getProjectsList(host); if (names != "") { IRC.DeliverMessage("I don't know this project, did you mean: " + names + "? I can guarantee there is no such project matching this name unless it has been created less than " + time().Seconds.ToString() + " seconds ago", channel.Name); return; } IRC.DeliverMessage("I don't know this project, sorry, try browsing the list by hand, but I can guarantee there is no such project matching this name unless it has been created less than " + time().Seconds.ToString() + " seconds ago", channel.Name); } } if (message.StartsWith("@labs-project-info ")) { if (GetConfig(channel, "LABS.Enabled", false)) { string host = message.Substring("@labs-project-info ".Length); if (!OK) { IRC.DeliverMessage("Please wait, I still didn't retrieve the labs datafile containing the list of projects", channel.Name); return; } Nova project = getProject(host); if (project != null) { string d = "The project " + project.Name + " has " + project.instances.Count.ToString() + " instances and " + project.users.Count.ToString() + " members, description: " + project.Description; IRC.DeliverMessage(d, channel.Name); return; } string names = getProjectsList(host); if (names != "") { IRC.DeliverMessage("I don't know this project, did you mean: " + names + "? I can guarantee there is no such project matching this name unless it has been created less than " + time().Seconds.ToString() + " seconds ago", channel.Name); return; } IRC.DeliverMessage("I don't know this project, sorry, try browsing the list by hand, but I can guarantee there is no such project matching this name unless it has been created less than " + time().Seconds.ToString() + " seconds ago", channel.Name); } } }
public override void Hook_PRIV(Channel channel, User invoker, string message) { if (channel.Name != RequestChannel) { return; } if (message == "@requests-off") { if (channel.SystemUsers.IsApproved(invoker.Nick, invoker.Host, "admin")) { if (!GetConfig(channel, "Requests.Enabled", false)) { Core.irc.Queue.DeliverMessage("Requests are already disabled", channel.Name); return; } else { Core.irc.Queue.DeliverMessage("Requests were disabled", channel.Name, IRC.priority.high); SetConfig(channel, "Requests.Enabled", false); channel.SaveConfig(); return; } } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } return; } if (message == "@requests-on") { if (channel.SystemUsers.IsApproved(invoker.Nick, invoker.Host, "admin")) { if (GetConfig(channel, "Requests.Enabled", false)) { Core.irc.Queue.DeliverMessage("Requests system is already enabled", channel.Name); return; } SetConfig(channel, "Requests.Enabled", true); channel.SaveConfig(); Core.irc.Queue.DeliverMessage("Requests were enabled", channel.Name, IRC.priority.high); return; } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } return; } if (message == "@requests") { if (!GetConfig(channel, "Requests.Enabled", false)) { Core.irc.Queue.DeliverMessage("You need to enable requests in this channel for this command to work", channel.Name); return; } lock (this.WaitingRequests) { if (this.WaitingRequests.Contains(channel.Name)) { Core.irc.Queue.DeliverMessage("I am already fetching the list of waiting users for this channel", channel.Name); return; } else { Core.irc.Queue.DeliverMessage("I am fetching the list of waiting users...", channel.Name); } this.WaitingRequests.Add(channel.Name); } return; } }
public override void Hook_PRIV(Channel channel, User invoker, string message) { WriteStatus(invoker.Nick, invoker.Host, channel.Name, item.Action.Talk); if (message.StartsWith(Configuration.System.CommandPrefix + "seen ")) { if (GetConfig(channel, "Seen.Enabled", false)) { string parameter = ""; if (message.Contains(" ")) { parameter = message.Substring(message.IndexOf(" ") + 1); } if (parameter != "") { RetrieveStatus(parameter, channel, invoker.Nick); return; } } } if (message.StartsWith(Configuration.System.CommandPrefix + "seenrx ")) { if (channel.SystemUsers.IsApproved(invoker, "trust")) { if (GetConfig(channel, "Seen.Enabled", false)) { string parameter = ""; if (message.Contains(" ")) { parameter = message.Substring(message.IndexOf(" ") + 1); } if (parameter != "") { RegEx(parameter, channel, invoker.Nick); return; } } return; } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } return; } if (message == Configuration.System.CommandPrefix + "seen-off") { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (!GetConfig(channel, "Seen.Enabled", false)) { Core.irc.Queue.DeliverMessage(messages.Localize("seen-e2", channel.Language), channel.Name); return; } else { Core.irc.Queue.DeliverMessage(messages.Localize("seen-off", channel.Language), channel.Name, IRC.priority.high); SetConfig(channel, "Seen.Enabled", false); channel.SaveConfig(); return; } } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } return; } if (message == Configuration.System.CommandPrefix + "seen-on") { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (GetConfig(channel, "Seen.Enabled", false)) { Core.irc.Queue.DeliverMessage(messages.Localize("seen-oe", channel.Language), channel.Name); return; } SetConfig(channel, "Seen.Enabled", true); channel.SaveConfig(); Core.irc.Queue.DeliverMessage(messages.Localize("seen-on", channel.Language), channel.Name, IRC.priority.high); return; } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } return; } }
/// <summary> /// Part a channel /// </summary> /// <param name="channel">Channel object</param> /// <param name="user">User</param> /// <param name="host">Host</param> /// <param name="message">Message</param> /// <param name="origin">The channel from which this request was sent</param> public static void PartChannel(Channel channel, string user, string host, string message, string origin = "NULL") { try { if (origin == "NULL") origin = channel.Name; if (channel.Name == Configuration.System.DebugChan && (message == Configuration.System.CommandPrefix + "part" || message == Configuration.System.CommandPrefix + "drop")) { IRC.DeliverMessage("Cowardly refusing to part this channel, because I love it :3", channel); return; } if (message == Configuration.System.CommandPrefix + "drop") { if (channel.SystemUsers.IsApproved(user, host, "drop")) { while (!IRC.FinishedJoining) { Syslog.Log("Postponing request to part " + channel.Name + " because bot is still loading", true); Thread.Sleep(2000); } channel.PrimaryInstance.Network.Transfer("PART " + channel.Name + " :" + "dropped by " + user + " from " + origin); Syslog.Log("Dropped " + channel.Name + " dropped by " + user + " from " + origin); Thread.Sleep(100); try { File.Delete(Variables.ConfigurationDirectory + Path.DirectorySeparatorChar + channel.Name + ".xml"); } catch (Exception fail) { Syslog.ErrorLog("Failed to delete configuration file of " + channel.Name); Core.HandleException(fail); } foreach (Module module in ExtensionHandler.ExtensionList) { try { if (module.IsWorking) module.Hook_ChannelDrop(channel); } catch (Exception fail) { Syslog.Log("MODULE: exception at Hook_ChannelDrop in " + module.Name, true); Core.HandleException(fail, module.Name); } } lock (Configuration.Channels) { channel.Remove(); } Configuration.Save(); return; } IRC.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), origin); return; } if (message == Configuration.System.CommandPrefix + "part") { if (channel.SystemUsers.IsApproved(user, host, "part")) { while (!IRC.FinishedJoining) { Syslog.Log("Postponing request to part " + channel.Name + " because bot is still loading", true); Thread.Sleep(2000); } channel.PrimaryInstance.Network.Transfer("PART " + channel.Name + " :" + "removed by " + user + " from " + origin); Syslog.Log("Removed " + channel.Name + " removed by " + user + " from " + origin); Thread.Sleep(100); lock (Configuration.Channels) { channel.Remove(); } channel.SaveConfig(); Configuration.Save(); return; } IRC.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), origin); } } catch (Exception fail) { Core.HandleException(fail); } }
public override void Hook_PRIV(Channel channel, libirc.UserInfo invoker, string message) { if (message == Configuration.System.CommandPrefix + "linkie-off") { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (GetConfig(channel, "Link.Enable", false)) { SetConfig(channel, "Link.Enable", false); channel.SaveConfig(); IRC.DeliverMessage(messages.Localize("Linkie-Off", channel.Language), channel); } else { IRC.DeliverMessage(messages.Localize("Linkie-Off2", channel.Language), channel); } return; } if (!channel.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name); } return; } if (message == Configuration.System.CommandPrefix + "linkie-on") { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (!GetConfig(channel, "Link.Enable", false)) { SetConfig(channel, "Link.Enable", true); channel.SaveConfig(); IRC.DeliverMessage(messages.Localize("Linkie-On", channel.Language), channel); } else { IRC.DeliverMessage(messages.Localize("Linkie-On2", channel.Language), channel); } return; } if (!channel.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name); } return; } if (message == Configuration.System.CommandPrefix + "link") { if (GetConfig(channel, "Link.Last", "") == "") { IRC.DeliverMessage(messages.Localize("Linkie-E1", channel.Language), channel); return; } string xx = MakeTemplate(GetConfig(channel, "Link.Last", ""), GetConfig(channel, "Link.Default", "en"), false) + MakeLink(GetConfig(channel, "Link.Last", ""), GetConfig(channel, "Link.Default", "en"), true); if (xx != "") { IRC.DeliverMessage(xx, channel); return; } IRC.DeliverMessage(messages.Localize("Linkie-E2", channel.Language), channel); return; } if (message.StartsWith(Configuration.System.CommandPrefix + "link ")) { string link = message.Substring(6); string xx = MakeTemplate(link, GetConfig(channel, "Link.Default", "en"), false) + MakeLink(link, GetConfig(channel, "Link.Default", "en"), true); if (xx.Length > 0) { IRC.DeliverMessage(xx, channel); return; } IRC.DeliverMessage(messages.Localize("Linkie-E3", channel.Language), channel); return; } if (GetConfig(channel, "Link.Enable", false)) { string result = MakeTemplate(message, GetConfig(channel, "Link.Default", "en"), false) + MakeLink(message, GetConfig(channel, "Link.Default", "en"), true); if (result.Length > 0) { IRC.DeliverMessage(result, channel); return; } } if (ContainsLink(message)) { SetConfig(channel, "Link.Last", message); } }
public override void Hook_PRIV(Channel channel, User invoker, string message) { // "\uff01" is the full-width version of "!". if ((message.StartsWith("!") || message.StartsWith("\uff01")) && GetConfig(channel, "Infobot.Enabled", true)) { while (Unwritable) { Thread.Sleep(10); } Unwritable = true; Infobot.InfoItem item = new Infobot.InfoItem(); item._Channel = channel; item.Name = "!" + message.Substring(1); // Normalizing "!". item.User = invoker.Nick; item.Host = invoker.Host; jobs.Add(item); Unwritable = false; } Infobot infobot = null; if (message.StartsWith(Configuration.System.CommandPrefix)) { infobot = (Infobot)channel.RetrieveObject("Infobot"); if (infobot == null) { Syslog.Log("Object Infobot in " + channel.Name + " doesn't exist", true); } if (GetConfig(channel, "Infobot.Enabled", true)) { if (infobot != null) { infobot.Find(message, channel); infobot.RSearch(message, channel); } } } if (Snapshots) { if (message.StartsWith(Configuration.System.CommandPrefix + "infobot-recovery ")) { if (channel.SystemUsers.IsApproved(invoker, "admin")) { string name = message.Substring("@infobot-recovery ".Length); if (!GetConfig(channel, "Infobot.Enabled", true)) { Core.irc.Queue.DeliverMessage("Infobot is not enabled in this channel", channel, IRC.priority.low); return; } if (infobot != null) { infobot.RecoverSnapshot(channel, name); } return; } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message.StartsWith(Configuration.System.CommandPrefix + "infobot-snapshot ")) { if (channel.SystemUsers.IsApproved(invoker, "admin")) { string name = message.Substring("@infobot-snapshot ".Length); if (!GetConfig(channel, "Infobot.Enabled", true)) { Core.irc.Queue.DeliverMessage("Infobot is not enabled in this channel", channel, IRC.priority.low); return; } if (infobot != null) { infobot.CreateSnapshot(channel, name); } return; } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message.StartsWith(Configuration.System.CommandPrefix + "infobot-set-raw ")) { if (channel.SystemUsers.IsApproved(invoker, "trust")) { string name = message.Substring("@infobot-set-raw ".Length); if (!GetConfig(channel, "Infobot.Enabled", true)) { Core.irc.Queue.DeliverMessage("Infobot is not enabled in this channel", channel, IRC.priority.low); return; } if (infobot != null) { infobot.SetRaw(name, invoker.Nick, channel); return; } } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message.StartsWith(Configuration.System.CommandPrefix + "infobot-unset-raw ")) { if (channel.SystemUsers.IsApproved(invoker, "trust")) { string name = message.Substring("@infobot-unset-raw ".Length); if (!GetConfig(channel, "Infobot.Enabled", true)) { Core.irc.Queue.DeliverMessage("Infobot is not enabled in this channel", channel, IRC.priority.low); return; } if (infobot != null) { infobot.UnsetRaw(name, invoker.Nick, channel); return; } } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message.StartsWith(Configuration.System.CommandPrefix + "infobot-snapshot-rm ")) { if (channel.SystemUsers.IsApproved(invoker, "admin")) { string name = message.Substring("@infobot-snapshot-rm ".Length); name.Replace(".", ""); name.Replace("/", ""); name.Replace("\\", ""); name.Replace("*", ""); name.Replace("?", ""); if (name == "") { Core.irc.Queue.DeliverMessage("You should specify a file name", channel, IRC.priority.normal); return; } if (!File.Exists(SnapshotsDirectory + Path.DirectorySeparatorChar + channel.Name + Path.DirectorySeparatorChar + name)) { Core.irc.Queue.DeliverMessage("File not found", channel, IRC.priority.normal); return; } File.Delete(SnapshotsDirectory + Path.DirectorySeparatorChar + channel.Name + Path.DirectorySeparatorChar + name); Core.irc.Queue.DeliverMessage("Requested file was removed", channel, IRC.priority.normal); return; } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message == Configuration.System.CommandPrefix + "infobot-snapshot-ls") { string files = ""; DirectoryInfo di = new DirectoryInfo(SnapshotsDirectory + Path.DirectorySeparatorChar + channel.Name); FileInfo[] rgFiles = di.GetFiles("*"); int curr = 0; int displaying = 0; foreach (FileInfo fi in rgFiles) { curr++; if (files.Length < 200) { files += fi.Name + " "; displaying++; } } string response = ""; if (curr == displaying) { response = "There are " + displaying.ToString() + " files: " + files; } else { response = "There are " + curr.ToString() + " files, but displaying only " + displaying.ToString() + " of them: " + files; } if (curr == 0) { response = "There is no snapshot so far, create one!:)"; } Core.irc.Queue.DeliverMessage(response, channel.Name, IRC.priority.normal); return; } } if (message.StartsWith(Configuration.System.CommandPrefix + "infobot-share-trust+ ")) { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (channel.SharedDB != "local") { Core.irc.Queue.DeliverMessage(messages.Localize("infobot16", channel.Language), channel); return; } if (channel.SharedDB != "local" && channel.SharedDB != "") { Core.irc.Queue.DeliverMessage(messages.Localize("infobot15", channel.Language), channel); return; } else { if (message.Length <= "@infobot-share-trust+ ".Length) { Core.irc.Queue.DeliverMessage(messages.Localize("db6", channel.Language), channel.Name); return; } string name = message.Substring("@infobot-share-trust+ ".Length); Channel guest = Core.GetChannel(name); if (guest == null) { Core.irc.Queue.DeliverMessage(messages.Localize("db8", channel.Language), channel.Name); return; } if (channel.SharedLinkedChan.Contains(guest)) { Core.irc.Queue.DeliverMessage(messages.Localize("db14", channel.Language), channel.Name); return; } Core.irc.Queue.DeliverMessage(messages.Localize("db1", channel.Language, new List<string> { name }), channel.Name); lock (channel.SharedLinkedChan) { channel.SharedLinkedChan.Add(guest); } channel.SaveConfig(); return; } } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } return; } if (message.StartsWith(Configuration.System.CommandPrefix + "infobot-ignore- ")) { if (channel.SystemUsers.IsApproved(invoker, "trust")) { string item = message.Substring("@infobot-ignore+ ".Length); if (item != "") { if (!channel.Infobot_IgnoredNames.Contains(item)) { Core.irc.Queue.DeliverMessage(messages.Localize("infobot-ignore-found", channel.Language, new List<string> { item }), channel); return; } channel.Infobot_IgnoredNames.Remove(item); Core.irc.Queue.DeliverMessage(messages.Localize("infobot-ignore-rm", channel.Language, new List<string> { item }), channel); channel.SaveConfig(); return; } } else { if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel, IRC.priority.low); } } } if (message.StartsWith(Configuration.System.CommandPrefix + "infobot-ignore+ ")) { if (channel.SystemUsers.IsApproved(invoker, "trust")) { string item = message.Substring("@infobot-ignore+ ".Length); if (item != "") { if (channel.Infobot_IgnoredNames.Contains(item)) { Core.irc.Queue.DeliverMessage(messages.Localize("infobot-ignore-exist", channel.Language, new List<string> { item }), channel); return; } channel.Infobot_IgnoredNames.Add(item); Core.irc.Queue.DeliverMessage(messages.Localize("infobot-ignore-ok", channel.Language, new List<string> { item }), channel); channel.SaveConfig(); return; } } else { if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel, IRC.priority.low); } } } if (message == Configuration.System.CommandPrefix + "infobot-off") { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (!GetConfig(channel, "Infobot.Enabled", true)) { Core.irc.Queue.DeliverMessage(messages.Localize("infobot1", channel.Language), channel); return; } else { Core.irc.Queue.DeliverMessage(messages.Localize("infobot2", channel.Language), channel, IRC.priority.high); SetConfig(channel, "Infobot.Enabled", false); channel.SaveConfig(); return; } } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message.StartsWith(Configuration.System.CommandPrefix + "infobot-share-trust- ")) { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (channel.SharedDB != "local") { Core.irc.Queue.DeliverMessage(messages.Localize("infobot16", channel.Language), channel); return; } else { if (message.Length <= "@infobot-share-trust+ ".Length) { Core.irc.Queue.DeliverMessage(messages.Localize("db6", channel.Language), channel); return; } string name = message.Substring("@infobot-share-trust- ".Length); Channel target = Core.GetChannel(name); if (target == null) { Core.irc.Queue.DeliverMessage(messages.Localize("db8", channel.Language), channel); return; } if (channel.SharedLinkedChan.Contains(target)) { channel.SharedLinkedChan.Remove(target); Core.irc.Queue.DeliverMessage(messages.Localize("db2", channel.Language, new List<string> { name }), channel); channel.SaveConfig(); return; } Core.irc.Queue.DeliverMessage(messages.Localize("db4", channel.Language), channel); return; } } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message.StartsWith(Configuration.System.CommandPrefix + "infobot-detail ")) { if ((message.Length) <= "@infobot-detail ".Length) { Core.irc.Queue.DeliverMessage(messages.Localize("db6", channel.Language), channel); return; } if (GetConfig(channel, "Infobot.Enabled", true)) { if (channel.SharedDB == "local" || channel.SharedDB == "") { if (infobot != null) { infobot.InfobotDetail(message.Substring(16), channel); } return; } if (channel.SharedDB != "") { Channel db = Core.GetChannel(channel.SharedDB); if (db == null) { Core.irc.Queue.DeliverMessage("Error, null pointer to shared channel", channel, IRC.priority.low); return; } if (infobot != null) { infobot.InfobotDetail(message.Substring(16), channel); } return; } return; } Core.irc.Queue.DeliverMessage("Infobot is not enabled on this channel", channel, IRC.priority.low); return; } if (message.StartsWith(Configuration.System.CommandPrefix + "infobot-link ")) { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (channel.SharedDB == "local") { Core.irc.Queue.DeliverMessage(messages.Localize("infobot17", channel.Language), channel); return; } if (channel.SharedDB != "") { Core.irc.Queue.DeliverMessage(messages.Localize("infobot18", channel.Language, new List<string> { channel.SharedDB }), channel); return; } if ((message.Length - 1) < "@infobot-link ".Length) { Core.irc.Queue.DeliverMessage(messages.Localize("db6", channel.Language), channel); return; } string name = message.Substring("@infobot-link ".Length); Channel db = Core.GetChannel(name); if (db == null) { Core.irc.Queue.DeliverMessage(messages.Localize("db8", channel.Language), channel); return; } if (!Infobot.Linkable(db, channel)) { Core.irc.Queue.DeliverMessage(messages.Localize("db9", channel.Language), channel); return; } channel.SharedDB = name.ToLower(); Core.irc.Queue.DeliverMessage(messages.Localize("db10", channel.Language), channel); channel.SaveConfig(); return; } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message == Configuration.System.CommandPrefix + "infobot-share-off") { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (channel.SharedDB == "") { Core.irc.Queue.DeliverMessage(messages.Localize("infobot14", channel.Language), channel); return; } else { Core.irc.Queue.DeliverMessage(messages.Localize("infobot13", channel.Language), channel); lock (Configuration.Channels) { foreach (Channel curr in Configuration.Channels) { if (curr.SharedDB == channel.Name.ToLower()) { curr.SharedDB = ""; curr.SaveConfig(); Core.irc.Queue.DeliverMessage(messages.Localize("infobot19", curr.Language, new List<string> { invoker.Nick }), curr); } } } channel.SharedDB = ""; channel.SaveConfig(); return; } } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message == Configuration.System.CommandPrefix + "infobot-on") { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (GetConfig(channel, "Infobot.Enabled", true)) { Core.irc.Queue.DeliverMessage(messages.Localize("infobot3", channel.Language), channel); return; } SetConfig(channel, "Infobot.Enabled", true); channel.SaveConfig(); Core.irc.Queue.DeliverMessage(messages.Localize("infobot4", channel.Language), channel, IRC.priority.high); return; } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message == Configuration.System.CommandPrefix + "infobot-share-on") { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (channel.SharedDB == "local") { Core.irc.Queue.DeliverMessage(messages.Localize("infobot11", channel.Language), channel, IRC.priority.high); return; } if (channel.SharedDB != "local" && channel.SharedDB != "") { Core.irc.Queue.DeliverMessage(messages.Localize("infobot15", channel.Language), channel, IRC.priority.high); return; } else { Core.irc.Queue.DeliverMessage(messages.Localize("infobot12", channel.Language), channel); channel.SharedDB = "local"; channel.SaveConfig(); return; } } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } }
public override bool Hook_SetConfig(Channel chan, libirc.UserInfo invoker, string config, string value) { if (config == "default-link-wiki") { if (value != "") { SetConfig(chan, "Link.Default", value); chan.SaveConfig(); IRC.DeliverMessage(messages.Localize("configuresave", chan.Language, new List<string> { value, config }), chan.Name); return true; } IRC.DeliverMessage(messages.Localize("configure-va", chan.Language, new List<string> { config, value }), chan.Name); return true; } return false; }
/// <summary> /// Part a channel /// </summary> /// <param name="channel">Channel object</param> /// <param name="user">User</param> /// <param name="host">Host</param> /// <param name="message">Message</param> /// <param name="origin">The channel from which this request was sent</param> public static void PartChannel(Channel channel, string user, string host, string message, string origin = "NULL") { try { if (origin == "NULL") { origin = channel.Name; } if (channel.Name == Configuration.System.DebugChan && (message == Configuration.System.CommandPrefix + "part" || message == Configuration.System.CommandPrefix + "drop")) { IRC.DeliverMessage("Cowardly refusing to part this channel, because I love it :3", channel); return; } if (message == Configuration.System.CommandPrefix + "drop") { if (channel.SystemUsers.IsApproved(user, host, "drop")) { while (!IRC.FinishedJoining) { Syslog.Log("Postponing request to part " + channel.Name + " because bot is still loading", true); Thread.Sleep(2000); } channel.PrimaryInstance.Network.Transfer("PART " + channel.Name + " :" + "dropped by " + user + " from " + origin); Syslog.Log("Dropped " + channel.Name + " dropped by " + user + " from " + origin); Thread.Sleep(100); try { File.Delete(Variables.ConfigurationDirectory + Path.DirectorySeparatorChar + channel.Name + ".xml"); } catch (Exception fail) { Syslog.ErrorLog("Failed to delete configuration file of " + channel.Name); Core.HandleException(fail); } foreach (Module module in ExtensionHandler.ExtensionList) { try { if (module.IsWorking) { module.Hook_ChannelDrop(channel); } } catch (Exception fail) { Syslog.Log("MODULE: exception at Hook_ChannelDrop in " + module.Name, true); Core.HandleException(fail, module.Name); } } lock (Configuration.Channels) { channel.Remove(); } Configuration.Save(); return; } IRC.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), origin); return; } if (message == Configuration.System.CommandPrefix + "part") { if (channel.SystemUsers.IsApproved(user, host, "part")) { while (!IRC.FinishedJoining) { Syslog.Log("Postponing request to part " + channel.Name + " because bot is still loading", true); Thread.Sleep(2000); } channel.PrimaryInstance.Network.Transfer("PART " + channel.Name + " :" + "removed by " + user + " from " + origin); Syslog.Log("Removed " + channel.Name + " removed by " + user + " from " + origin); Thread.Sleep(100); lock (Configuration.Channels) { channel.Remove(); } channel.SaveConfig(); Configuration.Save(); return; } IRC.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), origin); } } catch (Exception fail) { Core.HandleException(fail); } }
public override void Hook_PRIV(Channel channel, User invoker, string message) { if (!message.StartsWith(Configuration.System.CommandPrefix) && GetConfig(channel, "Slap.Enabled", false)) { string ms = message.Trim(); ms = ms.Replace("!", ""); ms = ms.Replace("?", ""); ms = ms.ToLower(); if (ms.StartsWith("hi ")) { ms = ms.Substring(3); } if (ms.StartsWith("hi, ")) { ms = ms.Substring(4); } if (ms.StartsWith("hello ")) { ms = ms.Substring(5); } if (ms.StartsWith("hello, ")) { ms = ms.Substring(6); } if (ms.EndsWith(":ping") || ms.EndsWith(": ping")) { string target = message.Trim(); target = message.Substring(0, message.IndexOf(":")); if (GetConfig(channel, "Slap.Ping." + target, false)) { channel.PrimaryInstance.irc.Queue.DeliverMessage("Hi " + invoker.Nick + ", you just managed to say pointless nick: ping. Now please try again with some proper meaning of your request, something like nick: I need this and that. Or don't do that at all, it's very annoying. Thank you", channel); return; } } if (ms == "i have a question" || ms == "can i ask a question" || ms == "can i ask" || ms == "i got a question" || ms == "can i have a question" || ms == "can someone help me" || ms == "i need help") { channel.PrimaryInstance.irc.Queue.DeliverMessage("Hi " + invoker.Nick + ", just ask! There is no need to ask if you can ask", channel); return; } if (ms == "is anyone here" || ms == "is anybody here" || ms == "is anybody there" || ms == "is some one there" || ms == "is someone there" || ms == "is someone here") { channel.PrimaryInstance.irc.Queue.DeliverMessage("Hi " + invoker.Nick + ", I am here, if you need anything, please ask, otherwise no one is going to help you... Thank you", channel); return; } } if (message == Configuration.System.CommandPrefix + "slap") { if (channel.SystemUsers.IsApproved(invoker, "admin")) { SetConfig(channel, "Slap.Enabled", true); Core.irc.Queue.DeliverMessage("I will be slapping stupid people since now", channel); channel.SaveConfig(); return; } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage("Permission denied", channel); } } if (message == Configuration.System.CommandPrefix + "noslap") { if (channel.SystemUsers.IsApproved(invoker, "admin")) { SetConfig(channel, "Slap.Enabled", false); Core.irc.Queue.DeliverMessage("I will not be slapping stupid people since now", channel); channel.SaveConfig(); return; } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage("Permission denied", channel); } } if (message == Configuration.System.CommandPrefix + "nopingslap") { if (channel.SystemUsers.IsApproved(invoker, "trust")) { SetConfig(channel, "Slap.Ping." + invoker.Nick.ToLower(), false); Core.irc.Queue.DeliverMessage("I will not be slapping people who slap you now", channel); channel.SaveConfig(); return; } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage("Permission denied", channel); } } if (message == Configuration.System.CommandPrefix + "pingslap") { if (channel.SystemUsers.IsApproved(invoker, "trust")) { SetConfig(channel, "Slap.Ping." + invoker.Nick.ToLower(), true); Core.irc.Queue.DeliverMessage("I will be slapping people who ping you now", channel); channel.SaveConfig(); return; } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage("Permission denied", channel); } } }
public override void Hook_PRIV(Channel channel, User invoker, string message) { ChanLog(message, channel, invoker.Nick, invoker.Host); if (message == Configuration.System.CommandPrefix + "logon") { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (Module.GetConfig(channel, "Logging.Enabled", false)) { Core.irc.Queue.DeliverMessage(messages.Localize("ChannelLogged", channel.Language), channel.Name); return; } else { Core.irc.Queue.DeliverMessage(messages.Localize("LoggingOn", channel.Language), channel.Name); Module.SetConfig(channel, "Logging.Enabled", true); channel.SaveConfig(); return; } } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } return; } if (message == Configuration.System.CommandPrefix + "logoff") { if (channel.SystemUsers.IsApproved(invoker.Nick, invoker.Host, "admin")) { if (!Module.GetConfig(channel, "Logging.Enabled", false)) { Core.irc.Queue.DeliverMessage(messages.Localize("LogsE1", channel.Language), channel.Name); return; } else { Module.SetConfig(channel, "Logging.Enabled", false); channel.SaveConfig(); Core.irc.Queue.DeliverMessage(messages.Localize("NotLogged", channel.Language), channel.Name); return; } } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } return; } }