Exemplo n.º 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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
            public static void ProcessCommands(Channel chan, string nick, string ident, string host, string message)
            {
                if (!message.StartsWith(Configuration.System.CommandPrefix))
                {
                    return;
                }
                CommandParams p = new CommandParams();

                p.SourceChannel = chan;
                p.User          = new libirc.UserInfo(nick, ident, host);
                p.Message       = message;
                message         = message.Substring(1);
                p.Command       = message;
                if (message.Contains(" "))
                {
                    p.Parameters = message.Substring(message.IndexOf(" ") + 1);
                    p.Command    = message.Substring(0, message.IndexOf(" "));
                }

                GenericCommand command = CommandPool.GetCommand(p.Command);

                if (command != null)
                {
                    command.Launch(p);
                }
            }
Exemplo n.º 6
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);
            }
        }
Exemplo n.º 7
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);
 }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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;
 }
Exemplo n.º 10
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);
 }
Exemplo n.º 11
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();
 }
Exemplo n.º 12
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;
 }
Exemplo n.º 13
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;
        }
Exemplo n.º 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();
 }
Exemplo n.º 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);
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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);
        }
Exemplo n.º 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);
 }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 22
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);
            }
        }
Exemplo n.º 23
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);
        }
Exemplo n.º 24
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);
 }
Exemplo n.º 25
0
        private static void TrustAdd(CommandParams parameters)
        {
            if (parameters.Parameters == null)
            {
                return;
            }
            string[] rights_info = parameters.Parameters.Split(' ');
            if (rights_info.Length < 2)
            {
                IRC.DeliverMessage(messages.Localize("Trust1", parameters.SourceChannel.Language), parameters.SourceChannel);
                return;
            }
            if (!Security.Roles.ContainsKey(rights_info[1]))
            {
                IRC.DeliverMessage(messages.Localize("Unknown1", parameters.SourceChannel.Language), parameters.SourceChannel);
                return;
            }
            int level = Security.GetLevelOfRole(rights_info[1]);

            // This optional hack disallow to grant roles like "root" to anyone so that this role can be granted only to users
            // with shell access to server and hard-inserting it to admins file. If you wanted to allow granting of root, just
            // change System.MaxGrantableRoleLevel to 65535, this isn't very secure though
            if (level > Configuration.System.MaxGrantableRoleLevel)
            {
                IRC.DeliverMessage("You can't grant this role because it's over the maximum grantable role level, sorry", parameters.SourceChannel);
                return;
            }
            // now we check if role that user is to grant doesn't have higher level than the role they have
            // if we didn't do that, users with low roles could grant admin to someone and exploit this
            // to grant admins to themselves
            if (level > parameters.SourceChannel.SystemUsers.GetLevel(parameters.User))
            {
                IRC.DeliverMessage(messages.Localize("RoleMismatch", parameters.SourceChannel.Language), parameters.SourceChannel);
                return;
            }
            if (parameters.SourceChannel.SystemUsers.AddUser(rights_info[1], rights_info[0]))
            {
                IRC.DeliverMessage(messages.Localize("UserSc", parameters.SourceChannel.Language) + rights_info[0], parameters.SourceChannel);
                return;
            }
        }
