Search in sources :

Example 31 with TextChannel

use of net.dv8tion.jda.core.entities.TextChannel in project FlareBot by FlareBot.

the class VoteUtil method sendVoteMessage.

public static void sendVoteMessage(UUID id, VoteGroup.VoteRunnable voteRunnable, VoteGroup group, long timeout, TextChannel channel, User user, String buttonGroupString, ButtonGroup.Button... optionalButtons) {
    EmbedBuilder votesEmbed = new EmbedBuilder().setDescription("Vote to " + group.getMessageDesc()).addField("Yes", "0", true).addField("No", "0", true);
    String messageDesc = group.getMessageDesc();
    votesEmbed.setColor(ColorUtils.FLAREBOT_BLUE);
    group.setVotesEmbed(votesEmbed);
    ButtonGroup buttonGroup = new ButtonGroup(user.getIdLong(), buttonGroupString);
    groupMap.put(id + channel.getGuild().getId(), group);
    runnableMap.put(id + channel.getGuild().getId(), voteRunnable);
    buttonGroup.addButton(new ButtonGroup.Button(355776056092917761L, (owner, user1, message) -> {
        if (group.addVote(VoteGroup.Vote.YES, user1)) {
            MessageUtils.sendAutoDeletedMessage(new EmbedBuilder().setDescription("You voted yes on " + messageDesc).build(), 2000, channel);
        } else {
            MessageUtils.sendAutoDeletedMessage(new EmbedBuilder().setDescription("You cannot vote on " + messageDesc).build(), 2000, channel);
        }
    }));
    buttonGroup.addButton(new ButtonGroup.Button(355776081384570881L, (owner, user1, message) -> {
        if (group.addVote(VoteGroup.Vote.NO, user1)) {
            MessageUtils.sendAutoDeletedMessage(new EmbedBuilder().setDescription("You voted no on " + messageDesc).build(), 2000, channel);
        } else {
            MessageUtils.sendAutoDeletedMessage(new EmbedBuilder().setDescription("You cannot vote on " + messageDesc).build(), 2000, channel);
        }
    }));
    for (ButtonGroup.Button button : optionalButtons) {
        buttonGroup.addButton(button);
    }
    Message voteMessage = ButtonUtil.sendReturnedButtonedMessage(channel, votesEmbed.build(), buttonGroup);
    group.setVoteMessage(voteMessage);
    new FlareBotTask("Votes-" + voteMessage.getId()) {

        @Override
        public void run() {
            voteRunnable.run(group.won());
            groupMap.remove(group.getMessageDesc() + channel.getGuild().getId());
            runnableMap.remove(group.getMessageDesc() + channel.getGuild().getId());
            channel.deleteMessageById(voteMessage.getId()).queue();
        }
    }.delay(timeout);
}
Also used : ButtonGroup(stream.flarebot.flarebot.util.objects.ButtonGroup) FlareBotTask(stream.flarebot.flarebot.scheduler.FlareBotTask) TextChannel(net.dv8tion.jda.core.entities.TextChannel) ButtonUtil(stream.flarebot.flarebot.util.buttons.ButtonUtil) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) UUID(java.util.UUID) ColorUtils(stream.flarebot.flarebot.util.ColorUtils) Message(net.dv8tion.jda.core.entities.Message) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) Guild(net.dv8tion.jda.core.entities.Guild) User(net.dv8tion.jda.core.entities.User) Scheduler(stream.flarebot.flarebot.scheduler.Scheduler) Map(java.util.Map) MessageUtils(stream.flarebot.flarebot.util.MessageUtils) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) Message(net.dv8tion.jda.core.entities.Message) ButtonGroup(stream.flarebot.flarebot.util.objects.ButtonGroup) FlareBotTask(stream.flarebot.flarebot.scheduler.FlareBotTask)

Example 32 with TextChannel

use of net.dv8tion.jda.core.entities.TextChannel in project Rubicon by Rubicon-Bot.

the class CommandPortal method inviteGuild.

