package io.github.likcoras.asuka.handler;

import org.pircbotx.PircBotX;
import org.pircbotx.hooks.Event;
import org.pircbotx.hooks.events.ConnectEvent;
import org.pircbotx.hooks.types.GenericMessageEvent;
import io.github.likcoras.asuka.AsukaBot;
import io.github.likcoras.asuka.BotConfig;
import io.github.likcoras.asuka.BotUtil;
import io.github.likcoras.asuka.exception.HandlerException;
import io.github.likcoras.asuka.handler.response.BotResponse;
import io.github.likcoras.asuka.handler.response.EmptyResponse;
import io.github.likcoras.asuka.handler.response.UptimeResponse;

public class UptimeHandler implements Handler {

	private long upSince;

	@Override
	public void configure(BotConfig config) {
	}

	@Override
	public BotResponse handle(AsukaBot bot, Event<PircBotX> event) throws HandlerException {
		if (event instanceof ConnectEvent)
			upSince = event.getTimestamp();
		else if (event instanceof GenericMessageEvent) {
			@SuppressWarnings("unchecked")
			GenericMessageEvent<PircBotX> messageEvent = (GenericMessageEvent<PircBotX>) event;
			if (BotUtil.isTrigger(messageEvent.getMessage(), "uptime"))
				return new UptimeResponse(messageEvent, upSince);
		}
		return EmptyResponse.get();
	}

}

@@ -92,16 +92,30 @@
 x.hooks.
+events.Connect
 Event;%0Ai
@@ -138,39 +138,39 @@
 tx.hooks.events.
-Connect
+Message
 Event;%0Aimport or
@@ -190,21 +190,22 @@
 oks.
-types.Generic
+events.Private
 Mess
@@ -295,115 +295,12 @@
 .Bot
-Config;%0Aimport io.github.likcoras.asuka.BotUtil;%0Aimport io.github.likcoras.asuka.exception.HandlerException
+Util
 ;%0Aim
@@ -520,19 +520,27 @@
 ler 
-implement
+extend
 s 
+Translating
 Hand
@@ -593,46 +593,367 @@
 lic 
-void configure(BotConfig config) %7B
+BotResponse onConnect(AsukaBot bot, ConnectEvent%3CPircBotX%3E event) %7B%0A%09%09upSince = event.getTimestamp();%0A%09%09return EmptyResponse.get();%0A%09%7D%0A%09%0A%09@Override%0A%09public BotResponse onMessage(AsukaBot bot, MessageEvent%3CPircBotX%3E event) %7B%0A%09%09if (BotUtil.isTrigger(event.getMessage(), %22uptime%22))%0A%09%09%09return new UptimeResponse(event, upSince);%0A%09%09return EmptyResponse.get();
 %0A%09%7D%0A
+%09
 %0A%09@O
@@ -984,291 +984,46 @@
 nse 
-handle(AsukaBot bot, Event%3CPircBotX%3E event) throws HandlerException %7B%0A%09%09if (event instanceof ConnectEvent)%0A%09%09%09upSince = event.getTimestamp();%0A%09%09else if (event instanceof GenericMessageEvent) %7B%0A%09%09%09@SuppressWarnings(%22unchecked%22)%0A%09%09%09GenericMessageEvent%3CPircBotX%3E messageEvent = (Generic
+onPrivateMessage(AsukaBot bot, Private
 Mess
@@ -1044,18 +1044,18 @@
 otX%3E
-)
  event
-;%0A%09
+) %7B%0A
 %09%09if
@@ -1074,24 +1074,17 @@
 Trigger(
-messageE
+e
 vent.get
@@ -1108,17 +1108,16 @@
 e%22))%0A%09%09%09
-%09
 return n
@@ -1138,16 +1138,9 @@
 nse(
-messageE
+e
 vent
@@ -1155,12 +1155,8 @@
 e);%0A
-%09%09%7D%0A
 %09%09re

Use a TranslatingHandler instead of a normal handler for UptimeHandler