Ejemplo n.º 1
0
        public static void HandleJoinCommand(AlarisMainParameter mp, string chan)
        {
            if (Rfc2812Util.IsValidChannelName(chan))
                mp.IrcConnection.Sender.Join(chan);

            return;
        }
Ejemplo n.º 2
0
 public static void HandleHelpCommand(AlarisMainParameter mp)
 {
     mp.IrcConnection.Sender.PublicMessage(mp.Channel,
                                               "{0}: info | quit | sys | join | title | calc | sort | admin",
                                               "Available commands");
     return;
 }
Ejemplo n.º 3
0
        public static void TestAddHandler(AlarisMainParameter mp, string a, string b)
        {
            var ar = Convert.ToInt32(a);
            var br = Convert.ToInt32(b);

            mp.IrcConnection.Sender.PublicMessage(mp.Channel, string.Format("Result: {0}", ar + br));
        }
Ejemplo n.º 4
0
        public static void HandleAesCommands(AlarisMainParameter mp, params string[] parameters)
        {
            var action = parameters[0];
            var sb = new StringBuilder();
            for(var i = 1; i < parameters.Length; ++i)
                sb.AppendFormat("{0} ", parameters[i]);

            var text = sb.ToString();
            if (action.IsNull() || text.IsNull())
                return;

            if (action.Equals("decrypt", StringComparison.InvariantCultureIgnoreCase))
            {
                mp.Bot.SendMsg(mp.Channel, Rijndael.DecryptString(text));
            }
            else if(action.Equals("encrypt", StringComparison.InvariantCultureIgnoreCase))
                HandleAesEncryptCommand(mp, text);
        }
Ejemplo n.º 5
0
        public static void HandleWACommand(AlarisMainParameter mp, params string[] parameters)
        {
            var expression = parameters.ConcatenateWithSpaces();
            expression = expression.Replace("=", " = "); // for equations

            var client = new WAClient("557QYQ-UUUWTKX95V");
            /*var result = client.GetResult(expression);

            var results = from pod in result.Pods
                          where pod.Title.ToLower().Contains("solution")
                                || pod.Title.ToLower().Contains("result")
                                || pod.Title.ToLower().Contains("derivative")
                          select pod;

            foreach (var rs in results.Select(pod => pod.SubPods[0].PlainText))
            {
                mp.Bot.SendMsg(mp.Channel, rs);
            }*/

            var result = client.Solve(expression);

            mp.Bot.SendMsg(mp.Channel, result);
        }
Ejemplo n.º 6
0
        public static void HandleCallCommand(AlarisMainParameter mp, params string[] parameters)
        {
            var methodName = parameters[0];

            var pars = new ArrayList();

            for(var i = 1; i < parameters.Length; ++i)
            {
                pars.Add(parameters[i]);
            }

            var atype = AlarisBase.Instance.GetType();

            var method = atype.GetMethods().FirstOrDefault(minfo => minfo.Name.Equals(methodName,
                StringComparison.InvariantCultureIgnoreCase)
                && minfo.GetParameters().Length == pars.Count);

            if(method == null)
            {
                Log.Info("Specified method {0} is not found inside AlarisBot matching parameter count {1}", methodName, pars.Count);
            }
            else
            {
                try
                {
                    var ret = method.Invoke(AlarisBase.Instance, pars.ToArray());

                    if(ret != null) // probably void
                        mp.IrcConnection.Sender.PublicMessage(mp.Channel, ret.ToString());
                }
                catch(Exception x)
                {
                    Log.ErrorException(string.Format("Exception thrown while calling the specified method ({0})", x.Message), x);
                }

                return;
            }

            Log.Debug("Searching for method in all available assemblies. (Parameter count is {0})", pars.Count);

            var asms = AlarisBase.Instance.AddonManager.Assemblies.ToList();
            asms.Add(AlarisBase.Instance.GetType().Assembly);
            asms.AddRange(from asm in AppDomain.CurrentDomain.GetAssemblies()
                              where asm.GetName().FullName.ToLower().Contains("alaris")
                              select asm);

            foreach (var type in asms.SelectMany(asm => asm.GetTypes()))
            {
                foreach(var mi in type.GetMethods(BindingFlags.Static | BindingFlags.InvokeMethod))
                {
                    if(mi.Name.Equals(methodName, StringComparison.InvariantCultureIgnoreCase) && mi.GetParameters().Length == pars.Count)
                    {
                        method = mi;
                        break;
                    }
                }
            }

            if(method != null)
            {
                try
                {
                    var ret = method.Invoke(null, pars.ToArray());

                    if (method.ReturnType == typeof(string))
                        mp.IrcConnection.Sender.PublicMessage(mp.Channel, ret as string);
                }
                catch (Exception x)
                {
                    Log.ErrorException(string.Format("Exception thrown while calling the specified method ({0})", x.Message), x);
                }

            }
        }
Ejemplo n.º 7
0
        public static void HandleListMethodsCommand(AlarisMainParameter mp)
        {
            var sb = new StringBuilder();

            foreach(var type in Assembly.GetExecutingAssembly().GetTypes())
            {
                foreach(var mi in type.GetMethods(BindingFlags.Public | BindingFlags.InvokeMethod))
                {
                    sb.AppendFormat("{0}.{1}({2})", type.Name, mi.Name, mi.GetParameters().Length);
                }
            }

            var fl = sb.ToString();

            if(!string.IsNullOrEmpty(fl))
                mp.IrcConnection.Sender.PublicMessage(mp.Channel, fl);
        }
