aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/commands/CommandManager.java
blob: d56b39a433cd825dbdd554f11928b46e22c3bfd8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package commands;

import builders.ScheduleMessageBuilder;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import vtuber.ScheduleHandler;

import java.util.ArrayList;

public class CommandManager extends ListenerAdapter {
    ScheduleHandler scheduleHandler;
    ScheduleMessageBuilder scb;
    public CommandManager(String holodexAPIKey) {
        scheduleHandler = new ScheduleHandler(holodexAPIKey);
        scb = new ScheduleMessageBuilder();
        System.out.println("CommandManager initialized");
    }
    @Override
    public void onSlashCommand(SlashCommandEvent e) {
        String command = e.getName();
        switch (command) {
            case "schedule":
                String organization = e.getOption("organization").getAsString();
                organization = organization.replaceAll(" ", "%20");
                if (scheduleHandler.organizationExists(organization) == false) {
                    e.reply("Sorry, I couldn't find any information on that organization. Please ensure it matches Holodex's spelling").queue();
                    return;
                }
                MessageEmbed scheduleMessage = scb.buildLiveAndUpcomingMessage(scheduleHandler.getSchedule(organization, 10));
                e.deferReply().queue();
                e.getHook().sendMessageEmbeds(scheduleMessage).queue();
                break;
            default:
                e.reply("Unknown command received").queue();
                break;
        }
    }

    public ArrayList<MessageEmbed> updateUpcomingChannel(String name, String type){
        ArrayList<MessageEmbed> messageEmbeds = new ArrayList<>();
        switch (type) {
            case "org":
                messageEmbeds = scb.getUpcomingLiveListMessages(scheduleHandler.getSchedule(name));
                break;
            case "channel":
                messageEmbeds = scb.getUpcomingLiveListMessages(scheduleHandler.getScheduleChannelId(name));
                break;
            default:
                System.out.println("Unknown type");
                break;
        }
        return messageEmbeds;
    }

}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage