use of data.ChannelLanguage in project KaellyBot by Kaysoro.
the class LanguageCommand method request.
@Override
public boolean request(IMessage message) {
if (super.request(message)) {
Language lg = Translator.getLanguageFrom(message.getChannel());
Matcher m = getMatcher(message);
m.find();
if (m.group(2) != null) {
// Ajouts
if (isUserHasEnoughRights(message)) {
List<Language> langs = new ArrayList<>();
for (Language lang : Language.values()) if (m.group(2).trim().toUpperCase().equals(lang.getAbrev()))
langs.add(lang);
if (langs.size() == 1) {
if (m.group(1) == null) {
Guild.getGuild(message.getGuild()).setLanguage(langs.get(0));
lg = langs.get(0);
Message.sendText(message.getChannel(), message.getGuild().getName() + " " + Translator.getLabel(lg, "lang.request.1") + " " + langs.get(0));
} else {
ChannelLanguage chan = ChannelLanguage.getChannelLanguages().get(message.getChannel().getLongID());
if (chan != null) {
if (chan.getLang().equals(langs.get(0))) {
chan.removeToDatabase();
lg = Translator.getLanguageFrom(message.getChannel());
Message.sendText(message.getChannel(), message.getChannel().getName() + " " + Translator.getLabel(lg, "lang.request.2") + " " + Guild.getGuild(message.getGuild()).getLanguage());
} else {
chan.setLanguage(langs.get(0));
lg = langs.get(0);
Message.sendText(message.getChannel(), message.getChannel().getName() + " " + Translator.getLabel(lg, "lang.request.1") + " " + chan.getLang());
}
} else {
chan = new ChannelLanguage(langs.get(0), message.getChannel().getLongID());
chan.addToDatabase();
lg = langs.get(0);
Message.sendText(message.getChannel(), message.getChannel().getName() + " " + Translator.getLabel(lg, "lang.request.1") + " " + chan.getLang());
}
}
} else if (langs.isEmpty())
notFoundLang.throwException(message, this, lg);
else
tooMuchLangs.throwException(message, this, lg);
} else {
noEnoughRights.throwException(message, this, lg);
return false;
}
} else {
// Consultation
String text = "**" + message.getGuild().getName() + "** " + Translator.getLabel(lg, "lang.request.3") + " " + Guild.getGuild(message.getGuild()).getLanguage() + ".";
ChannelLanguage chanLang = ChannelLanguage.getChannelLanguages().get(message.getChannel().getLongID());
if (chanLang != null)
text += "\nLe salon *" + message.getChannel().getName() + "* " + Translator.getLabel(lg, "lang.request.3") + " " + chanLang.getLang() + ".";
Message.sendText(message.getChannel(), text);
}
}
return false;
}
use of data.ChannelLanguage in project KaellyBot by Kaysoro.
the class Translator method getLanguageFrom.
public static Language getLanguageFrom(IChannel channel) {
Language result = Constants.defaultLanguage;
if (!channel.isPrivate()) {
Guild guild = Guild.getGuild(channel.getGuild());
result = guild.getLanguage();
ChannelLanguage channelLanguage = ChannelLanguage.getChannelLanguages().get(channel.getLongID());
if (channelLanguage != null)
result = channelLanguage.getLang();
}
return result;
}
Aggregations