Ejemplo n.º 8
0
        public static void HandleListAssembliesCommand(AlarisMainParameter mp)
        {
            var sb = new StringBuilder();

            foreach(var asm in AppDomain.CurrentDomain.GetAssemblies())
                sb.AppendFormat("{0} ", asm.GetName().Name);

            var fn = sb.ToString();

            mp.IrcConnection.Sender.PublicMessage(mp.Channel, fn);
        }
Ejemplo n.º 9
0
        public static void HandleSysCommand(AlarisMainParameter mp)
        {
            Utility.SendSysStats(mp.Channel);

            return;
        }
Ejemplo n.º 10
0
 public static void HandleQuitCommand(AlarisMainParameter mp)
 {
     mp.Bot.Disconnect("Quit command used by " + mp.User.Nick);
     return;
 }
Ejemplo n.º 11
0
 public static void HandleInfoCommand(AlarisMainParameter mp)
 {
     Utility.SendInfo(mp.Channel);
     return;
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Handles the command.
        /// </summary>
        /// <param name="user">The irc user</param>
        /// <param name="channel">IRC channel</param>
        /// <param name="message">IRC msg.</param>
        public void HandleCommand(UserInfo user, string channel, string message)
        {
            try
            {
                if (!message.StartsWith(CommandPrefix))
                    return;

                var commandText = message.Remove(0, 1); // remove prefix
                Log.Info("Checking for command: {0}", commandText);

                if(_commandMethodMap.Count <= 5)
                    foreach (var entry in _commandMethodMap)
                        Log.Info("Mapping contains command: {0}", entry.Key.Command);

                var wr = commandText.Split(' ');
                var command = wr[0];

                var parameters = new List<string>();

                for (var i = 1; i < wr.Length; ++i)
                {
                    parameters.Add(wr[i]);
                }

                var perm = CommandPermission.Normal;
                AlarisMethod handler = null;
                AlarisCommandWrapper cmd = null;

                foreach (var entry in _commandMethodMap.AsParallel().Where(entry => entry.Key.Command.Equals(command, StringComparison.InvariantCultureIgnoreCase)))
                {
                    perm = entry.Key.Permission;
                    handler = entry.Value;
                    cmd = entry.Key;
                }

                if (handler == null)
                    return;

                if (parameters.Count != 0 && !handler.IsParameterized)
                    return;

                if (perm == CommandPermission.Admin && !Utility.IsAdmin(user))
                    return;

                Log.Info("The handler {0} parameterized. It is about to be called with {1} params",
                         (handler.IsParameterized ? "is" : "is not"), parameters.Count);

                var mp = new AlarisMainParameter
                             {
                                 Channel = channel,
                                 Channels = AlarisBase.Instance.Channels,
                                 IrcConnection = AlarisBase.Instance.Connection,
                                 User = user

                             };

                var parl = new List<object>();

                if(handler.IsParameterized)
                {
                    parl.Add(mp);

                    if (!cmd.IsParameterCountUnspecified)
                    {
                        parl.AddRange(parameters);
                        var pdiff = handler.Method.GetParameters().Length - (parl.Count + 1);

                        if (pdiff > 0)
                        {
                            for (var i = 0; i <= pdiff; ++i)
                                parl.Add(null);
                        }
                    }

                }
                else
                    parl.Add(mp);

                /*object[] passParams = handler.IsParameterized
                                          ? new object[] {mp, parameters.ToArray()}
                                          : new object[] {mp};*/

                if(handler.IsParameterized && cmd.IsParameterCountUnspecified)
                {
                    var prms = new ArrayList {mp, parameters.ToArray()};
                    Log.Info("Invoking command handler method ({0}) ({1})", handler.Method.Name, prms.Count);
                    handler.Method.Invoke(null, prms.ToArray());
                    return;
                }

                Log.Info("Invoking command handler method ({0}) ({1})", handler.Method.Name, parl.Count);

                handler.Method.Invoke(null, parl.ToArray());

            }
            catch(Exception x)
            {
                Log.ErrorException(string.Format("Exception thrown during command recognition ({0})", x), x);
                return;
            }
        }
Ejemplo n.º 13
0
 public static void HandleListCmdsCommand(AlarisMainParameter mp)
 {
 }
Ejemplo n.º 14
0
 public static void HandleTestCommand(AlarisMainParameter mp)
 {
     mp.IrcConnection.Sender.PublicMessage(mp.Channel, "Test command called.");
 }
Ejemplo n.º 15
0
 public static void HandleAesEncryptCommand(AlarisMainParameter mp, string text)
 {
     mp.Bot.SendMsg(mp.Channel, Rijndael.EncryptString(text));
 }
Ejemplo n.º 16
0
 public static void HandleAddCommand(AlarisMainParameter mp, string a, string b)
 {
     mp.Bot.SendMsg(mp.Channel, (a.Cast<int>() + b.Cast<int>()).ToString());
 }