private void inviteGuild(CommandManager.ParsedCommandInvocation parsedCommandInvocation) {
    Guild messageGuild = parsedCommandInvocation.getMessage().getGuild();
    TextChannel messageChannel = parsedCommandInvocation.getMessage().getTextChannel();
    if (!StringUtil.isNumeric(parsedCommandInvocation.getArgs()[1])) {
        parsedCommandInvocation.getMessage().getTextChannel().sendMessage(EmbedUtil.error("Portal error", "Invalid guild id.").build()).queue(msg -> msg.delete().queueAfter(30, TimeUnit.SECONDS));
        return;
    }
    if (parsedCommandInvocation.getArgs()[1].equalsIgnoreCase(messageGuild.getId())) {
        messageChannel.sendMessage(EmbedUtil.error("Portal error!", "Portal you can't invite yourself.").build()).queue();
        return;
    }
    // Check if portal exists
    String oldGuildPortalEntry = RubiconBot.getMySQL().getGuildValue(messageGuild, "portal");
    if (oldGuildPortalEntry.equals("open") || oldGuildPortalEntry.contains("waiting")) {
        messageChannel.sendMessage(EmbedUtil.error("Portal error!", "Portal is already open.").build()).queue();
        return;
    }
    String guildId = parsedCommandInvocation.getArgs()[1];
    Guild guildTwo = null;
    try {
        guildTwo = parsedCommandInvocation.getMessage().getJDA().getGuildById(guildId);
    } catch (NullPointerException ignored) {
    // Guild doesn't exist
    }
    if (guildTwo == null) {
        parsedCommandInvocation.getMessage().getTextChannel().sendMessage(EmbedUtil.error("Portal error", "Invalid guild id.").build()).queue(msg -> msg.delete().queueAfter(30, TimeUnit.SECONDS));
        return;
    }
    if (RubiconBot.getMySQL().getGuildValue(guildTwo, "portal").equals("waiting") || RubiconBot.getMySQL().getGuildValue(guildTwo, "portal").equals("closed")) {
        EmbedBuilder builder = EmbedUtil.embed("Portal Invite", parsedCommandInvocation.getMessage().getGuild().getName() + "(" + parsedCommandInvocation.getMessage().getGuild().getId() + ") has sent you an portal invite.\n`Accept with rc!portal accept <serverid>`");
        builder.setFooter("Execute this command on your server", null);
        builder.setColor(Colors.COLOR_PRIMARY);
        guildTwo.getOwner().getUser().openPrivateChannel().queue(privateChannel -> privateChannel.sendMessage(builder.build()).queue());
        if (!inviteFile.exists()) {
            try {
                inviteFile.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        Configuration configuration = new Configuration(inviteFile);
        createInviteEntryIfNotExists(configuration, guildTwo);
        configuration.set(guildTwo.getId() + "." + messageGuild.getId(), 1);
        parsedCommandInvocation.getMessage().getTextChannel().sendMessage(EmbedUtil.success("Portal Invite sent", "Successfully sent an portal invite to " + guildTwo.getName()).build()).queue();
    }
}
Also used : TextChannel(net.dv8tion.jda.core.entities.TextChannel) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) IOException(java.io.IOException) Guild(net.dv8tion.jda.core.entities.Guild)

Example 33 with TextChannel

use of net.dv8tion.jda.core.entities.TextChannel in project Rubicon by Rubicon-Bot.

the class CommandPortal method closePortal.

private void closePortal(CommandManager.ParsedCommandInvocation parsedCommandInvocation) {
    JDA jda = parsedCommandInvocation.getMessage().getJDA();
    Guild messageGuild = parsedCommandInvocation.getMessage().getGuild();
    TextChannel messageChannel = parsedCommandInvocation.getMessage().getTextChannel();
    // Check if portal exists
    String oldGuildPortalEntry = RubiconBot.getMySQL().getGuildValue(messageGuild, "portal");
    if (oldGuildPortalEntry.equals("closed")) {
        messageChannel.sendMessage(EmbedUtil.error("Portal error!", "Portal is already closed").build()).queue();
        return;
    }
    if (oldGuildPortalEntry.equals("waiting")) {
        RubiconBot.getMySQL().updateGuildValue(messageGuild, "portal", "closed");
        messageChannel.sendMessage(EmbedUtil.success("Portal", "Successful closed portal request.").build()).queue();
        return;
    }
    Guild partnerGuild = jda.getGuildById(RubiconBot.getMySQL().getPortalValue(messageGuild, "partnerid"));
    // Close Channels
    TextChannel channelOne = null;
    TextChannel channelTwo = null;
    try {
        channelOne = jda.getTextChannelById(RubiconBot.getMySQL().getPortalValue(messageGuild, "channelid"));
        channelTwo = jda.getTextChannelById(RubiconBot.getMySQL().getPortalValue(partnerGuild, "channelid"));
    } catch (NullPointerException ignored) {
    // Channels doesn't exist
    }
    if (channelOne != null)
        channelOne.getManager().setName(closedChannelName).queue();
    if (channelTwo != null)
        channelTwo.getManager().setName(closedChannelName).queue();
    // Close and delete DB Portal
    RubiconBot.getMySQL().updateGuildValue(messageGuild, "portal", "closed");
    RubiconBot.getMySQL().deletePortal(messageGuild);
    RubiconBot.getMySQL().updateGuildValue(partnerGuild, "portal", "closed");
    RubiconBot.getMySQL().deletePortal(partnerGuild);
    EmbedBuilder portalClosedMessage = new EmbedBuilder();
    portalClosedMessage.setAuthor("Portal closed!", null, jda.getSelfUser().getEffectiveAvatarUrl());
    portalClosedMessage.setDescription("Portal was closed. Create a new one with `" + parsedCommandInvocation.getPrefix() + "portal create`");
    portalClosedMessage.setColor(Colors.COLOR_ERROR);
    channelOne.sendMessage(portalClosedMessage.build()).queue();
    portalClosedMessage.setDescription("Portal was closed. Create a new one with `" + parsedCommandInvocation.getPrefix() + "portal create`");
    channelTwo.sendMessage(portalClosedMessage.build()).queue();
    channelOne.getManager().setTopic("Portal closed").queue();
    channelTwo.getManager().setTopic("Portal closed").queue();
}
Also used : TextChannel(net.dv8tion.jda.core.entities.TextChannel) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) JDA(net.dv8tion.jda.core.JDA) Guild(net.dv8tion.jda.core.entities.Guild)

