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 ? System.Web.HttpUtility.HtmlEncode(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); }
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/mpddj.ini"; } cfgpath = System.IO.Path.GetFullPath(cfgpath); Console.WriteLine("Trying to read from " + cfgpath); Configuration.ReadConfig(cfgpath); Console.WriteLine("Connecting to MPD"); MPCClient = new MPC(Configuration.Config ["mpc"] ["host"], Configuration.Config ["mpc"] ["port"]); MPCClient.Status(); 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); } if (method.GetCustomAttribute <BotFallback>() != null) { if (fallback != null) { Console.WriteLine("WARN: You have more than one fallback command set, overwriting previous"); } fallback = method; } } }