From 904a06d013f999e98724b222e6a4b48f68ddf32f Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 7 Jun 2016 19:01:40 +0300 Subject: fix indentation and update telegram library --- src/main/java/com/juick/api/TelegramBotHook.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/main/java/com/juick') 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> 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() { @@ -139,6 +140,7 @@ public class TelegramBotHook { List 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 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 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 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) { -- cgit v1.2.3