Search in sources :

Example 1 with SubscribeEvent

use of net.dv8tion.jda.api.hooks.SubscribeEvent in project TechDiscordBot by TechsCode-Team.

the class StaffEmbedModule method receive.

@SubscribeEvent
public void receive(GuildMessageReceivedEvent e) {
    if (e.getMember() == null)
        return;
    if (e.getAuthor().isBot())
        return;
    if (!e.getMember().getRoles().contains(STAFF_ROLE.query().first()))
        return;
    String message = e.getMessage().getContentRaw();
    if (message.startsWith("^^ ") && message.endsWith(" ^^")) {
        e.getMessage().delete().queue();
        String text = message.substring(3, message.length() - 3);
        e.getChannel().sendMessage(text).queue();
        return;
    }
    if (message.startsWith("^ ")) {
        e.getMessage().delete().queue();
        String text = message.substring(2);
        String[] arguments = text.split("\\^");
        if (arguments.length != 2 && arguments.length != 3) {
            new TechEmbedBuilder("Invalid Arguments").text("Usage: ^ Title ^ Message ^ (Optional) Thumbnail ^").error().sendTemporary(e.getChannel(), 5);
            return;
        }
        if (arguments.length == 3) {
            if (arguments[2].trim().startsWith("#")) {
                new TechEmbedBuilder(arguments[0]).footer("Posted by " + e.getAuthor().getName()).text(arguments[1]).color(Color.decode(arguments[2].trim())).queue(e.getChannel());
            } else {
                new TechEmbedBuilder(arguments[0]).footer("Posted by " + e.getAuthor().getName()).text(arguments[1]).thumbnail(arguments[2]).queue(e.getChannel());
            }
        } else {
            new TechEmbedBuilder(arguments[0]).footer("Posted by " + e.getAuthor().getName()).text(arguments[1]).queue(e.getChannel());
        }
    }
}
Also used : TechEmbedBuilder(me.TechsCode.TechDiscordBot.util.TechEmbedBuilder) SubscribeEvent(net.dv8tion.jda.api.hooks.SubscribeEvent)

Example 2 with SubscribeEvent

use of net.dv8tion.jda.api.hooks.SubscribeEvent in project TechDiscordBot by TechsCode-Team.

the class TicketModule method onSlashCommand.

