Search in sources :

Example 1 with OrderUser

use of data.OrderUser in project KaellyBot by Kaysoro.

the class AlignmentCommand method request.

@Override
public boolean request(IMessage message) {
    if (super.request(message)) {
        Language lg = Translator.getLanguageFrom(message.getChannel());
        Matcher m = getMatcher(message);
        m.matches();
        String content = m.group(1).trim();
        // Initialisation du Filtre
        City city;
        Order order;
        IUser user = message.getAuthor();
        ServerDofus server = Guild.getGuild(message.getGuild()).getServerDofus();
        List<ServerDofus> servers;
        // Consultation filtré par niveau
        if ((m = Pattern.compile(">\\s+(\\d{1,3})(\\s+.+)?").matcher(content)).matches()) {
            Message.sendText(message.getChannel(), "Consultation filtré par niveau");
        // TODO
        } else {
            // L'utilisateur concerné est-il l'auteur de la commande ?
            if (Pattern.compile("^<@[!|&]?\\d+>").matcher(content).find()) {
                content = content.replaceFirst("<@[!|&]?\\d+>", "").trim();
                user = message.getMentions().get(0);
            }
            // Consultation des données filtrés par utilisateur
            if (!(servers = findServer(content)).isEmpty() && (m = Pattern.compile("(.+)").matcher(content)).matches() || content.isEmpty()) {
                Message.sendText(message.getChannel(), "Consultation des données utilisateur");
            // TODO
            } else // Enregistrement des données
            if ((m = Pattern.compile("(\\p{L}+)\\s+(\\p{L}+)\\s+(\\d{1,3})(\\s+.+)?").matcher(content)).matches()) {
                if (user == message.getAuthor() || user != message.getAuthor() && isUserHasEnoughRights(message)) {
                    // Parsing des données et traitement des divers exceptions
                    List<City> cities = findCity(m.group(1), lg);
                    if (!checkData(cities, tooMuchCities, notFoundCity, message, lg))
                        return false;
                    city = cities.get(0);
                    List<Order> orders = findOrder(m.group(2), lg);
                    if (!checkData(orders, tooMuchOrders, notFoundOrder, message, lg))
                        return false;
                    order = orders.get(0);
                    int level = Integer.parseInt(m.group(3));
                    if (m.group(4) != null) {
                        servers = findServer(m.group(4));
                        if (!checkData(servers, tooMuchServers, notFoundServer, message, lg))
                            return false;
                        server = servers.get(0);
                    } else if (server == null) {
                        notFoundGuildServer.throwException(message, this, lg);
                        return false;
                    }
                    if (OrderUser.getOrders().containsKey(Quadruple.of(user.getLongID(), server, city, order)))
                        OrderUser.getOrders().get(Quadruple.of(user.getLongID(), server, city, order)).setLevel(level);
                    else
                        new OrderUser(user.getLongID(), server, city, order, level).addToDatabase();
                    if (level != 0)
                        Message.sendText(message.getChannel(), "align.save");
                    else
                        Message.sendText(message.getChannel(), "align.reset");
                } else
                    noEnoughRights.throwException(message, this, lg);
            } else // Consultation filtré par cité et/ou par ordre
            if ((m = Pattern.compile("(\\p{L}+)(\\s+\\p{L}+)?(\\s+[\\p{L}|\\W]+)?").matcher(content)).matches()) {
                Message.sendText(message.getChannel(), "Consultation filtré par cité et/ou par ordre");
            // TODO
            } else
                badUse.throwException(message, this, lg);
        }
    }
    return false;
}
Also used : Order(enums.Order) OrderUser(data.OrderUser) Language(enums.Language) Matcher(java.util.regex.Matcher) ServerDofus(data.ServerDofus) IUser(sx.blah.discord.handle.obj.IUser) ArrayList(java.util.ArrayList) List(java.util.List) City(enums.City)

Aggregations

OrderUser (data.OrderUser)1 ServerDofus (data.ServerDofus)1 City (enums.City)1 Language (enums.Language)1 Order (enums.Order)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Matcher (java.util.regex.Matcher)1 IUser (sx.blah.discord.handle.obj.IUser)1