package com.techcavern.wavetact.ircCommands.misc;

import com.techcavern.wavetact.annot.IRCCMD;
import com.techcavern.wavetact.objects.IRCCommand;
import com.techcavern.wavetact.utils.GeneralUtils;
import com.techcavern.wavetact.utils.IRCUtils;
import com.techcavern.wavetact.utils.Registry;
import org.pircbotx.Channel;
import org.pircbotx.PircBotX;
import org.pircbotx.User;
import org.pircbotx.hooks.ListenerAdapter;
import org.pircbotx.hooks.events.PrivateMessageEvent;
import org.pircbotx.hooks.events.WhoisEvent;

import java.util.HashMap;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

//@IRCCMD
public class Test extends IRCCommand {

    public Test() {
        super(GeneralUtils.toArray("test timer project"), 0, "test", "moooo", false);
    }
    @Override
    public void onCommand(String command, User user, PircBotX network, String prefix, Channel channel, boolean isPrivate, int userPermLevel, String... args) throws Exception {
        class CrackbotListener extends ListenerAdapter {
            @Override
            public void onPrivateMessage(PrivateMessageEvent event) throws Exception {
                if (event.getUser().getNick().equalsIgnoreCase("Crackbot")) {
                    IRCUtils.sendMessage(user, network, channel, "./start", prefix);
                }
            }
        }
        TimerTask buy = new TimerTask() {
            public void run() {
                TimerTask sellall = new TimerTask() {
                    public void run() {
                        IRCUtils.sendMessage(user, network, channel, "./sellall <<buy company 10>>", prefix);
                        Registry.messageQueue.get(network).add("PRIVMSG ##powder-moo :./bc24");
                        IRCUtils.sendMessage(user, network, channel, "./buy company 10", prefix);
                    }
                };
                Registry.messageQueue.get(network).add("PRIVMSG ##powder-moo :./bc24");
                IRCUtils.sendMessage(user, network, channel, "./buy company 10", prefix);
                Timer timer2 = new Timer();
                timer2.schedule(sellall, 40000);
            }
        };
        TimerTask use = new TimerTask() {
            public void run() {
                IRCUtils.sendMessage(user, network, channel, "./use cow", prefix);
                IRCUtils.sendMessage(user, network, channel, "./use company", prefix);
            }
        };
        TimerTask givejz = new TimerTask() {
            public void run() {
                IRCUtils.sendMessage(user, network, channel, "./give Ginvera <<calc $cash-800000000>>", prefix);
            }
        };
        Timer timer1 = new Timer();
        if (command.equalsIgnoreCase("project")) {
            network.getConfiguration().getListenerManager().addListener(new CrackbotListener());
            IRCUtils.sendMessage(user, network, channel, "./start", prefix);
        } else if (command.equalsIgnoreCase("timer")) {
            timer1.scheduleAtFixedRate(buy, 0, 80000);
            timer1.scheduleAtFixedRate(use, 0, 4000);
            timer1.scheduleAtFixedRate(givejz, 0, 800000);
        } else if (command.equalsIgnoreCase("stoptimer")) {
            timer1.purge();
        }
    }
}

@@ -618,10 +618,8 @@
 k;%0A%0A
-//
 @IRC
@@ -1641,77 +1641,69 @@
     
-Registry.messageQueue.get(network).add(%22PRIVMSG ##powder-moo :./bc24%22
+IRCUtils.sendMessage(user, network, channel, %22./bc24%22, prefix
 );%0A 
@@ -1860,77 +1860,69 @@
     
-Registry.messageQueue.get(network).add(%22PRIVMSG ##powder-moo :./bc24%22
+IRCUtils.sendMessage(user, network, channel, %22./bc24%22, prefix
 );%0A 
@@ -2547,15 +2547,14 @@
 ive 
-Ginvera
+WTTest
  %3C%3Cc

Fix Giant Derp