/*
 * Copyright 2016 LINE Corporation
 *
 * LINE Corporation licenses this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package com.example.bot.spring;

import java.util.Timer;
import java.util.TimerTask;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.stereotype.Component;
import java.lang.Override;
import com.heroku.sdk.jdbc.DatabaseUrl;
import java.util.concurrent.ExecutionException;
import java.util.Collections;
import java.net.URISyntaxException;
import java.net.URI;
import java.sql.*;
import javax.sql.*;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.linecorp.bot.client.LineMessagingClient;
import com.linecorp.bot.client.MessageContentResponse;
import com.linecorp.bot.model.ReplyMessage;
import com.linecorp.bot.model.Multicast;
import com.linecorp.bot.model.PushMessage;
import com.linecorp.bot.model.action.MessageAction;
import com.linecorp.bot.model.action.PostbackAction;
import com.linecorp.bot.model.action.URIAction;
import com.linecorp.bot.model.event.BeaconEvent;
import com.linecorp.bot.model.event.Event;
import com.linecorp.bot.model.event.FollowEvent;
import com.linecorp.bot.model.event.JoinEvent;
import com.linecorp.bot.model.event.MessageEvent;
import com.linecorp.bot.model.event.PostbackEvent;
import com.linecorp.bot.model.event.UnfollowEvent;
import com.linecorp.bot.model.event.message.AudioMessageContent;
import com.linecorp.bot.model.event.message.ImageMessageContent;
import com.linecorp.bot.model.event.message.LocationMessageContent;
import com.linecorp.bot.model.event.message.StickerMessageContent;
import com.linecorp.bot.model.event.message.TextMessageContent;
import com.linecorp.bot.model.event.message.VideoMessageContent;
import com.linecorp.bot.model.event.source.GroupSource;
import com.linecorp.bot.model.event.source.RoomSource;
import com.linecorp.bot.model.event.source.Source;
import com.linecorp.bot.model.message.AudioMessage;
import com.linecorp.bot.model.message.ImageMessage;
import com.linecorp.bot.model.message.ImagemapMessage;
import com.linecorp.bot.model.message.LocationMessage;
import com.linecorp.bot.model.message.Message;
import com.linecorp.bot.model.message.StickerMessage;
import com.linecorp.bot.model.message.TemplateMessage;
import com.linecorp.bot.model.message.TextMessage;
import com.linecorp.bot.model.message.VideoMessage;
import com.linecorp.bot.model.message.imagemap.ImagemapArea;
import com.linecorp.bot.model.message.imagemap.ImagemapBaseSize;
import com.linecorp.bot.model.message.imagemap.MessageImagemapAction;
import com.linecorp.bot.model.message.imagemap.URIImagemapAction;
import com.linecorp.bot.model.message.template.ButtonsTemplate;
import com.linecorp.bot.model.message.template.CarouselColumn;
import com.linecorp.bot.model.message.template.CarouselTemplate;
import com.linecorp.bot.model.message.template.ConfirmTemplate;
import com.linecorp.bot.model.profile.UserProfileResponse;
import com.linecorp.bot.model.response.BotApiResponse;
import com.linecorp.bot.spring.boot.annotation.EventMapping;
import com.linecorp.bot.spring.boot.annotation.LineMessageHandler;

import lombok.NonNull;
import lombok.Value;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@LineMessageHandler
public class Runtime extends TimerTask
{    
	@Autowired
    private LineMessagingClient lineMessagingClient;

    private void push(@NonNull String To, @NonNull Message message) {
        push(To, Collections.singletonList(message));
    }

    private void push(@NonNull String To, @NonNull List<Message> messages) {
        try {
            BotApiResponse apiResponse = lineMessagingClient
                    .pushMessage(new PushMessage(To, messages))
                    .get();
            log.info("Sent messages: {}", apiResponse);
        } catch (InterruptedException | ExecutionException e) {
            throw new RuntimeException(e);
        }
    }

    private void pushText(@NonNull String To, @NonNull String message) {
        if (To.isEmpty()) {
            throw new IllegalArgumentException("replyToken must not be empty");
        }
        if (message.length() > 1000) {
            message = message.substring(0, 1000 - 2);
        }
        this.push(To, new TextMessage(message));
    }

	@Override
	public void run() {
		try{
				Connection connection = KitchenSinkController.getConnection();
	        	Statement stmt = connection.createStatement();
	        	ResultSet rs = stmt.executeQuery("SELECT Condition,GroupId FROM 'ticks' WHERE 'ticks'.tick <= now() + INTERVAL '6 HOUR 57 MINUTES'");
	        	while (rs.next()) {   	 
	        		if (rs.getInt("Condition")==0){
	        			Runtime.pushText(rs.getString("GroupId"),"Permainan Dimulai");
	        			stmt.executeUpdate("UPDATE 'ticks' SET Condition = 1 , tick = now() + INTERVAL '7 HOUR'"
	    	        			+ "WHERE 'ticks'.tick <= now() + INTERVAL '6 HOUR 57 MINUTES' AND 'ticks'.GroupId = "+rs.getString("GroupId"));
	        		}
	        	}
	        	rs.close();
	        	stmt.close();
	        	connection.close();
			}catch(SQLException e){
				e.getMessage();
			}catch(URISyntaxException err){
				err.getMessage();
		}
	}
}
 	   					
	   				
  

@@ -1117,86 +1117,8 @@
 rl;%0A
-import java.util.concurrent.ExecutionException;%0Aimport java.util.Collections;%0A
 impo
@@ -1213,3733 +1213,48 @@
 .*;%0A
-import java.util.List;%0Aimport org.springframework.beans.factory.annotation.Autowired;%0Aimport com.linecorp.bot.client.LineMessagingClient;%0Aimport com.linecorp.bot.client.MessageContentResponse;%0Aimport com.linecorp.bot.model.ReplyMessage;%0Aimport com.linecorp.bot.model.Multicast;%0Aimport com.linecorp.bot.model.PushMessage;%0Aimport com.linecorp.bot.model.action.MessageAction;%0Aimport com.linecorp.bot.model.action.PostbackAction;%0Aimport com.linecorp.bot.model.action.URIAction;%0Aimport com.linecorp.bot.model.event.BeaconEvent;%0Aimport com.linecorp.bot.model.event.Event;%0Aimport com.linecorp.bot.model.event.FollowEvent;%0Aimport com.linecorp.bot.model.event.JoinEvent;%0Aimport com.linecorp.bot.model.event.MessageEvent;%0Aimport com.linecorp.bot.model.event.PostbackEvent;%0Aimport com.linecorp.bot.model.event.UnfollowEvent;%0Aimport com.linecorp.bot.model.event.message.AudioMessageContent;%0Aimport com.linecorp.bot.model.event.message.ImageMessageContent;%0Aimport com.linecorp.bot.model.event.message.LocationMessageContent;%0Aimport com.linecorp.bot.model.event.message.StickerMessageContent;%0Aimport com.linecorp.bot.model.event.message.TextMessageContent;%0Aimport com.linecorp.bot.model.event.message.VideoMessageContent;%0Aimport com.linecorp.bot.model.event.source.GroupSource;%0Aimport com.linecorp.bot.model.event.source.RoomSource;%0Aimport com.linecorp.bot.model.event.source.Source;%0Aimport com.linecorp.bot.model.message.AudioMessage;%0Aimport com.linecorp.bot.model.message.ImageMessage;%0Aimport com.linecorp.bot.model.message.ImagemapMessage;%0Aimport com.linecorp.bot.model.message.LocationMessage;%0Aimport com.linecorp.bot.model.message.Message;%0Aimport com.linecorp.bot.model.message.StickerMessage;%0Aimport com.linecorp.bot.model.message.TemplateMessage;%0Aimport com.linecorp.bot.model.message.TextMessage;%0Aimport com.linecorp.bot.model.message.VideoMessage;%0Aimport com.linecorp.bot.model.message.imagemap.ImagemapArea;%0Aimport com.linecorp.bot.model.message.imagemap.ImagemapBaseSize;%0Aimport com.linecorp.bot.model.message.imagemap.MessageImagemapAction;%0Aimport com.linecorp.bot.model.message.imagemap.URIImagemapAction;%0Aimport com.linecorp.bot.model.message.template.ButtonsTemplate;%0Aimport com.linecorp.bot.model.message.template.CarouselColumn;%0Aimport com.linecorp.bot.model.message.template.CarouselTemplate;%0Aimport com.linecorp.bot.model.message.template.ConfirmTemplate;%0Aimport com.linecorp.bot.model.profile.UserProfileResponse;%0Aimport com.linecorp.bot.model.response.BotApiResponse;%0Aimport com.linecorp.bot.spring.boot.annotation.EventMapping;%0Aimport com.linecorp.bot.spring.boot.annotation.LineMessageHandler;%0A%0Aimport lombok.NonNull;%0Aimport lombok.Value;%0Aimport lombok.extern.slf4j.Slf4j;%0A%0A@Slf4j%0A@LineMessageHandler%0Apublic class Runtime extends TimerTask%0A%7B    %0A%09@Autowired%0A    private LineMessagingClient lineMessagingClient;%0A%0A    private void push(@NonNull String To, @NonNull Message message) %7B%0A        push(To, Collections.singletonList(message));%0A    %7D%0A%0A    private void push(@NonNull String To, @NonNull List%3CMessage%3E messages) %7B%0A        try %7B%0A            BotApiResponse apiResponse = lineMessagingClient%0A                    .pushMessage(new PushMessage(To, messages))%0A                    .get();%0A            log.info(%22Sent messages: %7B%7D%22, apiResponse);%0A        %7D catch (InterruptedException %7C ExecutionException e) %7B%0A            throw new RuntimeException(e);%0A        %7D%0A    %7D%0A%0A    private void pushText(@NonNull String To, @NonNull String message) %7B%0A        if (To.isEmpty()) %7B%0A            throw new IllegalArgumentException(%22replyToken must not be empty%22);%0A        %7D%0A        if (message.length() %3E 1000) %7B%0A            message = message.substring(0, 1000 - 2);%0A        %7D%0A        this.push(To, new TextMessage(message));%0A    %7D%0A
+public class Runtime extends TimerTask%0A%7B
 %0A%09@O
@@ -1352,24 +1352,29 @@
 nnection();%0A
+%09%09%09%09%0A
 %09        %09St
@@ -1652,23 +1652,37 @@
      %09%09%09
-Runtime
+KitchenSinkController
 .pushTex

Add Existing files