Example 34 with TextChannel

use of net.dv8tion.jda.core.entities.TextChannel in project Rubicon by Rubicon-Bot.

the class CommandPortal method connectGuilds.

/**
 * Create portals at two guilds
 *
 * @param guildOne message guild
 * @param guildTwo guild with waiting status
 */
private void connectGuilds(Guild guildOne, Guild guildTwo, TextChannel messageChannel) {
    // Channel creation and waiting check
    try {
        TextChannel channelOne;
        TextChannel channelTwo;
        if (guildOne.getTextChannelsByName(portalChannelName, true).size() == 0) {
            if (guildOne.getMemberById(RubiconBot.getJDA().getSelfUser().getId()).getPermissions().contains(Permission.MANAGE_CHANNEL)) {
                channelOne = (TextChannel) guildOne.getController().createTextChannel(portalChannelName).complete();
            } else {
                messageChannel.sendMessage(EmbedUtil.error("Portal Error!", "I need the `MANAGE_CHANNEL` permissions or you create yourself a channel called `rubicon-portal`.").setFooter(guildOne.getName(), null).build()).queue();
                return;
            }
        } else {
            channelOne = guildOne.getTextChannelsByName(portalChannelName, true).get(0);
        }
        if (guildTwo.getTextChannelsByName(portalChannelName, true).size() == 0) {
            if (guildTwo.getMemberById(RubiconBot.getJDA().getSelfUser().getId()).getPermissions().contains(Permission.MANAGE_CHANNEL)) {
                channelTwo = (TextChannel) guildTwo.getController().createTextChannel(portalChannelName).complete();
            } else {
                guildTwo.getOwner().getUser().openPrivateChannel().queue(privateChannel -> privateChannel.sendMessage(EmbedUtil.error("Portal Error!", "I need the `MANAGE_CHANNEL` permissions or you create yourself a channel called `rubicon-portal`.").setFooter(guildTwo.getName(), null).build()).queue());
                RubiconBot.getMySQL().updateGuildValue(guildTwo, "portal", "closed");
                setGuildWaiting(guildOne, messageChannel);
                return;
            }
        } else {
            channelTwo = guildTwo.getTextChannelsByName(portalChannelName, true).get(0);
        }
        // Update Database Values
        RubiconBot.getMySQL().updateGuildValue(guildOne, "portal", "open");
        RubiconBot.getMySQL().createPortal(guildOne, guildTwo, channelOne);
        RubiconBot.getMySQL().updateGuildValue(guildTwo, "portal", "open");
        RubiconBot.getMySQL().createPortal(guildTwo, guildOne, channelTwo);
        channelOne.getManager().setTopic("Connected to: " + guildTwo.getName()).queue();
        channelTwo.getManager().setTopic("Connected to: " + guildOne.getName()).queue();
        // Send Connected Message
        sendConnectedMessage(channelOne, channelTwo);
    } catch (Exception ignored) {
        Logger.error(ignored);
    }
}
Also used : TextChannel(net.dv8tion.jda.core.entities.TextChannel) IOException(java.io.IOException)