@SubscribeEvent
public void onSlashCommand(SlashCommandEvent e) {
    if (e.getMember() == null || e.getMember().getUser().isBot())
        return;
    if (e.getName().equals("ticket") && e.getSubcommandName() != null) {
        if (!isTicketChat(e.getTextChannel())) {
            e.reply("This channel is not a ticket!").setEphemeral(true).queue();
            return;
        }
        boolean isTicketCreator = e.getTextChannel().getTopic() != null && e.getTextChannel().getTopic().contains(e.getMember().getAsMention());
        if (!isTicketCreator && !TechDiscordBot.isStaff(e.getMember())) {
            e.reply("You have to be the ticket creator or a staff member to execute this command!").setEphemeral(true).queue();
            return;
        }
        Member member = e.getOption("member") == null ? null : e.getOption("member").getAsMember();
        if (!e.getSubcommandName().equals("transcript") && !e.getSubcommandName().equals("close") && member == null) {
            e.reply("**Member is invalid!** This probably shouldn't be happening...").setEphemeral(true).queue();
            return;
        }
        switch(e.getSubcommandName()) {
            case "transcript":
                {
                    if (!TechDiscordBot.isStaff(e.getMember())) {
                        e.reply("You cannot force a ticket transcript!").setEphemeral(true).queue();
                        return;
                    }
                    TicketTranscript transcript = TicketTranscript.buildTranscript(e.getTextChannel(), TicketTranscriptOptions.DEFAULT);
                    Member ticketMember = getMemberFromTicket(e.getTextChannel());
                    e.reply("Generating the transcript... please wait.").queue(msg -> {
                        transcript.build(object -> {
                            if (ticketMember != null) {
                                TranscriptLogs.log(new TechEmbedBuilder("Ticket Transcript (Command)").text(ticketMember == null ? "Transcript of #" + e.getChannel().getName() + ": " + transcript.getUrl() : "Transcript of " + ticketMember.getAsMention() + "'s ticket:\n" + transcript.getUrl()).color(Color.ORANGE));
                            }
                            msg.editOriginalEmbeds(new TechEmbedBuilder("Ticket Transcript").text(ticketMember == null ? "Transcript of #" + e.getChannel().getName() + ": " + transcript.getUrl() : "Transcript of " + ticketMember.getAsMention() + "'s ticket:\n" + transcript.getUrl()).color(Color.ORANGE).build()).queue();
                            TechDiscordBot.getStorage().saveTranscript(object);
                        });
                    });
                }
            case "add":
                if (e.getMember().equals(member)) {
                    e.reply("You can't be added to a ticket you're already in.").setEphemeral(true).queue();
                    return;
                }
                e.reply("Successfully added " + member.getAsMention() + " to this ticket!").queue();
                Collection<Permission> permissionsAddAllow = new ArrayList<>(Arrays.asList(Permission.MESSAGE_ADD_REACTION, Permission.MESSAGE_ATTACH_FILES, Permission.MESSAGE_EMBED_LINKS, Permission.MESSAGE_READ, Permission.MESSAGE_WRITE, Permission.MESSAGE_HISTORY));
                Collection<Permission> permissionsAddDeny = new ArrayList<>(Arrays.asList(Permission.MANAGE_THREADS, Permission.USE_PRIVATE_THREADS, Permission.USE_PUBLIC_THREADS));
                e.getTextChannel().getManager().putPermissionOverride(member, permissionsAddAllow, permissionsAddDeny).queue();
                break;
            case "remove":
                boolean isTicketCreator2 = e.getTextChannel().getTopic() != null && e.getTextChannel().getTopic().contains(member.getAsMention());
                if (TechDiscordBot.isStaff(member) || isTicketCreator2) {
                    e.reply(member.getAsMention() + " can't be removed from this ticket!").setEphemeral(true).queue();
                    return;
                }
                e.reply("Successfully removed " + member.getAsMention() + " from this ticket!").queue();
                Collection<Permission> permissionsRemoveDeny = new ArrayList<>(Arrays.asList(Permission.MESSAGE_ADD_REACTION, Permission.MESSAGE_ATTACH_FILES, Permission.MESSAGE_EMBED_LINKS, Permission.MESSAGE_READ, Permission.MESSAGE_WRITE, Permission.MESSAGE_HISTORY));
                e.getTextChannel().getManager().putPermissionOverride(member, new ArrayList<>(), permissionsRemoveDeny).queue();
                break;
            case "close":
                TicketTranscript transcript = TicketTranscript.buildTranscript(e.getTextChannel(), TicketTranscriptOptions.DEFAULT);
                String channelId = e.getChannel().getId();
                if (isTicketCreator) {
                    if (CLOSING_CHANNELS.contains(e.getChannel().getId())) {
                        e.reply("This ticket is already closing!").setEphemeral(true).queue();
                        return;
                    }
                    e.replyEmbeds(new TechEmbedBuilder("Ticket").text("Thank you for contacting us " + e.getMember().getAsMention() + ". Consider writing a review if you enjoyed the support!").build()).queue();
                    transcript.build(object -> {
                        new TechEmbedBuilder("Transcript").text("You can view your recently closed ticket's transcript here:\n" + transcript.getUrl()).color(Color.ORANGE).queue(e.getMember());
                        TranscriptLogs.log(new TechEmbedBuilder("Ticket Transcript").text("Transcript of " + e.getMember().getAsMention() + "'s ticket:\n" + transcript.getUrl()).color(Color.ORANGE));
                        e.getTextChannel().delete().queueAfter(15, TimeUnit.SECONDS, s -> CLOSING_CHANNELS.remove(channelId));
                        TechDiscordBot.getStorage().saveTranscript(object);
                    });
                    TicketLogs.log(new TechEmbedBuilder("Solved Ticket").text("The ticket (" + e.getTextChannel().getName() + ") created by " + e.getMember().getAsMention() + " is now solved. Thanks for contacting us!").success());
                } else {
                    if (!TechDiscordBot.isStaff(e.getMember())) {
                        e.reply("You cannot close this ticket!").setEphemeral(true).queue();
                        return;
                    }
                    if (CLOSING_CHANNELS.contains(e.getChannel().getId())) {
                        e.reply("This ticket is already closing!").setEphemeral(true).queue();
                        return;
                    }
                    String reason = e.getOption("reason") == null ? null : e.getOption("reason").getAsString();
                    boolean hasReason = reason != null;
                    String reasonSend = (hasReason ? " \n\n**Reason**: " + reason : "");
                    Member ticketMember = getMemberFromTicket(e.getTextChannel());
                    e.replyEmbeds(new TechEmbedBuilder("Ticket").text(e.getMember().getAsMention() + " has closed this support ticket." + reasonSend).build()).queue();
                    CLOSING_CHANNELS.add(e.getChannel().getId());
                    if (ticketMember != null) {
                        new TechEmbedBuilder("Ticket Closed").text("The ticket (" + e.getTextChannel().getName() + ") from " + ticketMember.getAsMention() + " has been closed!").success().queueAfter(channel, 15, TimeUnit.SECONDS, (msg) -> reset());
                        if (ticketMember != null) {
                            new TechEmbedBuilder("Ticket Closed").text("Your ticket (" + e.getTextChannel().getName() + ") has been closed!" + reasonSend).success().queue(ticketMember);
                        }
                    } else {
                        new TechEmbedBuilder("Ticket Closed").text("The ticket (" + e.getTextChannel().getName() + ") from *member has left* has been closed!").success().queueAfter(channel, 15, TimeUnit.SECONDS, (msg) -> reset());
                    }
                    transcript.build(object -> {
                        if (ticketMember != null) {
                            TranscriptLogs.log(new TechEmbedBuilder("Ticket Transcript").text(ticketMember == null ? "Transcript of #" + e.getChannel().getName() + ": " + transcript.getUrl() : "Transcript of " + ticketMember.getAsMention() + "'s ticket:\n" + transcript.getUrl()).color(Color.ORANGE));
                            if (ticketMember != null) {
                                new TechEmbedBuilder("Ticket Closed").text("Your ticket (" + e.getTextChannel().getName() + ") has been closed!" + reasonSend + "\n\nYou can view the transcript here:\n" + transcript.getUrl()).success().queue(ticketMember);
                            }
                        }
                        TechDiscordBot.getStorage().saveTranscript(object);
                        e.getTextChannel().delete().queueAfter(15, TimeUnit.SECONDS, s -> CLOSING_CHANNELS.remove(channelId));
                    });
                }
                break;
            default:
                e.reply("Could not recognize this sub command!").setEphemeral(true).queue();
                break;
        }
    }
}
Also used : net.dv8tion.jda.api.entities(net.dv8tion.jda.api.entities) GuildMessageReceivedEvent(net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent) TechEmbedBuilder(me.TechsCode.TechDiscordBot.util.TechEmbedBuilder) java.util(java.util) TechDiscordBot(me.TechsCode.TechDiscordBot.TechDiscordBot) Permission(net.dv8tion.jda.api.Permission) Plugin(me.TechsCode.TechDiscordBot.util.Plugin) MessageReactionAddEvent(net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent) Collectors(java.util.stream.Collectors) SlashCommandEvent(net.dv8tion.jda.api.events.interaction.SlashCommandEvent) java.awt(java.awt) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Requirement(me.TechsCode.TechDiscordBot.objects.Requirement) SubscribeEvent(net.dv8tion.jda.api.hooks.SubscribeEvent) List(java.util.List) TicketTranscript(me.TechsCode.TechDiscordBot.transcripts.TicketTranscript) Module(me.TechsCode.TechDiscordBot.module.Module) TicketTranscriptOptions(me.TechsCode.TechDiscordBot.transcripts.TicketTranscriptOptions) TranscriptLogs(me.TechsCode.TechDiscordBot.logs.TranscriptLogs) TicketPriority(me.TechsCode.TechDiscordBot.objects.TicketPriority) TicketLogs(me.TechsCode.TechDiscordBot.logs.TicketLogs) DefinedQuery(me.TechsCode.TechDiscordBot.objects.DefinedQuery) Query(me.TechsCode.TechDiscordBot.objects.Query) TicketTranscript(me.TechsCode.TechDiscordBot.transcripts.TicketTranscript) TechEmbedBuilder(me.TechsCode.TechDiscordBot.util.TechEmbedBuilder) Permission(net.dv8tion.jda.api.Permission) SubscribeEvent(net.dv8tion.jda.api.hooks.SubscribeEvent)

