diff --git a/sample_botsettings.json b/sample_botsettings.json index 2b27001..fd3dfcc 100644 --- a/sample_botsettings.json +++ b/sample_botsettings.json @@ -1,9 +1,8 @@ { - "tguser": "Telegram user name", "matrixuser": "Matrix user name", "tgtoken": "Token key given from BotFather", "matrixpswd": "Matrix user password", - "matrixhomeserver": "Matrix home server url", + "matrixhomeserver": "https://homeserver.com/_matrix/client/r0", "rooms": [{ "tgname": "Name of the room in Telegram", diff --git a/src/com/em/miguelbridge/matrixbot/MatrixBot.java b/src/com/em/miguelbridge/matrixbot/MatrixBot.java index ba0144d..00aff9c 100644 --- a/src/com/em/miguelbridge/matrixbot/MatrixBot.java +++ b/src/com/em/miguelbridge/matrixbot/MatrixBot.java @@ -27,8 +27,8 @@ public class MatrixBot { this.accessToken = accessToken; } - public MatrixBot() { - homeUrl = "https://maxwell.ydns.eu/_matrix/client/r0"; + public MatrixBot() throws IOException, FileNotFoundException, ParseException { + homeUrl = getHomeServer(); } public static String readBotUserName() throws FileNotFoundException, IOException, ParseException { @@ -55,6 +55,18 @@ public class MatrixBot { return pswd; } + public String getHomeServer() throws FileNotFoundException, IOException, ParseException { + FileReader file = new FileReader(Launcher.fileSettings); + BufferedReader in = new BufferedReader(file); + + JSONObject obj = (JSONObject) new JSONParser().parse(in); + in.close(); + + String server = (String) obj.get("matrixhomeserver"); + + return server; + } + /** * * @return Access Token per il bot, da utilizzare nelle prossime richieste HTTP