Example 35 with TextChannel

use of net.dv8tion.jda.core.entities.TextChannel in project Rubicon by Rubicon-Bot.

the class CommandPortal method createPortalWithRandomGuild.

/**
 * Creates a portal with a random guild
 *
 * @param parsedCommandInvocation parsedCommandInvocation
 */
private void createPortalWithRandomGuild(CommandManager.ParsedCommandInvocation parsedCommandInvocation) {
    Guild messageGuild = parsedCommandInvocation.getMessage().getGuild();
    TextChannel messageChannel = parsedCommandInvocation.getMessage().getTextChannel();
    // Check if portal exists
    String oldGuildPortalEntry = RubiconBot.getMySQL().getGuildValue(messageGuild, "portal");
    if (oldGuildPortalEntry.equals("open") || oldGuildPortalEntry.contains("waiting") || RubiconBot.getMySQL().ifPortalExist(messageGuild)) {
        messageChannel.sendMessage(EmbedUtil.error("Portal error!", "Portal is already open.").build()).queue();
        return;
    }
    List<Guild> waitingGuilds = RubiconBot.getMySQL().getGuildsByValue("portal", "waiting");
    if (waitingGuilds.size() == 0) {
        setGuildWaiting(messageGuild, messageChannel);
    } else {
        connectGuilds(messageGuild, waitingGuilds.get(0), messageChannel);
    }
}
Also used : TextChannel(net.dv8tion.jda.core.entities.TextChannel) Guild(net.dv8tion.jda.core.entities.Guild)

Aggregations

TextChannel (net.dv8tion.jda.core.entities.TextChannel)91 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)27 Guild (net.dv8tion.jda.core.entities.Guild)22 User (net.dv8tion.jda.core.entities.User)20 Member (net.dv8tion.jda.core.entities.Member)18 List (java.util.List)17 Message (net.dv8tion.jda.core.entities.Message)17 ArrayList (java.util.ArrayList)14 VoiceChannel (net.dv8tion.jda.core.entities.VoiceChannel)13 GuildWrapper (stream.flarebot.flarebot.objects.GuildWrapper)13 MessageUtils (stream.flarebot.flarebot.util.MessageUtils)13 Collectors (java.util.stream.Collectors)11 CommandType (stream.flarebot.flarebot.commands.CommandType)8 Role (net.dv8tion.jda.core.entities.Role)7 FlareBot (stream.flarebot.flarebot.FlareBot)7 Track (com.arsenarsen.lavaplayerbridge.player.Track)6 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)6 MantaroData (net.kodehawa.mantarobot.data.MantaroData)6 DBGuild (net.kodehawa.mantarobot.db.entities.DBGuild)6 EmoteReference (net.kodehawa.mantarobot.utils.commands.EmoteReference)6