ClaptrapBot/src/main/java/net/Broken/audio/FindGeneral.java

57 lines
1.9 KiB
Java
Raw Normal View History

2018-02-26 12:09:56 +01:00
package net.Broken.audio;
import net.dv8tion.jda.core.entities.Category;
import net.dv8tion.jda.core.entities.Channel;
import net.dv8tion.jda.core.entities.Guild;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.List;
2018-02-28 17:59:09 +01:00
/**
* Used to find general voice channels
*/
2018-02-26 12:09:56 +01:00
public class FindGeneral {
static Logger logger = LogManager.getLogger();
2018-02-28 17:59:09 +01:00
/**
* Search for 🤖 char on category name, if this category can't be find, auto create it
* @param guild Current guild
* @return General Category
*/
2018-02-26 12:09:56 +01:00
public static Category find(Guild guild){
List<Category> categories = guild.getCategories();
Category finded = null;
for(Category cat : categories){
if(cat.getName().contains("\uD83E\uDD16")){
finded = cat;
break;
}
}
if(finded == null)
finded = create(guild);
return finded;
}
2018-02-28 17:59:09 +01:00
/**
* Create default category "🤖 Salons Vocaux 🤖", and create basic voice channel on it.
* @param guild Current guild
* @return Brand new General Category
*/
2018-02-26 12:09:56 +01:00
private static Category create(Guild guild){
logger.info("Can't find general voice chanel, creating it!");
Channel temp = guild.getController().createCategory("\uD83E\uDD16 Salons Vocaux \uD83E\uDD16").complete();
Category cat = guild.getCategoryById(temp.getId());
cat.createVoiceChannel("Général").complete();
cat.createVoiceChannel("Cour").complete();
cat.createVoiceChannel("\uD83C\uDFAE Game 1 \uD83C\uDFAE").complete();
cat.createVoiceChannel("\uD83C\uDFAE Game 2 \uD83C\uDFAE").complete();
cat.createVoiceChannel("\uD83C\uDFAE Game 3 \uD83C\uDFAE").complete();
cat.createVoiceChannel("AFK").complete();
cat = guild.getCategoryById(temp.getId());
return cat;
}
}