Search in sources :

Example 1 with Guild

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);
    }
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ServerDofus(data.ServerDofus) IOException(java.io.IOException) Guild(data.Guild) IOException(java.io.IOException)

Example 2 with Guild

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;
}
Also used : CommandForbidden(data.CommandForbidden) Language(enums.Language) Matcher(java.util.regex.Matcher) AbstractCommand(commands.model.AbstractCommand) Command(commands.model.Command) ArrayList(java.util.ArrayList) Guild(data.Guild)

Example 3 with Guild

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;
}
Also used : Language(enums.Language) Matcher(java.util.regex.Matcher) ServerDofus(data.ServerDofus) ArrayList(java.util.ArrayList) List(java.util.List) Guild(data.Guild)

Example 4 with Guild

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);
    }
}
Also used : Language(enums.Language) DiscordException(sx.blah.discord.util.DiscordException) LanguageCommand(commands.config.LanguageCommand) Guild(data.Guild) DiscordException(sx.blah.discord.util.DiscordException) ServerCommand(commands.config.ServerCommand) TwitterCommand(commands.config.TwitterCommand) AlmanaxCommand(commands.classic.AlmanaxCommand) RSSCommand(commands.config.RSSCommand) EventSubscriber(sx.blah.discord.api.events.EventSubscriber)

Example 5 with Guild

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;
}
Also used : ChannelLanguage(data.ChannelLanguage) Language(enums.Language) ChannelLanguage(data.ChannelLanguage) Guild(data.Guild)

Aggregations

Guild (data.Guild)5 Language (enums.Language)4 ServerDofus (data.ServerDofus)2 ArrayList (java.util.ArrayList)2 Matcher (java.util.regex.Matcher)2 AlmanaxCommand (commands.classic.AlmanaxCommand)1 LanguageCommand (commands.config.LanguageCommand)1 RSSCommand (commands.config.RSSCommand)1 ServerCommand (commands.config.ServerCommand)1 TwitterCommand (commands.config.TwitterCommand)1 AbstractCommand (commands.model.AbstractCommand)1 Command (commands.model.Command)1 ChannelLanguage (data.ChannelLanguage)1 CommandForbidden (data.CommandForbidden)1 IOException (java.io.IOException)1 List (java.util.List)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 EventSubscriber (sx.blah.discord.api.events.EventSubscriber)1 DiscordException (sx.blah.discord.util.DiscordException)1