Search in sources :

Example 1 with IUser

use of sx.blah.discord.handle.obj.IUser in project KaellyBot by Kaysoro.

the class AboutCommand method request.

@Override
public boolean request(IMessage message) {
    if (super.request(message)) {
        IUser author = ClientConfig.DISCORD().getApplicationOwner();
        EmbedBuilder builder = new EmbedBuilder();
        Language lg = Translator.getLanguageFrom(message.getChannel());
        builder.withTitle(Translator.getLabel(lg, "about.title").replace("{name}", Constants.name).replace("{version}", Constants.version)).withDesc(Translator.getLabel(lg, "about.desc").replace("{game}", Constants.game)).withColor(new Random().nextInt(16777216)).withThumbnail(ClientConfig.DISCORD().getApplicationIconURL()).withAuthorName(author.getName()).withAuthorIcon(author.getAvatarURL()).withImage(Constants.changelog);
        ;
        builder.appendField(Translator.getLabel(lg, "about.invite.title"), Translator.getLabel(lg, "about.invite.desc").replace("{name}", Constants.name).replace("{invite}", Constants.invite), true).appendField(Translator.getLabel(lg, "about.support.title"), Translator.getLabel(lg, "about.support.desc").replace("{name}", Constants.name).replace("{discordInvite}", Constants.discordInvite), true).appendField(Translator.getLabel(lg, "about.twitter.title"), Translator.getLabel(lg, "about.twitter.desc").replace("{name}", Constants.name).replace("{twitter}", Constants.twitterAccount), true).appendField(Translator.getLabel(lg, "about.opensource.title"), Translator.getLabel(lg, "about.opensource.desc").replace("{git}", Constants.git), true).appendField(Translator.getLabel(lg, "about.free.title"), Translator.getLabel(lg, "about.free.desc").replace("{paypal}", Constants.paypal), true);
        StringBuilder st = new StringBuilder();
        for (Donator donator : Donator.values()) st.append(donator.getName()).append(", ");
        st.setLength(st.length() - 2);
        builder.appendField(Translator.getLabel(lg, "about.donators.title"), st.toString() + ".", true);
        Message.sendEmbed(message.getChannel(), builder.build());
        return true;
    }
    return false;
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) Language(enums.Language) Random(java.util.Random) Donator(enums.Donator) IUser(sx.blah.discord.handle.obj.IUser)

Example 2 with IUser

use of sx.blah.discord.handle.obj.IUser 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)

Example 3 with IUser

use of sx.blah.discord.handle.obj.IUser in project DisCal-Discord-Bot by NovaFox161.

the class Authorization method requestCode.

public void requestCode(MessageReceivedEvent event, GuildSettings settings) {
    try {
        String body = "client_id=" + clientData.getClientId() + "&scope=" + CalendarScopes.CALENDAR;
        com.mashape.unirest.http.HttpResponse<JsonNode> response = Unirest.post("https://accounts.google.com/o/oauth2/device/code").header("Content-Type", "application/x-www-form-urlencoded").body(body).asJson();
        if (response.getStatus() == HttpStatusCodes.STATUS_CODE_OK) {
            Type type = new TypeToken<CodeResponse>() {
            }.getType();
            CodeResponse cr = new Gson().fromJson(response.getBody().toString(), type);
            // Send DM to user with code.
            EmbedBuilder em = new EmbedBuilder();
            em.withAuthorIcon(Main.client.getGuildByID(266063520112574464L).getIconURL());
            em.withAuthorName("DisCal");
            em.withTitle(MessageManager.getMessage("Embed.AddCalendar.Code.Title", settings));
            em.appendField(MessageManager.getMessage("Embed.AddCalendar.Code.Code", settings), cr.user_code, true);
            em.withFooterText(MessageManager.getMessage("Embed.AddCalendar.Code.Footer", settings));
            em.withUrl(cr.verification_url);
            em.withColor(36, 153, 153);
            IUser user = event.getAuthor();
            Message.sendDirectMessage(MessageManager.getMessage("AddCalendar.Auth.Code.Request.Success", settings), em.build(), user);
            // Start timer to poll Google Cal for auth
            Poll poll = new Poll(user, event.getGuild());
            poll.setDevice_code(cr.device_code);
            poll.setRemainingSeconds(cr.expires_in);
            poll.setExpires_in(cr.expires_in);
            poll.setInterval(cr.interval);
            pollForAuth(poll);
        } else {
            Message.sendDirectMessage(MessageManager.getMessage("AddCalendar.Auth.Code.Request.Failure.NotOkay", settings), event.getAuthor());
            Logger.getLogger().debug(event.getAuthor(), "Error requesting access token.", "Status code: " + response.getStatus() + " | " + response.getStatusText() + " | " + response.getBody().toString(), this.getClass(), true);
        }
    } catch (Exception e) {
        // Failed, report issue to dev.
        Logger.getLogger().exception(event.getAuthor(), "Failed to request Google Access Code", e, this.getClass(), true);
        IUser u = event.getAuthor();
        Message.sendDirectMessage(MessageManager.getMessage("AddCalendar.Auth.Code.Request.Failure.Unknown", settings), u);
    }
}
Also used : CodeResponse(com.cloudcraftgaming.discal.api.object.json.google.CodeResponse) Gson(com.google.gson.Gson) JsonNode(com.mashape.unirest.http.JsonNode) IOException(java.io.IOException) Type(java.lang.reflect.Type) EmbedBuilder(sx.blah.discord.util.EmbedBuilder) IUser(sx.blah.discord.handle.obj.IUser) Poll(com.cloudcraftgaming.discal.api.object.network.google.Poll)

