Пример #1
0
        static void Main(string[] args)
        {
            string       homeserverUrl = "https://matrix.org";
            MatrixClient client;

            if (File.Exists("/tmp/mx_access"))
            {
                string[] tokens = File.ReadAllText("/tmp/mx_access.txt").Split("$");
                client = new MatrixClient(homeserverUrl);
                client.UseExistingToken(tokens[1], tokens[0]);
            }
            else
            {
                string username = "******";
                string password = "******";
                client = new MatrixClient(homeserverUrl);
                MatrixLoginResponse login = client.LoginWithPassword(username, password);
                File.WriteAllText("/tmp/mx_access.txt", $"{login.access_token}${login.user_id}");
            }
            Console.WriteLine("Starting sync");
            client.StartSync();
            Console.WriteLine("Finished initial sync");
            foreach (var room in client.GetAllRooms())
            {
                Console.WriteLine($"Found room: {room.ID}");
            }
        }
Пример #2
0
        private static void Main(string[] args)
        {
            var homeserverUrl = new Uri("http://localhost:8008");

            MatrixClient client;

            if (File.Exists("/tmp/mx_access"))
            {
                var tokens = File.ReadAllText("/tmp/mx_access").Split("$");
                client = new MatrixClient(homeserverUrl);
                client.UseExistingToken(tokens[1], tokens[0]);
            }
            else
            {
                var username = "******";
                var password = "******";
                client = new MatrixClient(homeserverUrl);
                var login = client.LoginWithPassword(username, password);
                File.WriteAllText("/tmp/mx_access", $"{login.AccessToken}${login.UserId}");
            }

            Console.WriteLine("Starting sync");
            client.StartSync();
            Console.WriteLine("Finished initial sync");
            foreach (var room in client.GetAllRooms())
            {
                Console.WriteLine($"Found room: {room.Id}");
            }
        }
Пример #3
0
        public static void Main(string[] args)
        {
            MatrixClient client = new MatrixClient("");

            client.LoginWithPassword("", "");
            MatrixUser user = client.GetUser("");
        }
Пример #4
0
        private RoomsViewModel GetUserRooms(User user)
        {
            string       homeserverUrl = "https://matrix.org";
            MatrixClient client;
            string       username = user.Username;
            string       password = user.Password;

            client = new MatrixClient(homeserverUrl);
            MatrixLoginResponse login = client.LoginWithPassword(username, password);


            client.StartSync();
            RoomsViewModel rmv = new RoomsViewModel();

            rmv.rooms = client.GetAllRooms();


            return(rmv);
        }
Пример #5
0
        protected void onLogin(object sender, EventArgs e)
        {
            Console.WriteLine("Trying to login to the matrix server...");
            var client = new MatrixClient(this.serverEntry.Text);

            try{
                client.LoginWithPassword(this.usernameEntry.Text, this.passwordEntry.Text);
                var user = client.GetUser();
                Console.WriteLine("Login success");
                var storage = new Storage();
                storage.Server   = this.serverEntry.Text;
                storage.Username = this.usernameEntry.Text;
                storage.UserId   = user.UserID;
                storage.Token    = client.GetAccessToken();
                storage.Save();
            }catch (Exception loginException) {
                Console.WriteLine(loginException.Message);
            }
        }
Пример #6
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/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;
                }
            }
        }
Пример #7
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();
            };
        }
Пример #8
0
        public MatrixBot(
            string cmdprefix,
            string host,
            string user,
            string pass,
            string[] rooms,
            bool AutoAcceptInvite = false,
            StatusOptions statusOptions = null
            )
        {
            prefix = cmdprefix;
            Client = new MatrixClient (host);
            Client.AddStateEventType ("uk.half-shot.status", typeof(HSStatusEvent));

            this.AutoAcceptInvite = AutoAcceptInvite;

            Client.OnInvite += (roomid, joined) => {
                if (AutoAcceptInvite) {
                    MatrixRoom room = Client.JoinRoom (roomid);
                    if (room != null) {
                        room.OnMessage += Room_OnMessage;
                    }

                }
            };

            Client.LoginWithPassword (user, pass);

            MatrixRoom[] existingRooms = Client.GetAllRooms ();
            foreach (string roomid in rooms) {
                MatrixRoom room = roomid.StartsWith ("#") ? Client.GetRoomByAlias (roomid) : Client.GetRoom (roomid);
                if (existingRooms.Contains (room)) {
                    continue;
                }
                if (room == null) {
                    room = Client.JoinRoom (roomid);
                    if (room != null) {
                        Console.WriteLine ("\tJoined " + roomid);
                    } else {
                        Console.WriteLine ("\tCouldn't find " + roomid);
                    }
                }
            }

            existingRooms = Client.GetAllRooms ();
            foreach (MatrixRoom room in existingRooms) {
                room.OnMessage += Room_OnMessage;
            }

            //Find commands
            foreach (MethodInfo method in typeof(T).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;
                }
            }

            if (statusOptions != null && statusOptions.StartAutomatically) {
                //Start Status Thread.
                statusOpts = statusOptions;
                StartStatusReporting(statusOptions.IntervalMinutes);

            }
        }