package stream.flarebot.flarebot.commands.general;

import com.arsenarsen.lavaplayerbridge.player.Player;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.Role;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.entities.User;
import stream.flarebot.flarebot.FlareBot;
import stream.flarebot.flarebot.FlareBotManager;
import stream.flarebot.flarebot.commands.Command;
import stream.flarebot.flarebot.commands.CommandType;
import stream.flarebot.flarebot.objects.GuildWrapper;
import stream.flarebot.flarebot.util.MessageUtils;

import java.util.Iterator;

public class FixCommand implements Command {


    @Override
    public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
        for (Member member1 : guild.getGuild().getMembers()) {
            Iterator<String> iterator = guild.getAutoAssignRoles().iterator();
            while (iterator.hasNext()) {
                Role role = guild.getGuild().getRoleById(iterator.next());
                if (role == null) {
                    iterator.remove();
                } else {
                    if (!member1.getRoles().contains(role)) {
                        guild.getGuild().getController().addRolesToMember(member1, role).queue();
                    }
                }
            }
        }
        if (guild.isSongnickEnabled()) {
            Player player = FlareBot.getInstance().getMusicManager().getPlayer(guild.getGuildId());
            if (player.getPlaylist().isEmpty()) {
                guild.getGuild().getController().setNickname(guild.getGuild().getSelfMember(), null).queue();
            } else if (player.getPlayingTrack() != null) {
                String str = null;
                if (player.getPlayingTrack() != null) {
                    str = player.getPlayingTrack().getTrack().getInfo().title;
                    if (str.length() > 32)
                        str = str.substring(0, 32);
                    str = str.substring(0, str.lastIndexOf(' ') + 1);
                } // Even I couldn't make this a one-liner
                guild.getGuild().getController()
                        .setNickname(guild.getGuild().getSelfMember(), str)
                        .queue();
            }
        } else {
            guild.getGuild().getController().setNickname(guild.getGuild().getSelfMember(), null).queue();
        }
    }

    @Override
    public String getCommand() {
        return "fix";
    }

    @Override
    public String getDescription() {
        return "A command to fix common errors caused by downtime or crash";
    }

    @Override
    public String getUsage() {
        return "`{%}fix` - Fixes common issues";
    }

    @Override
    public CommandType getType() {
        return CommandType.GENERAL;
    }
}

@@ -1628,154 +1628,30 @@
     
-if (player.getPlaylist().isEmpty()) %7B%0A                guild.getGuild().getController().setNickname(guild.getGuild().getSelfMember(), null).queue()
+String nickname = null
 ;%0A  
@@ -1660,23 +1660,16 @@
         
-%7D else 
 if (play
@@ -1720,106 +1720,16 @@
     
-String str = null;%0A                if (player.getPlayingTrack() != null) %7B%0A                    str
+nickname
  = p
@@ -1800,19 +1800,20 @@
     
-    if (str
+if (nickname
 .len
@@ -1823,16 +1823,18 @@
 () %3E 32)
+ %7B
 %0A       
@@ -1842,37 +1842,43 @@
             
-    str = str
+nickname = nickname
 .substring(0
@@ -1904,21 +1904,45 @@
     
+%7D%0A
     
-str = str
+            nickname = nickname
 .sub
@@ -1951,19 +1951,24 @@
 ring(0, 
-str
+nickname
 .lastInd
@@ -1999,59 +1999,10 @@
     
-    %7D // Even I couldn't make this a one-liner%0A    
+%7D%0A
     
@@ -2042,20 +2042,16 @@
 oller()%0A
-    
         
@@ -2113,17 +2113,18 @@
 (), 
-str)%0A    
+nickname)%0A
     
@@ -2149,30 +2149,16 @@
 ueue();%0A
-            %7D%0A
         

Make changes