use of data.Guild in project KaellyBot by Kaysoro.
the class PortalFinder method start.
public static void start() {
if (!isStarted) {
isStarted = true;
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
scheduler.scheduleAtFixedRate(() -> {
try {
for (Guild guild : Guild.getGuilds().values()) if (guild.getServerDofus() != null) {
// Server renseigné ?
ServerDofus server = guild.getServerDofus();
// Si les positions ne sont plus d'actualités, on les met à jour
if (System.currentTimeMillis() - server.getLastSweetRefresh() > DELTA)
server.setSweetPortals(Portal.getSweetPortals(server));
guild.mergePortals(server.getSweetPortals());
}
} catch (IOException e) {
ExceptionManager.manageSilentlyIOException(e);
} catch (Exception e) {
ExceptionManager.manageSilentlyException(e);
}
}, 0, 20, TimeUnit.MINUTES);
}
}
use of data.Guild in project KaellyBot by Kaysoro.
the class CommandCommand method request.
@Override
public boolean request(IMessage message) {
if (super.request(message)) {
Language lg = Translator.getLanguageFrom(message.getChannel());
if (isUserHasEnoughRights(message)) {
Guild guild = Guild.getGuild(message.getGuild());
Matcher m = getMatcher(message);
m.find();
List<Command> potentialCmds = new ArrayList<>();
String commandName = m.group(1).trim();
for (Command command : CommandManager.getCommands()) if (command.isPublic() && !command.isAdmin() && command.getName().contains(commandName))
potentialCmds.add(command);
if (potentialCmds.size() == 1) {
Command command = potentialCmds.get(0);
String value = m.group(2);
if (command instanceof CommandCommand) {
Message.sendText(message.getChannel(), Translator.getLabel(lg, "command.request.1"));
return false;
}
if (value.matches("false") || value.matches("1") || value.matches("off")) {
if (!guild.getForbiddenCommands().containsKey(command.getName())) {
new CommandForbidden(command, guild).addToDatabase();
Message.sendText(message.getChannel(), Translator.getLabel(lg, "command.request.2") + " *" + commandName + "* " + Translator.getLabel(lg, "command.request.3"));
} else
forbiddenCmdFound.throwException(message, this, lg);
} else if (value.matches("true") || value.matches("0") || value.matches("on")) {
if (guild.getForbiddenCommands().containsKey(command.getName())) {
guild.getForbiddenCommands().get(command.getName()).removeToDatabase();
Message.sendText(message.getChannel(), Translator.getLabel(lg, "command.request.2") + " *" + commandName + "* " + Translator.getLabel(lg, "command.request.4"));
} else
forbiddenCmdNotFound.throwException(message, this, lg);
} else
new BadUseCommandDiscordException().throwException(message, this, lg);
} else if (potentialCmds.isEmpty())
notFoundCmd.throwException(message, this, lg);
else
tooMuchCmds.throwException(message, this, lg);
} else
noEnoughRights.throwException(message, this, lg);
}
return false;
}
use of data.Guild in project KaellyBot by Kaysoro.
the class ServerCommand method request.
@Override
public boolean request(IMessage message) {
if (super.request(message)) {
Guild guild = Guild.getGuild(message.getGuild());
Language lg = Translator.getLanguageFrom(message.getChannel());
Matcher m = getMatcher(message);
m.find();
if (m.group(1) != null)
if (isUserHasEnoughRights(message)) {
String serverName = m.group(1).toLowerCase().trim();
if (!serverName.equals("-reset")) {
serverName = Normalizer.normalize(serverName, Normalizer.Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", "").replaceAll("\\W+", "").trim();
List<ServerDofus> result = new ArrayList<>();
for (ServerDofus server : ServerDofus.getServersDofus()) if (Normalizer.normalize(server.getName(), Normalizer.Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", "").replaceAll("\\W+", "").toLowerCase().trim().startsWith(serverName))
result.add(server);
if (result.size() == 1) {
if (guild.getServerDofus() != null && guild.getServerDofus() != result.get(0))
guild.resetPortals();
guild.setServer(result.get(0));
guild.mergePortals(result.get(0).getSweetPortals());
Message.sendText(message.getChannel(), Translator.getLabel(lg, "server.request.1").replace("{game}", Constants.game) + " " + guild.getName() + " " + Translator.getLabel(lg, "server.request.2") + " " + result.get(0).getName() + ".");
} else if (result.isEmpty())
notFoundServer.throwException(message, this, lg);
else
tooMuchServers.throwException(message, this, lg, result);
} else {
guild.setServer(null);
Message.sendText(message.getChannel(), guild.getName() + " " + Translator.getLabel(lg, "server.request.3").replace("{game}", Constants.game));
}
} else
noEnoughRights.throwException(message, this, lg);
else {
if (guild.getServerDofus() != null)
Message.sendText(message.getChannel(), guild.getName() + " " + Translator.getLabel(lg, "server.request.4") + " " + guild.getServerDofus().getName() + ".");
else
Message.sendText(message.getChannel(), guild.getName() + " " + Translator.getLabel(lg, "server.request.5").replace("{game}", Constants.game));
}
}
return false;
}
use of data.Guild in project KaellyBot by Kaysoro.
the class GuildCreateListener method onReady.
@EventSubscriber
public void onReady(GuildCreateEvent event) {
try {
if (!Guild.getGuilds().containsKey(event.getGuild().getStringID())) {
Guild guild = new Guild(event.getGuild().getStringID(), event.getGuild().getName(), Translator.detectLanguage(event.getGuild().getDefaultChannel()));
guild.addToDatabase();
Language lg = guild.getLanguage();
LOG.info("La guilde " + guild.getId() + " - " + guild.getName() + " a ajouté " + Constants.name);
String customMessage = Translator.getLabel(lg, "welcome.message");
customMessage = customMessage.replaceAll("\\{name\\}", Constants.name).replaceAll("\\{game\\}", Constants.game).replaceAll("\\{prefix\\}", Constants.prefixCommand).replaceAll("\\{help\\}", HelpCommand.NAME).replaceAll("\\{server\\}", new ServerCommand().getName()).replaceAll("\\{lang\\}", new LanguageCommand().getName()).replaceAll("\\{twitter\\}", new TwitterCommand().getName()).replaceAll("\\{almanax\\}", new AlmanaxCommand().getName()).replaceAll("\\{rss\\}", new RSSCommand().getName()).replaceAll("\\{owner\\}", event.getGuild().getOwner().mention()).replaceAll("\\{guild\\}", event.getGuild().getName());
if (event.getGuild().getDefaultChannel() != null && event.getGuild().getDefaultChannel().getModifiedPermissions(ClientConfig.DISCORD().getOurUser()).contains(Permissions.SEND_MESSAGES))
Message.sendText(event.getGuild().getDefaultChannel(), customMessage);
else
try {
Message.sendText(event.getGuild().getOwner().getOrCreatePMChannel(), customMessage);
} catch (DiscordException e) {
LOG.warn("onReady", "Impossible de contacter l'administrateur de la guilde [" + guild.getName() + "].");
}
Message.sendText(ClientConfig.DISCORD().getChannelByID(Constants.chanReportID), "[NEW] **" + guild.getName() + "** (" + guild.getLanguage().getAbrev() + "), +" + event.getGuild().getUsers().size() + " utilisateurs");
}
} catch (Exception e) {
Reporter.report(e, event.getGuild());
LOG.error("onReady", e);
}
}
use of data.Guild 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