Exemplo n.º 26
0
 private static void TrustAdd(CommandParams parameters)
 {
     if (parameters.Parameters == null)
         return;
     string[] rights_info = parameters.Parameters.Split(' ');
     if (rights_info.Length < 2)
     {
         IRC.DeliverMessage(messages.Localize("Trust1", parameters.SourceChannel.Language), parameters.SourceChannel);
         return;
     }
     if (!Security.Roles.ContainsKey(rights_info[1]))
     {
         IRC.DeliverMessage(messages.Localize("Unknown1", parameters.SourceChannel.Language), parameters.SourceChannel);
         return;
     }
     int level = Security.GetLevelOfRole(rights_info[1]);
     // This optional hack disallow to grant roles like "root" to anyone so that this role can be granted only to users
     // with shell access to server and hard-inserting it to admins file. If you wanted to allow granting of root, just
     // change System.MaxGrantableRoleLevel to 65535, this isn't very secure though
     if (level > Configuration.System.MaxGrantableRoleLevel)
     {
         IRC.DeliverMessage("You can't grant this role because it's over the maximum grantable role level, sorry", parameters.SourceChannel);
         return;
     }
     // now we check if role that user is to grant doesn't have higher level than the role they have
     // if we didn't do that, users with low roles could grant admin to someone and exploit this
     // to grant admins to themselves
     if (level > parameters.SourceChannel.SystemUsers.GetLevel(parameters.User))
     {
         IRC.DeliverMessage(messages.Localize("RoleMismatch", parameters.SourceChannel.Language), parameters.SourceChannel);
         return;
     }
     if (parameters.SourceChannel.SystemUsers.AddUser(rights_info[1], rights_info[0]))
     {
         IRC.DeliverMessage(messages.Localize("UserSc", parameters.SourceChannel.Language) + rights_info[0], parameters.SourceChannel);
         return;
     }
 }
Exemplo n.º 27
0
        private static void Part(CommandParams parameters)
        {
            if (string.IsNullOrEmpty(parameters.Parameters))
            {
                return;
            }
            string channel = parameters.Parameters.Trim();

            if (!string.IsNullOrEmpty(channel))
            {
                Channel _Channel = Core.GetChannel(channel);
                if (_Channel == null)
                {
                    IRC.DeliverMessage(messages.Localize("UnknownChan", parameters.SourceChannel.Language), parameters.SourceChannel,
                                       libirc.Defs.Priority.Low);
                    return;
                }
                PartChannel(_Channel, parameters.User.Nick, parameters.User.Host, Configuration.System.CommandPrefix
                            + "part", parameters.SourceChannel.Name);
                return;
            }
            IRC.DeliverMessage(messages.Localize("Responses-PartFail", parameters.SourceChannel.Language), parameters.SourceChannel,
                               libirc.Defs.Priority.Low);
        }
Exemplo n.º 28
0
        private static void SysRejoin(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))
            {
                if (!wmib.Instance.Instances[parameters.Parameters].ChannelsJoined)
                {
                    IRC.DeliverMessage("Instance " + parameters.Parameters + " is still joining channels", parameters.SourceChannel);
                    return;
                }
                wmib.Instance.Instances[parameters.Parameters].ChannelsJoined = false;
                wmib.Instance.Instances[parameters.Parameters].Join();
                IRC.DeliverMessage("Rejoining all channels on instance " + parameters.Parameters, parameters.SourceChannel);
            }
            else
            {
                IRC.DeliverMessage("Unknown bot: " + parameters.Parameters, parameters.SourceChannel);
            }
        }
Exemplo n.º 29
0
        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);
        }
Exemplo n.º 30
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();
 }
Exemplo n.º 31
0
 private static void TrafficOn(CommandParams parameters)
 {
     Configuration.Network.Logging = true;
     IRC.DeliverMessage("Logging started", parameters.SourceChannel);
 }
