aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-06-07 19:01:40 +0300
committerGravatar Vitaly Takmazov2016-06-07 19:01:40 +0300
commit904a06d013f999e98724b222e6a4b48f68ddf32f (patch)
tree57cb5e67c80b9e28152f7171b56862228617a9fb /src/main/java
parentf2d66113d764f81d58905256a0f74e4f2ebd19f0 (diff)
fix indentation and update telegram library
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/juick/api/TelegramBotHook.java18
1 files changed, 12 insertions, 6 deletions
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) {