Exemplo n.º 1
0
        public int Run()
        {
            var cmdparser = new CommandParser();

            cmdparser.Add <int, int>("!add {0}+{1}", (a, b) => Console.WriteLine("a + b = {0}", a + b));

            cmdparser.Exec("!add 2+4");

            return(0);
        }
Exemplo n.º 2
0
        private void InitCommands()
        {
            m_cmdparser.Exceptions += CommandParserExceptions;

            m_cmdparser.Add("!help", () => Send(string.Join("\n", m_cmdparser.Commands)));

            m_cmdparser.Add("!ping", () => Send("pong!"));

            m_cmdparser.Add("!users", () => Send("Current users: " + Users.AsString()));

            m_cmdparser.Add <uint>("!keepalive {0}m", m => {
                KeepAliveTimeout = TimeSpan.FromMinutes(m);
                Send(string.Format("Keep alive timeout for this channel is {0} minute(s)", m));
            });

            m_cmdparser.Add <uint>("!keepalive {0}h", h => {
                KeepAliveTimeout = TimeSpan.FromHours(h);
                Send(string.Format("Keep alive timeout for this channel is {0} hour(s)", h));
            });

            m_cmdparser.Add <string, uint>("!invite {0} {0}m", (user, keepalive) =>
            {
                var connection = Connection.Invite(user, Name, Password, TimeSpan.FromMinutes(keepalive));
                if (connection != null)
                {
                    Send(user + " invited (<a href=\"/view-channel/" + connection.Token + "\">copy this link</a>)");
                }
            });

            m_cmdparser.Add <string, uint>("!invite {0} {0}h", (user, keepalive) =>
            {
                var connection = Connection.Invite(user, Name, Password, TimeSpan.FromHours(keepalive));
                if (connection != null)
                {
                    Send(user + " invited (<a href=\"/view-channel/" + connection.Token + "\">copy this link</a>)");
                }
            });

            m_cmdparser.Add <bool>("!invite-only {0}", enabled =>
            {
                InviteOnly = enabled;
                Send("Invite only mode " + (enabled ? "enabled" : "disabled"));
            });

            m_cmdparser.Add("!bots", () =>
            {
                Send("Bots available: " + m_botmgr.Available);
                Send("Bots enabled: " + m_botmgr.Current);
            });

            m_cmdparser.Add <string>("!add-bot {0}", bot =>
            {
                var newbot = m_botmgr.Add(bot);
                if (newbot != null)
                {
                    newbot.UserData = User.BotUser(bot);
                    Send("Bot added");
                }
            });

            m_cmdparser.Add <string>("!remove-bot {0}", bot =>
            {
                if (m_botmgr.Remove(bot))
                {
                    Send("Bot removed");
                }
            });

            m_cmdparser.Add <string, string, string>("!bot {0} {1}:{2}", (bot, arg, value) =>
            {
                Bot tmp_bot = m_botmgr.Get(bot);
                if (tmp_bot != null)
                {
                    tmp_bot[arg] = value;
                    Send("Done");
                }
            });

            m_cmdparser.Add <string, string>("!bot {0} {1}?", (bot, arg) =>
            {
                Bot tmp_bot = m_botmgr.Get(bot);
                if (tmp_bot != null)
                {
                    Send(tmp_bot[arg]);
                }
            });
        }