Example 3 with SubscribeEvent

use of net.dv8tion.jda.api.hooks.SubscribeEvent in project TechDiscordBot by TechsCode-Team.

the class UrlWhitelistModule method onMessage.

@SubscribeEvent
public void onMessage(GuildMessageReceivedEvent e) {
    if (e.getMember() == null || e.getAuthor().isBot() || e.getMember().getRoles().contains(STAFF_ROLE.query().first()) || IGNORED_CATEGORIES.query().stream().anyMatch(c -> c.getId().equals(e.getChannel().getParent().getId())))
        return;
    boolean block = checkMessage(e.getMessage().getContentRaw());
    if (block) {
        e.getMessage().delete().queue();
        new TechEmbedBuilder("Blocked URL(s)").color(Color.RED).text("Your message contained a URL which is not in our whitelist.\n\nIf you think this is a mistake, take a look at our [**link whitelist**](" + URL + ").").sendTemporary(e.getChannel(), 10, TimeUnit.SECONDS);
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) GuildMessageReceivedEvent(net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent) TechEmbedBuilder(me.TechsCode.TechDiscordBot.util.TechEmbedBuilder) GuildMessageUpdateEvent(net.dv8tion.jda.api.events.message.guild.GuildMessageUpdateEvent) TechDiscordBot(me.TechsCode.TechDiscordBot.TechDiscordBot) URL(java.net.URL) Category(net.dv8tion.jda.api.entities.Category) Set(java.util.Set) InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) java.awt(java.awt) TimeUnit(java.util.concurrent.TimeUnit) Requirement(me.TechsCode.TechDiscordBot.objects.Requirement) SubscribeEvent(net.dv8tion.jda.api.hooks.SubscribeEvent) List(java.util.List) Matcher(java.util.regex.Matcher) Role(net.dv8tion.jda.api.entities.Role) Module(me.TechsCode.TechDiscordBot.module.Module) BufferedReader(java.io.BufferedReader) Pattern(java.util.regex.Pattern) DefinedQuery(me.TechsCode.TechDiscordBot.objects.DefinedQuery) Query(me.TechsCode.TechDiscordBot.objects.Query) LinkedHashSet(java.util.LinkedHashSet) TechEmbedBuilder(me.TechsCode.TechDiscordBot.util.TechEmbedBuilder) SubscribeEvent(net.dv8tion.jda.api.hooks.SubscribeEvent)