Exemplo n.º 32
0
        private static void Configure(CommandParams parameters)
        {
            if (string.IsNullOrEmpty(parameters.Parameters))
            {
                return;
            }

            if (parameters.Parameters.Contains("=") && !parameters.Parameters.EndsWith("="))
            {
                string name  = parameters.Parameters.Substring(0, parameters.Parameters.IndexOf("="));
                string value = parameters.Parameters.Substring(parameters.Parameters.IndexOf("=") + 1);
                bool   _temp_a;
                switch (name)
                {
                case "ignore-unknown":
                    if (bool.TryParse(value, out _temp_a))
                    {
                        parameters.SourceChannel.IgnoreUnknown = _temp_a;
                        IRC.DeliverMessage(messages.Localize("configuresave", parameters.SourceChannel.Language,
                                                             new List <string> {
                            value, name
                        }), parameters.SourceChannel);
                        parameters.SourceChannel.SaveConfig();
                        return;
                    }
                    IRC.DeliverMessage(messages.Localize("configure-va", parameters.SourceChannel.Language, new List <string> {
                        name, value
                    }), parameters.SourceChannel);
                    return;

                case "respond-wait":
                    int _temp_b;
                    if (int.TryParse(value, out _temp_b))
                    {
                        if (_temp_b > 1 && _temp_b < 364000)
                        {
                            parameters.SourceChannel.RespondWait = _temp_b;
                            IRC.DeliverMessage(messages.Localize("configuresave", parameters.SourceChannel.Language, new List <string> {
                                value, name
                            }), parameters.SourceChannel);
                            parameters.SourceChannel.SaveConfig();
                            return;
                        }
                    }
                    IRC.DeliverMessage(messages.Localize("configure-va", parameters.SourceChannel.Language, new List <string> {
                        name, value
                    }), parameters.SourceChannel);
                    return;

                case "respond-message":
                    if (bool.TryParse(value, out _temp_a))
                    {
                        parameters.SourceChannel.RespondMessage = _temp_a;
                        IRC.DeliverMessage(messages.Localize("configuresave", parameters.SourceChannel.Language, new List <string> {
                            value, name
                        }), parameters.SourceChannel);
                        parameters.SourceChannel.SaveConfig();
                        return;
                    }
                    IRC.DeliverMessage(messages.Localize("configure-va", parameters.SourceChannel.Language, new List <string> {
                        name, value
                    }), parameters.SourceChannel);
                    return;

                case "suppress-warnings":
                    if (bool.TryParse(value, out _temp_a))
                    {
                        parameters.SourceChannel.SuppressWarnings = _temp_a;
                        IRC.DeliverMessage(messages.Localize("configuresave", parameters.SourceChannel.Language, new List <string> {
                            value, name
                        }), parameters.SourceChannel);
                        parameters.SourceChannel.SaveConfig();
                        return;
                    }
                    IRC.DeliverMessage(messages.Localize("configure-va", parameters.SourceChannel.Language, new List <string> {
                        name, value
                    }), parameters.SourceChannel);
                    return;
                }
                bool exist = false;
                foreach (Module curr in ExtensionHandler.ExtensionList)
                {
                    try
                    {
                        if (curr.IsWorking && curr.Hook_SetConfig(parameters.SourceChannel, parameters.User, name, value))
                        {
                            exist = true;
                        }
                    }
                    catch (Exception fail)
                    {
                        Syslog.Log("Error on Hook_SetConfig module " + curr.Name);
                        Core.HandleException(fail, curr.Name);
                    }
                }
                if (!parameters.SourceChannel.SuppressWarnings && !exist)
                {
                    IRC.DeliverMessage(messages.Localize("configure-wrong", parameters.SourceChannel.Language), parameters.SourceChannel);
                }
                return;
            }
            if (!parameters.Parameters.Contains(" "))
            {
                switch (parameters.Parameters)
                {
                case "ignore-unknown":
                    IRC.DeliverMessage(messages.Localize("Responses-Conf", parameters.SourceChannel.Language, new List <string> {
                        parameters.Parameters, parameters.SourceChannel.IgnoreUnknown.ToString()
                    }), parameters.SourceChannel);
                    return;

                case "respond-message":
                    IRC.DeliverMessage(messages.Localize("Responses-Conf", parameters.SourceChannel.Language, new List <string> {
                        parameters.Parameters, parameters.SourceChannel.RespondMessage.ToString()
                    }), parameters.SourceChannel);
                    return;

                case "suppress-warnings":
                    IRC.DeliverMessage(messages.Localize("Responses-Conf", parameters.SourceChannel.Language, new List <string> {
                        parameters.Parameters, parameters.SourceChannel.SuppressWarnings.ToString()
                    }), parameters.SourceChannel);
                    return;
                }
                bool exist = false;
                foreach (Module curr in ExtensionHandler.ExtensionList)
                {
                    try
                    {
                        if (curr.IsWorking && curr.Hook_GetConfig(parameters.SourceChannel, parameters.User, parameters.Parameters))
                        {
                            exist = true;
                        }
                    }
                    catch (Exception fail)
                    {
                        Syslog.Log("Error on Hook_GetConfig module " + curr.Name);
                        Core.HandleException(fail);
                    }
                }
                if (exist)
                {
                    return;
                }
            }
            if (!parameters.SourceChannel.SuppressWarnings)
            {
                IRC.DeliverMessage(messages.Localize("configure-wrong", parameters.SourceChannel.Language), parameters.SourceChannel);
            }
        }