Example 4 with IUser

use of sx.blah.discord.handle.obj.IUser in project DisCal-Discord-Bot by NovaFox161.

the class DevCommand method moduleEval.

@SuppressWarnings("all")
private void moduleEval(MessageReceivedEvent event) {
    IGuild guild = event.getGuild();
    IUser user = event.getAuthor();
    IMessage message = event.getMessage();
    IDiscordClient client = event.getClient();
    IChannel channel = event.getChannel();
    String input = message.getContent().substring(message.getContent().indexOf("eval") + 5).replaceAll("`", "");
    Object o = null;
    factory.put("guild", guild);
    factory.put("channel", channel);
    factory.put("user", user);
    factory.put("message", message);
    factory.put("command", this);
    factory.put("client", client);
    factory.put("builder", new EmbedBuilder());
    factory.put("cUser", client.getOurUser());
    try {
        o = factory.eval(input);
    } catch (Exception ex) {
        EmbedBuilder em = new EmbedBuilder();
        em.withAuthorIcon(guild.getIconURL());
        em.withAuthorName("Error");
        em.withDesc(ex.getMessage());
        em.withFooterText("Eval failed");
        em.withColor(56, 138, 237);
        Message.sendMessage(em.build(), channel);
        return;
    }
    EmbedBuilder em = new EmbedBuilder();
    em.withAuthorIcon(guild.getIconURL());
    em.withAuthorName("Success!");
    em.withColor(56, 138, 237);
    em.withTitle("Evaluation output.");
    em.withDesc(o == null ? "No output, object is null" : o.toString());
    em.appendField("Input", "```java\n" + input + "\n```", false);
    em.withFooterText("Eval successful!");
    Message.sendMessage(em.build(), channel);
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) IChannel(sx.blah.discord.handle.obj.IChannel) IMessage(sx.blah.discord.handle.obj.IMessage) IUser(sx.blah.discord.handle.obj.IUser) IGuild(sx.blah.discord.handle.obj.IGuild) IDiscordClient(sx.blah.discord.api.IDiscordClient) DiscordException(sx.blah.discord.util.DiscordException)

Example 5 with IUser

use of sx.blah.discord.handle.obj.IUser in project DisCal-Discord-Bot by NovaFox161.

the class DisCalCommand method moduleDmAnnouncements.

private void moduleDmAnnouncements(MessageReceivedEvent event, GuildSettings settings) {
    if (settings.isDevGuild()) {
        IUser user = event.getAuthor();
        if (settings.getDmAnnouncements().contains(user.getStringID())) {
            settings.getDmAnnouncements().remove(user.getStringID());
            DatabaseManager.getManager().updateSettings(settings);
            Message.sendMessage(MessageManager.getMessage("DisCal.DmAnnouncements.Off", settings), event);
        } else {
            settings.getDmAnnouncements().add(user.getStringID());
            DatabaseManager.getManager().updateSettings(settings);
            Message.sendMessage(MessageManager.getMessage("DisCal.DmAnnouncements.On", settings), event);
        }
    } else {
        Message.sendMessage(MessageManager.getMessage("Notification.Disabled", settings), event);
    }
}
Also used : IUser(sx.blah.discord.handle.obj.IUser)

Aggregations

IUser (sx.blah.discord.handle.obj.IUser)67 ArrayList (java.util.ArrayList)15 IGuild (sx.blah.discord.handle.obj.IGuild)13 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)13 XEmbedBuilder (com.github.vaerys.objects.XEmbedBuilder)9 IMessage (sx.blah.discord.handle.obj.IMessage)9 IRole (sx.blah.discord.handle.obj.IRole)8 List (java.util.List)7 MissingArgumentException (me.shadorc.shadbot.exception.MissingArgumentException)7 IllegalCmdArgumentException (me.shadorc.shadbot.exception.IllegalCmdArgumentException)6 IChannel (sx.blah.discord.handle.obj.IChannel)6 HashMap (java.util.HashMap)5 CCommandObject (com.github.vaerys.objects.CCommandObject)4 AbstractCommand (me.shadorc.shadbot.core.command.AbstractCommand)4 CommandCategory (me.shadorc.shadbot.core.command.CommandCategory)4 Context (me.shadorc.shadbot.core.command.Context)4 Command (me.shadorc.shadbot.core.command.annotation.Command)4 BotUtils (me.shadorc.shadbot.utils.BotUtils)4 FormatUtils (me.shadorc.shadbot.utils.FormatUtils)4 TextUtils (me.shadorc.shadbot.utils.TextUtils)4