public static DeliverMessage ( string text, |
||
text | string | Text of a message |
target | Channel | |
priority | libirc | Priority |
return | void |
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); }
private static void TrustDel(CommandParams parameters) { Channel channel = parameters.SourceChannel; string[] rights_info = parameters.Parameters.Split(' '); if (rights_info[0] == null) { IRC.DeliverMessage(messages.Localize("InvalidUser", parameters.SourceChannel.Language), parameters.SourceChannel); return; } if (rights_info.Length > 1) { if (channel.SystemUsers.IsApproved(parameters.User, "root")) { channel = Core.GetChannel(rights_info[1]); if (channel == null) { IRC.DeliverMessage("I don't know this channel: " + rights_info[1], parameters.SourceChannel); return; } } else { IRC.DeliverMessage("Sorry, only root users can manage permissions for other channels.", parameters.SourceChannel); return; } } channel.SystemUsers.DeleteUser(parameters.SourceChannel.SystemUsers.GetUser(parameters.User), rights_info[0], parameters.SourceChannel); }
private static void ChannelList(CommandParams parameters) { IRC.DeliverMessage(messages.Localize("Responses-List", parameters.SourceChannel.Language, new List <string> { Configuration.Channels.Count.ToString() }), parameters.SourceChannel); }
/// <summary> /// Delete user /// </summary> /// <param name="origin"></param> /// <param name="user">Regex</param> /// <returns></returns> public void DeleteUser(SystemUser origin, string user) { foreach (SystemUser u in Users) { if (u.Name == user) { if (GetLevelOfRole(u.Role) > GetLevelOfRole(origin.Role)) { // users with role that has lower level than role of user who is to be removed aren't allowed to do that // eg. trusted can't delete admin from channel IRC.DeliverMessage(messages.Localize("RoleMismatch", this._Channel.Language), this._Channel); return; } if (u.Name == origin.Name) { // users aren't permitted to delete themselve IRC.DeliverMessage(messages.Localize("Trust2", this._Channel.Language), this._Channel); return; } Users.Remove(u); Save(); IRC.DeliverMessage(messages.Localize("Trust3", this._Channel.Language), this._Channel); return; } } IRC.DeliverMessage(messages.Localize("Trust4", this._Channel.Language), this._Channel); return; }
/// <summary> /// Exception handler /// </summary> /// <param name="ex">Exception pointer</param> public static void HandleException(Exception ex) { try { if (!string.IsNullOrEmpty(Configuration.System.DebugChan)) { IRC.DeliverMessage("DEBUG Exception: " + ex.Message + " st: " + ex.StackTrace.Replace(Environment.NewLine, ""), Configuration.System.DebugChan); } if (ex.InnerException != null) { Syslog.ErrorLog("DEBUG Exception: " + ex.Message + ex.Source + ex.StackTrace + "\n\nThread name: " + Thread.CurrentThread.Name + "\n\nInner: " + ex.InnerException); } else { Syslog.ErrorLog("DEBUG Exception: " + ex.Message + ex.Source + ex.StackTrace + "\n\nThread name: " + Thread.CurrentThread.Name); } } catch (Exception fail) { // exception happened while we tried to handle another one, ignore that (probably issue with logging) Console.WriteLine(fail.ToString()); } }
public override void Hook_PRIV(Channel channel, libirc.UserInfo invoker, string message) { if (message == "@replag") { IRC.DeliverMessage("Replication lag is approximately " + GetReplag(), channel); } }
private static void CommandList(CommandParams parameters) { string commands = ""; List <string> list = new List <string>(CommandPool.CommandsList.Keys); list.Sort(); foreach (string command in list) { commands += command; commands += ", "; } if (commands.EndsWith(", ", System.StringComparison.InvariantCulture)) { commands = commands.Substring(0, commands.Length - 2); } if (parameters.SourceChannel != null) { int max_possible_length = IRC.GetMaxMessageLength(parameters.SourceChannel); // "I know: " max_possible_length -= 8; if (commands.Length > max_possible_length) { commands = commands.Substring(0, max_possible_length - 3) + "..."; } IRC.DeliverMessage("I know: " + commands, parameters.SourceChannel); } else if (parameters.SourceUser != null) { IRC.DeliverMessage("I know: " + commands, parameters.SourceUser); } }
public virtual void Launch(CommandParams parameter) { try { if (this.channelOnly && parameter.SourceChannel == null) { return; } if (this.RequiredPermission != null) { if (parameter.SourceChannel != null) { if (!parameter.SourceChannel.SystemUsers.IsApproved(parameter.User, requiredPermission)) { if (!parameter.SourceChannel.SuppressWarnings && !SilentErrors) { IRC.DeliverMessage(messages.Localize("PermissionDenied", parameter.SourceChannel.Language), parameter.SourceChannel); } // user doesn't have permission to run this command return; } } else if (!Security.IsGloballyApproved(parameter.User, RequiredPermission)) { IRC.DeliverMessage(messages.Localize("PermissionDenied"), parameter.User, libirc.Defs.Priority.Low); } } this.action(parameter); } catch (Exception fail) { Core.HandleException(fail); } }
private static void Reload(CommandParams parameters) { parameters.SourceChannel.LoadConfig(); SystemHooks.IrcReloadChannelConf(parameters.SourceChannel); IRC.DeliverMessage(messages.Localize("Config", parameters.SourceChannel.Language), parameters.SourceChannel); return; }
private static void CommandList(CommandParams parameters) { string commands = ""; List <string> list = new List <string>(CommandPool.CommandsList.Keys); list.Sort(); foreach (string command in list) { commands += command; commands += ", "; } if (commands.EndsWith(", ")) { commands = commands.Substring(0, commands.Length - 2); } if (parameters.SourceChannel != null) { IRC.DeliverMessage("I know: " + commands, parameters.SourceChannel); } else if (parameters.SourceUser != null) { IRC.DeliverMessage("I know: " + commands, parameters.SourceUser); } }
protected override void __evt_JOINERROR(libirc.Network.NetworkJoinErrorEventArgs args) { if (!string.IsNullOrEmpty(Configuration.System.DebugChan)) { IRC.DeliverMessage("Join error: " + args.Message + " channel: " + args.ParameterLine + " reason: " + args.Error.ToString(), Configuration.System.DebugChan); } base.__evt_JOINERROR(args); }
private static void VerbosityDown(CommandParams parameters) { if (Configuration.System.SelectedVerbosity > 0) { Configuration.System.SelectedVerbosity--; } IRC.DeliverMessage("Verbosity: " + Configuration.System.SelectedVerbosity, parameters.SourceChannel, libirc.Defs.Priority.High); }
private static void SuppressOn(CommandParams parameters) { if (parameters.SourceChannel.Suppress) { //Message("Channel had already quiet mode disabled", chan.name); return; } IRC.DeliverMessage(messages.Localize("SilenceBegin", parameters.SourceChannel.Language), parameters.SourceChannel); parameters.SourceChannel.Suppress = true; parameters.SourceChannel.SaveConfig(); }
private static void SuppressOff(CommandParams parameters) { if (!parameters.SourceChannel.Suppress) { IRC.DeliverMessage(messages.Localize("Silence1", parameters.SourceChannel.Language), parameters.SourceChannel); return; } parameters.SourceChannel.Suppress = false; IRC.DeliverMessage(messages.Localize("Silence2", parameters.SourceChannel.Language), parameters.SourceChannel); parameters.SourceChannel.SaveConfig(); Configuration.Save(); }
private static void ChangePass(CommandParams parameters) { if (string.IsNullOrEmpty(parameters.Parameters)) { IRC.DeliverMessage("You need to provide exactly 1 parameter", parameters.SourceChannel); return; } parameters.SourceChannel.Password = parameters.Parameters.Trim(); parameters.SourceChannel.SaveConfig(); IRC.DeliverMessage("Password updated", parameters.SourceChannel); }
private static void TrustDel(CommandParams parameters) { if (string.IsNullOrEmpty(parameters.Parameters)) { IRC.DeliverMessage(messages.Localize("InvalidUser", parameters.SourceChannel.Language), parameters.SourceChannel); return; } string rights_info = parameters.Parameters.Trim(); parameters.SourceChannel.SystemUsers.DeleteUser(parameters.SourceChannel.SystemUsers.GetUser(parameters.User), rights_info); return; }
private void linkie_on(CommandParams p) { if (!GetConfig(p.SourceChannel, "Link.Enable", false)) { SetConfig(p.SourceChannel, "Link.Enable", true); p.SourceChannel.SaveConfig(); IRC.DeliverMessage(messages.Localize("Linkie-On", p.SourceChannel.Language), p.SourceChannel); } else { IRC.DeliverMessage(messages.Localize("Linkie-On2", p.SourceChannel.Language), p.SourceChannel); } }
private static void Whoami(CommandParams parameters) { SystemUser current = parameters.SourceChannel.SystemUsers.GetUser(parameters.User); if (current.Role == "null") { IRC.DeliverMessage(messages.Localize("Unknown", parameters.SourceChannel.Language), parameters.SourceChannel); return; } IRC.DeliverMessage(messages.Localize("usr1", parameters.SourceChannel.Language, new List <string> { current.Role, current.Name }), parameters.SourceChannel); }
private static void Help(CommandParams parameters) { if (!String.IsNullOrEmpty(parameters.Parameters)) { Core.ShowHelp(parameters.Parameters, parameters.SourceChannel); 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", parameters.SourceChannel); }
private static void TrustedList(CommandParams parameters) { Channel channel = parameters.SourceChannel; if (!String.IsNullOrEmpty(parameters.Parameters)) { channel = Core.GetChannel(parameters.Parameters.Trim()); if (channel == null) { IRC.DeliverMessage("I don't know this channel: " + parameters.Parameters, parameters.SourceChannel); return; } } IRC.DeliverMessage(messages.Localize("TrustedUserList", parameters.SourceChannel.Language) + channel.SystemUsers.ListAll(), parameters.SourceChannel); }
private static void Ignore(CommandParams parameters) { if (string.IsNullOrEmpty(parameters.Parameters)) { IRC.DeliverMessage("You need to provide exactly 1 parameter", parameters.SourceChannel); return; } string hostmask = parameters.Parameters.Trim(); Configuration.IgnoredHostmasks.Add(hostmask); Configuration.Save(); IRC.DeliverMessage("I will ignore all commands of user with hostmask " + hostmask, parameters.SourceChannel.Name); }
/// <summary> /// Called when someone post a message to server /// </summary> /// <param name="channel">Channel</param> /// <param name="nick">Nick</param> /// <param name="host">Host</param> /// <param name="message">Message</param> /// <returns></returns> public static bool GetMessage(string channel, string nick, string host, string message) { LastText = nick + " chan: " + channel + " " + message; Channel channel_ = GetChannel(channel); if (channel_ != null) { if (!channel_.IgnoreUnknown || channel_.SystemUsers.IsKnown(nick, host)) { if (message.StartsWith(Configuration.System.CommandPrefix)) { Commands.PartChannel(channel_, nick, host, message); } Commands.Processing.ProcessCommands(channel_, nick, "", host, message); } foreach (Module _Module in ExtensionHandler.ExtensionList) { try { if (_Module.IsWorking) { _Module.Hook_PRIV(channel_, new libirc.UserInfo(nick, "", host), message); } } catch (Exception f) { Syslog.Log("MODULE: exception at Hook_PRIV in " + _Module.Name, true); HandleException(f); } } if (channel_.RespondMessage) { if (message.StartsWith(Configuration.IRC.NickName + ":")) { DateTime time = channel_.TimeOfLastMsg; if (DateTime.Now >= time.AddSeconds(channel_.RespondWait)) { IRC.DeliverMessage(messages.Localize("hi", channel_.Language, new List <string> { nick }), channel_.Name); channel_.TimeOfLastMsg = DateTime.Now; } } } } return(false); }
private static Boolean displayWaiting(Boolean reportNoUsersWaiting) { ArrayList shellRequests = getWaitingUsernames("Shell Access Requests", "Shell Request User Name"); ArrayList toolsRequests = getWaitingUsernames("Tools Access Requests", "Tools Request User Name"); if (shellRequests.Count != 0 || reportNoUsersWaiting) { IRC.DeliverMessage(formatReportLine(shellRequests, "shell access"), RequestChannel); } if (toolsRequests.Count != 0 || reportNoUsersWaiting) { IRC.DeliverMessage(formatReportLine(toolsRequests, "Tools access"), RequestChannel); } return(shellRequests.Count != 0 || toolsRequests.Count != 0); }
public override void Hook_PRIV(Channel channel, libirc.UserInfo invoker, string message) { 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 ", System.StringComparison.InvariantCulture)) { 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); } }
/// <summary> /// Exception handler /// </summary> /// <param name="ex">Exception pointer</param> /// <param name="module">Channel name</param> public static void HandleException(Exception ex, string module) { try { if (!string.IsNullOrEmpty(Configuration.System.DebugChan)) { IRC.DeliverMessage("DEBUG Exception in module " + module + ": " + ex.Message + " st: " + ex.StackTrace.Replace(Environment.NewLine, ""), Configuration.System.DebugChan); } Syslog.Log("DEBUG Exception in module " + module + ": " + ex.Message + ex.Source + ex.StackTrace, true); } catch (Exception fail) { // exception happened while we tried to handle another one, ignore that (probably issue with logging) Console.WriteLine(fail.ToString()); } }
private static void Reauth(CommandParams parameters) { if (string.IsNullOrEmpty(parameters.Parameters)) { IRC.DeliverMessage("You need to provide exactly 1 parameter", parameters.SourceChannel); return; } if (wmib.Instance.Instances.ContainsKey(parameters.Parameters)) { wmib.Instance.Instances[parameters.Parameters].Protocol.Authenticate(false); } else { IRC.DeliverMessage("Unknown bot: " + parameters.Parameters, parameters.SourceChannel); } }
private static void SystemUnload(CommandParams parameters) { if (string.IsNullOrEmpty(parameters.Parameters)) { IRC.DeliverMessage("You need to provide at least 1 parameters", parameters.SourceChannel); return; } string module = parameters.Parameters; Module _m = ExtensionHandler.RetrieveModule(module); if (_m == null) { IRC.DeliverMessage("This module is not currently loaded in core", parameters.SourceChannel, libirc.Defs.Priority.High); return; } _m.Exit(); IRC.DeliverMessage("Unloaded module " + module, parameters.SourceChannel, libirc.Defs.Priority.High); }
private static void Language(CommandParams parameters) { if (!String.IsNullOrEmpty(parameters.Parameters)) { if (messages.Exists(parameters.Parameters)) { parameters.SourceChannel.Language = parameters.Parameters; IRC.DeliverMessage(messages.Localize("Language", parameters.SourceChannel.Language), parameters.SourceChannel); parameters.SourceChannel.SaveConfig(); return; } if (!parameters.SourceChannel.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("InvalidCode", parameters.SourceChannel.Language), parameters.SourceChannel); } return; } IRC.DeliverMessage(messages.Localize("LanguageInfo", parameters.SourceChannel.Language), parameters.SourceChannel); }
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> /// Add /// </summary> /// <param name="level">Level</param> /// <param name="user">Regex</param> /// <returns></returns> public bool AddUser(string level, string user) { if (!misc.IsValidRegex(user)) { Syslog.Log("Unable to create user " + user + " because the regex is invalid", true); IRC.DeliverMessage("Unable to add user because this regex is not valid", this._Channel); return(false); } foreach (SystemUser u in Users) { if (u.Name == user) { IRC.DeliverMessage("Unable to add user because this user is already in a list", this._Channel); return(false); } } Users.Add(new SystemUser(level, user)); Save(); return(true); }