Exemplo n.º 33
0
 private static void Info(CommandParams parameters)
 {
     IRC.DeliverMessage(Configuration.WebPages.WebpageURL + Configuration.Paths.DumpDir
                         + "/" + HttpUtility.UrlEncode(parameters.SourceChannel.Name) + ".htm", parameters.SourceChannel);
 }
Exemplo n.º 34
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();
 }
Exemplo n.º 35
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);
        }
Exemplo n.º 36
0
        private static void Configure(CommandParams parameters)
        {
            if (string.IsNullOrEmpty(parameters.Parameters))
                return;

            if (parameters.Parameters.Contains("=") && !parameters.Parameters.EndsWith("="))
            {
                string name = parameters.Parameters.Substring(0, parameters.Parameters.IndexOf("="));
                string value = parameters.Parameters.Substring(parameters.Parameters.IndexOf("=") + 1);
                bool _temp_a;
                switch (name)
                {
                    case "ignore-unknown":
                        if (bool.TryParse(value, out _temp_a))
                        {
                            parameters.SourceChannel.IgnoreUnknown = _temp_a;
                            IRC.DeliverMessage(messages.Localize("configuresave", parameters.SourceChannel.Language,
                                                                       new List<string> { value, name }), parameters.SourceChannel);
                            parameters.SourceChannel.SaveConfig();
                            return;
                        }
                        IRC.DeliverMessage(messages.Localize("configure-va", parameters.SourceChannel.Language, new List<string> { name, value }), parameters.SourceChannel);
                        return;
                    case "respond-wait":
                        int _temp_b;
                        if (int.TryParse(value, out _temp_b))
                        {
                            if (_temp_b > 1 && _temp_b < 364000)
                            {
                                parameters.SourceChannel.RespondWait = _temp_b;
                                IRC.DeliverMessage(messages.Localize("configuresave", parameters.SourceChannel.Language, new List<string> { value, name }), parameters.SourceChannel);
                                parameters.SourceChannel.SaveConfig();
                                return;
                            }
                        }
                        IRC.DeliverMessage(messages.Localize("configure-va", parameters.SourceChannel.Language, new List<string> { name, value }), parameters.SourceChannel);
                        return;
                    case "respond-message":
                        if (bool.TryParse(value, out _temp_a))
                        {
                            parameters.SourceChannel.RespondMessage = _temp_a;
                            IRC.DeliverMessage(messages.Localize("configuresave", parameters.SourceChannel.Language, new List<string> { value, name }), parameters.SourceChannel);
                            parameters.SourceChannel.SaveConfig();
                            return;
                        }
                        IRC.DeliverMessage(messages.Localize("configure-va", parameters.SourceChannel.Language, new List<string> { name, value }), parameters.SourceChannel);
                        return;
                    case "suppress-warnings":
                        if (bool.TryParse(value, out _temp_a))
                        {
                            parameters.SourceChannel.SuppressWarnings = _temp_a;
                            IRC.DeliverMessage(messages.Localize("configuresave", parameters.SourceChannel.Language, new List<string> { value, name }), parameters.SourceChannel);
                            parameters.SourceChannel.SaveConfig();
                            return;
                        }
                        IRC.DeliverMessage(messages.Localize("configure-va", parameters.SourceChannel.Language, new List<string> { name, value }), parameters.SourceChannel);
                        return;
                }
                bool exist = false;
                foreach (Module curr in ExtensionHandler.ExtensionList)
                {
                    try
                    {
                        if (curr.IsWorking && curr.Hook_SetConfig(parameters.SourceChannel, parameters.User, name, value))
                            exist = true;
                    }
                    catch (Exception fail)
                    {
                        Syslog.Log("Error on Hook_SetConfig module " + curr.Name);
                        Core.HandleException(fail, curr.Name);
                    }
                }
                if (!parameters.SourceChannel.SuppressWarnings && !exist)
                    IRC.DeliverMessage(messages.Localize("configure-wrong", parameters.SourceChannel.Language), parameters.SourceChannel);
                return;
            }
            if (!parameters.Parameters.Contains(" "))
            {
                switch (parameters.Parameters)
                {
                    case "ignore-unknown":
                        IRC.DeliverMessage(messages.Localize("Responses-Conf", parameters.SourceChannel.Language, new List<string> { parameters.Parameters, parameters.SourceChannel.IgnoreUnknown.ToString() }), parameters.SourceChannel);
                        return;
                    case "respond-message":
                        IRC.DeliverMessage(messages.Localize("Responses-Conf", parameters.SourceChannel.Language, new List<string> { parameters.Parameters, parameters.SourceChannel.RespondMessage.ToString() }), parameters.SourceChannel);
                        return;
                    case "suppress-warnings":
                        IRC.DeliverMessage(messages.Localize("Responses-Conf", parameters.SourceChannel.Language, new List<string> { parameters.Parameters, parameters.SourceChannel.SuppressWarnings.ToString() }), parameters.SourceChannel);
                        return;
                }
                bool exist = false;
                foreach (Module curr in ExtensionHandler.ExtensionList)
                {
                    try
                    {
                        if (curr.IsWorking && curr.Hook_GetConfig(parameters.SourceChannel, parameters.User, parameters.Parameters))
                            exist = true;
                    }
                    catch (Exception fail)
                    {
                        Syslog.Log("Error on Hook_GetConfig module " + curr.Name);
                        Core.HandleException(fail);
                    }
                }
                if (exist)
                    return;
            }
            if (!parameters.SourceChannel.SuppressWarnings)
                IRC.DeliverMessage(messages.Localize("configure-wrong", parameters.SourceChannel.Language), parameters.SourceChannel);
        }
Exemplo n.º 37
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);
        }
Exemplo n.º 38
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);
 }
Exemplo n.º 39
0
 private static void Restart(CommandParams parameters)
 {
     IRC.DeliverMessage("System is shutting down, requested by " + parameters.User.Nick + " from " + parameters.SourceChannel.Name, Configuration.System.DebugChan, libirc.Defs.Priority.High);
     Syslog.Log("System is shutting down, requested by " + parameters.User.Nick + " from " + parameters.SourceChannel.Name);
     Core.Kill();
 }
Exemplo n.º 40
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);
     }
 }
Exemplo n.º 41
0
 private static void Part(CommandParams parameters)
 {
     if (string.IsNullOrEmpty(parameters.Parameters))
         return;
     string channel = parameters.Parameters.Trim();
     if (!string.IsNullOrEmpty(channel))
     {
         Channel _Channel = Core.GetChannel(channel);
         if (_Channel == null)
         {
             IRC.DeliverMessage(messages.Localize("UnknownChan", parameters.SourceChannel.Language), parameters.SourceChannel,
                                           libirc.Defs.Priority.Low);
             return;
         }
         PartChannel(_Channel, parameters.User.Nick, parameters.User.Host, Configuration.System.CommandPrefix
                          + "part", parameters.SourceChannel.Name);
         return;
     }
     IRC.DeliverMessage(messages.Localize("Responses-PartFail", parameters.SourceChannel.Language), parameters.SourceChannel,
                                   libirc.Defs.Priority.Low);
 }
Exemplo n.º 42
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);
 }
