DeliverMessage() public static method

Send a message to a given target
public static DeliverMessage ( string text, Channel target, libirc priority = libirc.Defs.Priority.Normal ) : void
text string Text of a message
target Channel Channel
priority libirc Priority
return void
Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
 private static void ChannelList(CommandParams parameters)
 {
     IRC.DeliverMessage(messages.Localize("Responses-List", parameters.SourceChannel.Language, new List <string> {
         Configuration.Channels.Count.ToString()
     }),
                        parameters.SourceChannel);
 }
Example #4
0
 /// <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;
 }
Example #5
0
 /// <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());
     }
 }
Example #6
0
 public override void Hook_PRIV(Channel channel, libirc.UserInfo invoker, string message)
 {
     if (message == "@replag")
     {
         IRC.DeliverMessage("Replication lag is approximately " + GetReplag(), channel);
     }
 }
Example #7
0
        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);
            }
        }
Example #8
0
 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);
     }
 }
Example #9
0
 private static void Reload(CommandParams parameters)
 {
     parameters.SourceChannel.LoadConfig();
     SystemHooks.IrcReloadChannelConf(parameters.SourceChannel);
     IRC.DeliverMessage(messages.Localize("Config", parameters.SourceChannel.Language), parameters.SourceChannel);
     return;
 }
Example #10
0
        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);
            }
        }
Example #11
0
 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);
 }
Example #12
0
 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);
 }
Example #13
0
 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();
 }
Example #14
0
 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();
 }
Example #15
0
        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);
        }
Example #16
0
        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;
        }
Example #17
0
 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);
     }
 }
Example #18
0
        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);
        }
Example #19
0
 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);
 }
Example #20
0
        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);
        }
Example #21
0
        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);
        }
Example #22
0
        /// <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);
        }
Example #23
0
        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);
        }
Example #24
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);
            }
        }
Example #25
0
 /// <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());
     }
 }
Example #26
0
        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);
            }
        }
Example #27
0
        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);
        }
Example #28
0
 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);
 }
Example #29
0
 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);
 }
Example #30
0
 /// <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);
 }