/*
 * Copyright 2016-2018 John Grosh (jagrosh) & Kaidan Gustave (TheMonitorLizard)
 *
 * Licensed 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.jagrosh.jdautilities.examples.command;

import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
import java.time.format.DateTimeFormatter;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.OnlineStatus;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;

/**
 *
 * @author John Grosh (jagrosh)
 */
public class ServerinfoCommand extends Command
{
    private final static String LINESTART = "\u25AB"; // ▫
    private final static String GUILD_EMOJI = "\uD83D\uDDA5"; // 🖥
    private final static String NO_REGION = "\u2754"; // ❔
    
    public ServerinfoCommand()
    {
        this.name = "serverinfo";
        this.aliases = new String[]{"server","guildinfo"};
        this.help = "shows server info";
        this.botPermissions = new Permission[]{Permission.MESSAGE_EMBED_LINKS};
        this.guildOnly = true;
    }
    
    @Override
    protected void execute(CommandEvent event) 
    {
        Guild guild = event.getGuild();
        Member owner = guild.getOwner();
        long onlineCount = guild.getMembers().stream().filter(u -> u.getOnlineStatus() != OnlineStatus.OFFLINE).count();
        long botCount = guild.getMembers().stream().filter(m -> m.getUser().isBot()).count();
        EmbedBuilder builder = new EmbedBuilder();
        String title = (GUILD_EMOJI + " Information about **" + guild.getName() + "**:")
                .replace("@everyone", "@\u0435veryone") // cyrillic e
                .replace("@here", "@h\u0435re") // cyrillic e
                .replace("discord.gg/", "dis\u0441ord.gg/"); // cyrillic c;
        String verif;
        switch(guild.getVerificationLevel()) 
        {
            case VERY_HIGH: 
                verif = "┻━┻ミヽ(ಠ益ಠ)ノ彡┻━┻"; 
                break;
            case HIGH:    
                verif = "(╯°□°）╯︵ ┻━┻"; 
                break;
            default:      
                verif = guild.getVerificationLevel().name(); 
                break;
        }
        String str = LINESTART + "ID: **" + guild.getId() + "**\n"
                + LINESTART + "Owner: " + (owner == null ? "Unknown" : "**" + owner.getUser().getName() + "**#" + owner.getUser().getDiscriminator()) + "\n"
                + LINESTART + "Location: " + (guild.getRegion().getEmoji().isEmpty() ? NO_REGION : guild.getRegion().getEmoji()) + " **" + guild.getRegion().getName() + "**\n"
                + LINESTART + "Creation: **" + guild.getTimeCreated().format(DateTimeFormatter.RFC_1123_DATE_TIME) + "**\n"
                + LINESTART + "Users: **" + guild.getMemberCache().size() + "** (" + onlineCount + " online, " + botCount + " bots)\n"
                + LINESTART + "Channels: **" + guild.getTextChannelCache().size() + "** Text, **" + guild.getVoiceChannelCache().size() + "** Voice, **" + guild.getCategoryCache().size() + "** Categories\n"
                + LINESTART + "Verification: **" + verif + "**";
        if(!guild.getFeatures().isEmpty())
            str += "\n" + LINESTART + "Features: **" + String.join("**, **", guild.getFeatures()) + "**";
        if(guild.getSplashId() != null)
        {
            builder.setImage(guild.getSplashUrl() + "?size=1024");
            str += "\n" + LINESTART + "Splash: ";
        }
        if(guild.getIconUrl()!=null)
            builder.setThumbnail(guild.getIconUrl());
        builder.setColor(owner == null ? null : owner.getColor());
        builder.setDescription(str);
        event.reply(new MessageBuilder().append(title).setEmbed(builder.build()).build());
    }
}

@@ -867,143 +867,9 @@
 api.
-EmbedBuilder;%0Aimport net.dv8tion.jda.api.MessageBuilder;%0Aimport net.dv8tion.jda.api.OnlineStatus;%0Aimport net.dv8tion.jda.api.Permission
+*
 ;%0Aim
@@ -2245,395 +2245,8 @@
  c;%0A
-        String verif;%0A        switch(guild.getVerificationLevel()) %0A        %7B%0A            case VERY_HIGH: %0A                verif = %22%E2%94%BB%E2%94%81%E2%94%BB%E3%83%9F%E3%83%BD(%E0%B2%A0%E7%9B%8A%E0%B2%A0)%E3%83%8E%E5%BD%A1%E2%94%BB%E2%94%81%E2%94%BB%22; %0A                break;%0A            case HIGH:    %0A                verif = %22(%E2%95%AF%C2%B0%E2%96%A1%C2%B0%EF%BC%89%E2%95%AF%EF%B8%B5 %E2%94%BB%E2%94%81%E2%94%BB%22; %0A                break;%0A            default:      %0A                verif = guild.getVerificationLevel().name(); %0A                break;%0A        %7D%0A
     
@@ -2464,16 +2464,17 @@
 ) + %22%5Cn%22
+;
 %0A       
@@ -2478,63 +2478,204 @@
     
-        + LINESTART + %22Location: %22 + (guild.getRegion()
+if(!guild.getVoiceChannels().isEmpty())%0A        %7B%0A            Region reg = guild.getVoiceChannels().get(0).getRegion();%0A            str += LINESTART + %22Location: %22 + (reg.getEmoji() == null %7C%7C reg
 .get
@@ -2706,33 +2706,19 @@
 EGION : 
-guild.getRegion()
+reg
 .getEmoj
@@ -2736,25 +2736,11 @@
 %22 + 
-guild.getRegion()
+reg
 .get
@@ -2746,32 +2746,33 @@
 tName() + %22**%5Cn%22
+;
 %0A               
@@ -2760,32 +2760,34 @@
 n%22;%0A        
+%7D%0A
         
 + LINESTART 
@@ -2766,33 +2766,41 @@
       %7D%0A        
-+
+str +=   
  LINESTART + %22Cr
@@ -3287,13 +3287,43 @@
 %22 + 
-verif
+guild.getVerificationLevel().name()
  + %22

fix to server info command