Exemplo n.º 43
0
 private static void TrustedList(CommandParams parameters)
 {
     IRC.DeliverMessage(messages.Localize("TrustedUserList", parameters.SourceChannel.Language) + parameters.SourceChannel.SystemUsers.ListAll(), parameters.SourceChannel);
 }
Exemplo n.º 44
0
 private static void VerbosityUp(CommandParams parameters)
 {
     Configuration.System.SelectedVerbosity++;
     IRC.DeliverMessage("Verbosity: " + Configuration.System.SelectedVerbosity,
                                       parameters.SourceChannel, libirc.Defs.Priority.High);
 }
Exemplo n.º 45
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);
 }
Exemplo n.º 46
0
 private static void Restart(CommandParams parameters)
 {
     IRC.DeliverMessage("System is shutting down, requested by " + parameters.User.Nick + " from " + parameters.SourceChannel.Name, Configuration.System.DebugChan, libirc.Defs.Priority.High);
     Syslog.Log("System is shutting down, requested by " + parameters.User.Nick + " from " + parameters.SourceChannel.Name);
     Core.Kill();
 }
Exemplo n.º 47
0
 private static void Info(CommandParams parameters)
 {
     IRC.DeliverMessage(Configuration.WebPages.WebpageURL + Configuration.Paths.DumpDir
                        + "/" + HttpUtility.UrlEncode(parameters.SourceChannel.Name) + ".htm", parameters.SourceChannel);
 }
Exemplo n.º 48
0
 private static void TrafficOn(CommandParams parameters)
 {
     Configuration.Network.Logging = true;
     IRC.DeliverMessage("Logging started", parameters.SourceChannel);
 }
Exemplo n.º 49
0
 /// <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;
 }
Exemplo n.º 50
0
        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);
        }
Exemplo n.º 51
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);
 }
Exemplo n.º 52
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);
 }
Exemplo n.º 53
0
        private static void Restrict(CommandParams parameters)
        {
            if (string.IsNullOrEmpty(parameters.Parameters))
            {
                IRC.DeliverMessage("Please specify restrict action", parameters.SourceChannel);
                return;
            }

            List <string> pm = new List <string>(parameters.Parameters.Trim().Split(' '));

            switch (pm[0])
            {
            case "add":
                if (pm.Count == 1)
                {
                    IRC.DeliverMessage("This command requires channel name to be specified", parameters.SourceChannel.Name);
                    break;
                }

                string channel_name = 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;
                }
                if (Configuration.RestrictedChannels.ContainsKey(channel_name))
                {
                    IRC.DeliverMessage("Channel " + channel_name + " is already restricted to join", parameters.SourceChannel.Name);
                    return;
                }

                int restriction_level = Security.Roles["root"].Level;
                if (pm.Count >= 3)
                {
                    if (Security.Roles.ContainsKey(pm[2]))
                    {
                        restriction_level = Security.Roles[pm[2]].Level;
                    }
                    else
                    {
                        IRC.DeliverMessage("Unknown user role: " + pm[2], parameters.SourceChannel.Name);
                        return;
                    }
                }

                foreach (KeyValuePair <string, Instance> instance in wmib.Instance.Instances)
                {
                    foreach (Channel channel in instance.Value.ChannelList)
                    {
                        if (channel.Name == channel_name)
                        {
                            instance.Value.Network.Transfer("PART " + channel_name);
                            break;
                        }
                    }
                }
                lock (Configuration.Channels)
                {
                    Configuration.Channels.RemoveAll(c => c.Name == channel_name);
                }
                lock (Configuration.RestrictedChannels)
                {
                    Configuration.RestrictedChannels[channel_name] = restriction_level;
                }
                Configuration.Save();

                IRC.DeliverMessage("I will not join " + channel_name + " anymore", parameters.SourceChannel.Name);
                break;

            default:
                IRC.DeliverMessage("Unknown restrict action: " + pm[0], parameters.SourceChannel.Name);
                break;
            }
        }
Exemplo n.º 54
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;
 }