diff options
author | 2016-06-07 19:01:40 +0300 | |
---|---|---|
committer | 2016-06-07 19:01:40 +0300 | |
commit | 904a06d013f999e98724b222e6a4b48f68ddf32f (patch) | |
tree | 57cb5e67c80b9e28152f7171b56862228617a9fb | |
parent | f2d66113d764f81d58905256a0f74e4f2ebd19f0 (diff) |
fix indentation and update telegram library
-rw-r--r-- | build.gradle | 2 | ||||
-rw-r--r-- | src/main/java/com/juick/api/TelegramBotHook.java | 18 |
2 files changed, 13 insertions, 7 deletions
diff --git a/build.gradle b/build.gradle index d11187c4..0d69481d 100644 --- a/build.gradle +++ b/build.gradle @@ -53,7 +53,7 @@ dependencies { compile "org.springframework:spring-jdbc:4.2.6.RELEASE" providedCompile 'javax.servlet:javax.servlet-api:3.1.0' compile 'javax.inject:javax.inject:1' - compile 'com.github.pengrad:java-telegram-bot-api:2.0.1' + compile 'com.github.pengrad:java-telegram-bot-api:2.1.1' compile 'com.neovisionaries:nv-websocket-client:1.27' runtime 'mysql:mysql-connector-java:5.1.39' testCompile 'junit:junit:4.12' diff --git a/src/main/java/com/juick/api/TelegramBotHook.java b/src/main/java/com/juick/api/TelegramBotHook.java index ccfa2c11..2e1ac20c 100644 --- a/src/main/java/com/juick/api/TelegramBotHook.java +++ b/src/main/java/com/juick/api/TelegramBotHook.java @@ -42,7 +42,7 @@ public class TelegramBotHook { public TelegramBotHook(JdbcTemplate jdbc, String token) { this.jdbc = jdbc; - bot = TelegramBotAdapter.build(token); + bot = TelegramBotAdapter.build(token); bot.setWebhook("https://api.juick.com/tlgmbtwbhk"); try { ws = new WebSocketFactory().createSocket("wss://ws.juick.com/_all"); @@ -59,6 +59,7 @@ public class TelegramBotHook { public void onConnected(WebSocket websocket, Map<String, List<String>> headers) { logger.info("ws connected"); } + @Override public void onTextMessage(WebSocket websocket, String text) throws Exception { super.onTextMessage(websocket, text); @@ -120,7 +121,7 @@ public class TelegramBotHook { private void telegramNotify(Long c, String msg, String msgUrl) { bot.execute(new SendMessage(c, msg).replyMarkup( new InlineKeyboardMarkup( - new InlineKeyboardButton[] { + new InlineKeyboardButton[]{ new InlineKeyboardButton("See on Juick").url(msgUrl) } )), new Callback<SendMessage, SendResponse>() { @@ -139,6 +140,7 @@ public class TelegramBotHook { List<Long> getChats() { return jdbc.queryForList("SELECT chat_id FROM telegram_chats", Long.class); } + void addChat(Long id) { jdbc.update("INSERT IGNORE INTO telegram_chats(chat_id) VALUES(?)", id); } @@ -149,10 +151,10 @@ public class TelegramBotHook { User user_from = UserQueries.getUserByUID(jdbc, getUser(message.chat().id())).orElse(new User()); logger.info(String.format("got telegram msg %s from juick user %d", message.toString(), user_from.getUID())); List<Long> chats = getChats(); - String username = message.from().username(); - if (username == null) { - username = message.from().firstName(); - } + String username = message.from().username(); + if (username == null) { + username = message.from().firstName(); + } if (!chats.contains(message.chat().id())) { addChat(message.chat().id()); logger.info("added chat with " + username); @@ -196,6 +198,7 @@ public class TelegramBotHook { return jdbc.update("INSERT INTO telegram(tg_id, tg_name, loginhash) VALUES(?,?,?)", tgID, tgName, UUID.randomUUID().toString()) > 0; } + private int getUser(long tgId) { try { return jdbc.queryForObject("SELECT id FROM users INNER JOIN telegram " + @@ -204,14 +207,17 @@ public class TelegramBotHook { return 0; } } + private List<Long> getSubscribers(int uid) { return jdbc.queryForList("SELECT tg_id FROM telegram INNER JOIN subscr_users " + "ON (subscr_users.user_id=? AND telegram.user_id=subscr_users.suser_id)", Long.class, uid); } + private List<Long> getSubscribersToComments(int mid, int ignore_uid) { return jdbc.queryForList("SELECT tg_id FROM telegram INNER JOIN subscr_messages " + "ON (telegram.user_id=subscr_messages.suser_id) WHERE message_id=? AND suser_id!=?", Long.class, mid, ignore_uid); } + private String getReplyQuote(int MID, int ReplyTo) { String quote = ""; if (ReplyTo > 0) { |