package com.avairebot.orion.commands.system;

import com.avairebot.orion.Orion;
import com.avairebot.orion.contracts.commands.SystemCommand;
import net.dv8tion.jda.core.entities.Game;
import net.dv8tion.jda.core.entities.Message;

import java.util.Arrays;
import java.util.List;

public class SetStatusCommand extends SystemCommand {

    public SetStatusCommand(Orion orion) {
        super(orion);
    }

    @Override
    public String getName() {
        return "Set Status Command";
    }

    @Override
    public String getDescription() {
        return "Sets the status of the bot instance for all servers the bot is on, if no status is set the bot status will go back to cycling status from the config.";
    }

    @Override
    public List<String> getUsageInstructions() {
        return Arrays.asList(
            "`:command <game>` - Sets the bots playing status to the given game.",
            "`:command <twitch url>` - The URL that the bot should be broadcasting."
        );
    }

    @Override
    public String getExampleUsage() {
        return "`:command with some stuff`";
    }

    @Override
    public List<String> getTriggers() {
        return Arrays.asList("setstatus", "status");
    }

    @Override
    public boolean onCommand(Message message, String[] args) {
        if (args.length == 0) {
            return false;
        }

        if (!Game.isValidStreamingUrl(args[0])) {
            message.getJDA().getPresence().setGame(Game.of(String.join(" ", args)));
            return true;
        }

        String url = args[0];
        String status = String.join(" ", args).substring(url.length());

        if (args.length == 1) {
            status = "Streaming on Twitch.tv";
        }

        message.getJDA().getPresence().setGame(Game.of(status, url));
        return true;
    }
}

@@ -134,16 +134,69 @@
 ommand;%0A
+import com.avairebot.orion.factories.MessageFactory;%0A
 import n
@@ -1422,54 +1422,37 @@
     
-if (!Game.isValidStreamingUrl(args%5B0%5D)) %7B%0A    
+Game game = parseGame(args);%0A
     
@@ -1498,78 +1498,697 @@
 ame(
-Game.of(String.join(%22 %22, args)));%0A            return true;%0A        %7D%0A%0A
+game);%0A%0A        MessageFactory.makeSuccess(message, %22Changed status to **:type :status**%22)%0A            .set(%22type%22, getTypeAsString(game.getType()))%0A            .set(%22status%22, game.getName())%0A            .queue();%0A%0A        return true;%0A    %7D%0A%0A    private String getTypeAsString(Game.GameType type) %7B%0A        switch (type) %7B%0A            case STREAMING:%0A                return %22Streaming%22;%0A%0A            case WATCHING:%0A                return %22Watching%22;%0A%0A            case LISTENING:%0A                return %22Listening to%22;%0A%0A            default:%0A                return %22Playing%22;%0A        %7D%0A    %7D%0A%0A    private Game parseGame(String%5B%5D args) %7B%0A        if (Game.isValidStreamingUrl(args%5B0%5D)) %7B%0A    
     
@@ -2217,24 +2217,28 @@
 0%5D;%0A        
+    
 String statu
@@ -2230,24 +2230,30 @@
    String st
+reamSt
 atus = Strin
@@ -2296,32 +2296,36 @@
 th());%0A%0A        
+    
 if (args.length 
@@ -2344,17 +2344,27 @@
         
-s
+    streamS
 tatus = 
@@ -2389,32 +2389,36 @@
 ch.tv%22;%0A        
+    
 %7D%0A%0A        messa
@@ -2416,89 +2416,879 @@
     
-message.getJDA().getPresence().setGame(Game.of(status, url));%0A        return true
+    return Game.streaming(streamStatus, url);%0A        %7D%0A%0A        String status = String.join(%22 %22, args);%0A%0A        if (status.contains(%22:%22)) %7B%0A            String%5B%5D split = status.split(%22:%22);%0A            status = String.join(%22:%22, Arrays.copyOfRange(split, 1, split.length));%0A            switch (split%5B0%5D.toLowerCase()) %7B%0A                case %22listen%22:%0A                case %22listening%22:%0A                    return Game.listening(status);%0A%0A                case %22watch%22:%0A                case %22watching%22:%0A                    return Game.watching(status);%0A%0A                case %22play%22:%0A                case %22playing%22:%0A                    return Game.playing(status);%0A%0A                case %22stream%22:%0A                case %22streaming%22:%0A                    return Game.streaming(status, %22https://www.twitch.tv/senither%22);%0A            %7D%0A        %7D%0A%0A        return Game.playing(status)
 ;%0A  

Add support for more status types in set status command