コード例 #1
0
ファイル: Commands.cs プロジェクト: Half-Shot/matrix-card-bot
        public static void Help(string cmd, string sender, MatrixRoom room)
        {
            string helptext = "";

            foreach (MethodInfo method in typeof(Commands).GetMethods(BindingFlags.Static | BindingFlags.Public))
            {
                BotCmd  c = method.GetCustomAttribute <BotCmd> ();
                BotHelp h = method.GetCustomAttribute <BotHelp> ();
                if (c != null)
                {
                    helptext += String.Format("<p><strong>{0}</strong> {1}</p>", c.CMD, h != null ? h.HelpText : "");
                }
            }
            MMessageCustomHTML htmlmsg = new MMessageCustomHTML();

            htmlmsg.body           = helptext.Replace("<strong>", "").Replace("</strong>", "").Replace("<p>", "").Replace("</p>", "\n");
            htmlmsg.formatted_body = helptext;
            room.SendMessage(htmlmsg);
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Reading INI File");
            string cfgpath;

            if (args.Length > 1)
            {
                cfgpath = args [1];
            }
            else
            {
                cfgpath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "/.config/cardbot.ini";
            }
            cfgpath = System.IO.Path.GetFullPath(cfgpath);
            Console.WriteLine("Trying to read from " + cfgpath);
            Configuration.ReadConfig(cfgpath);

            Console.WriteLine("Connecting to Matrix");
            Client = new MatrixClient(Configuration.Config ["matrix"] ["host"]);

            Console.WriteLine("Connected. Logging in");
            Client.LoginWithPassword(Configuration.Config ["matrix"] ["user"], Configuration.Config ["matrix"] ["pass"]);
            Console.WriteLine("Logged in OK");
            Console.WriteLine("Joining Rooms:");
            foreach (string roomid in Configuration.Config["matrix"] ["rooms"].Split(','))
            {
                MatrixRoom room = Client.GetRoomByAlias(roomid);
                if (room == null)
                {
                    room = Client.JoinRoom(roomid);
                    if (room != null)
                    {
                        Console.WriteLine("\tJoined " + roomid);
                        room.OnMessage += Room_OnMessage;
                    }
                    else
                    {
                        Console.WriteLine("\tCouldn't find " + roomid);
                    }
                }
                else
                {
                    room.OnMessage += Room_OnMessage;
                }
            }
            Console.WriteLine("Done!");
            //Find commands
            foreach (MethodInfo method in typeof(Commands).GetMethods(BindingFlags.Static | BindingFlags.Public))
            {
                BotCmd cmd = method.GetCustomAttribute <BotCmd> ();
                if (cmd != null)
                {
                    Cmds.Add(cmd, method);
                }
            }

            LobbyManager            = new LobbyManager(Client);
            Console.CancelKeyPress += (object sender, ConsoleCancelEventArgs e) => {
                LobbyManager.Dispose();
                Client.Dispose();
            };
        }