Example 4 with SubscribeEvent

use of net.dv8tion.jda.api.hooks.SubscribeEvent in project Utility by anweisen.

the class CommandListener method onSlashCommand.

@Override
@SubscribeEvent
public void onSlashCommand(@Nonnull SlashCommandEvent event) {
    // Acknowledge event
    event.deferReply().queue();
    manager.handleCommand(new CommandPreProcessInfo(event));
}
Also used : CommandPreProcessInfo(net.anweisen.utilities.jda.manager.process.CommandPreProcessInfo) SubscribeEvent(net.dv8tion.jda.api.hooks.SubscribeEvent)

Example 5 with SubscribeEvent

use of net.dv8tion.jda.api.hooks.SubscribeEvent in project ObbyLang by ClubObsidian.

the class DiscordCommandManager method onEvent.

@SubscribeEvent
public void onEvent(MessageReceivedEvent event) {
    String message = event.getMessage().getContentRaw();
    String label = message;
    String[] args = new String[0];
    if (message.contains(" ")) {
        String[] split = message.split(" ");
        label = split[0];
        if (split.length > 1) {
            args = Arrays.copyOfRange(split, 1, split.length);
        }
    }
    DiscordCommand command = this.registeredCommands.get(label);
    if (command != null) {
        User user = event.getAuthor();
        MessageChannel channel = event.getChannel();
        command.onCommand(user, channel, args);
    }
}
Also used : User(net.dv8tion.jda.api.entities.User) MessageChannel(net.dv8tion.jda.api.entities.MessageChannel) SubscribeEvent(net.dv8tion.jda.api.hooks.SubscribeEvent)

Aggregations

SubscribeEvent (net.dv8tion.jda.api.hooks.SubscribeEvent)15 TechEmbedBuilder (me.TechsCode.TechDiscordBot.util.TechEmbedBuilder)10 java.awt (java.awt)5 List (java.util.List)5 TimeUnit (java.util.concurrent.TimeUnit)5 TechDiscordBot (me.TechsCode.TechDiscordBot.TechDiscordBot)5 Module (me.TechsCode.TechDiscordBot.module.Module)5 DefinedQuery (me.TechsCode.TechDiscordBot.objects.DefinedQuery)5 Query (me.TechsCode.TechDiscordBot.objects.Query)5 Requirement (me.TechsCode.TechDiscordBot.objects.Requirement)5 GuildMessageReceivedEvent (net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent)5 BufferedReader (java.io.BufferedReader)4 InputStreamReader (java.io.InputStreamReader)4 HttpURLConnection (java.net.HttpURLConnection)4 URL (java.net.URL)4 ArrayList (java.util.ArrayList)4 Matcher (java.util.regex.Matcher)4 Pattern (java.util.regex.Pattern)4 Category (net.dv8tion.jda.api.entities.Category)4 GuildMessageUpdateEvent (net.dv8tion.jda.api.events.message.guild.GuildMessageUpdateEvent)4