Search in sources :

Example 6 with Response

use of util.Response in project Botnak by Gocnak.

the class DonationManager method parseDonation.

public Response parseDonation(String[] lines) {
    Response toReturn = new Response();
    if (lines.length > 2) {
        String name = lines[1];
        try {
            Double amount = Double.parseDouble(lines[2]);
            if (amount > 0.0) {
                addDonation(new Donation("LOCAL", name, "Added manually.", amount, java.util.Date.from(Instant.now())), true);
                toReturn.setResponseText("Successfully added local donation for " + name + " !");
                toReturn.wasSuccessful();
            } else {
                toReturn.setResponseText("Failed to add donation, the amount must be greater than 0!");
            }
        } catch (Exception ignored) {
            toReturn.setResponseText("Failed to add donation, the amount must have a decimal point!");
        }
    } else {
        toReturn.setResponseText("Failed to add donation, usage: !adddonation (user) (amount)");
    }
    return toReturn;
}
Also used : Response(util.Response) Donation(util.misc.Donation)

Example 7 with Response

use of util.Response in project Botnak by Gocnak.

the class GUIMain method initComponents.

private void initComponents() {
    // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
    // Generated using JFormDesigner Evaluation license - Nick K
    menuBar1 = new JMenuBar();
    fileMenu = new JMenu();
    openBotnakFolderOption = new JMenuItem();
    openLogViewerOption = new JMenuItem();
    openSoundsOption = new JMenuItem();
    exitOption = new JMenuItem();
    preferencesMenu = new JMenu();
    botReplyMenu = new JMenu();
    botReplyAll = new JRadioButtonMenuItem();
    botReplyJustYou = new JRadioButtonMenuItem();
    botReplyNobody = new JRadioButtonMenuItem();
    autoReconnectToggle = new JCheckBoxMenuItem();
    alwaysOnTopToggle = new JCheckBoxMenuItem();
    settingsOption = new JMenuItem();
    toolsMenu = new JMenu();
    startRaffleOption = new JMenuItem();
    startVoteOption = new JMenuItem();
    soundsToggle = new JCheckBoxMenuItem();
    soundDelayMenu = new JMenu();
    soundDelayOffOption = new JRadioButtonMenuItem();
    soundDelay5secOption = new JRadioButtonMenuItem();
    soundDelay10secOption = new JRadioButtonMenuItem();
    soundDelay20secOption = new JRadioButtonMenuItem();
    soundDelayCustomOption = new JRadioButtonMenuItem();
    soundDelayCustomOption.setToolTipText("Set a custom sound delay with \"!setsound (time)\" in chat");
    soundPermissionMenu = new JMenu();
    soundPermEveryoneOption = new JRadioButtonMenuItem();
    soundPermSDMBOption = new JRadioButtonMenuItem();
    soundPermDMBOption = new JRadioButtonMenuItem();
    soundPermModAndBroadOption = new JRadioButtonMenuItem();
    soundPermBroadOption = new JRadioButtonMenuItem();
    manageTextCommandsOption = new JMenuItem();
    runAdMenu = new JMenu();
    timeOption30sec = new JMenuItem();
    timeOption60sec = new JMenuItem();
    timeOption90sec = new JMenuItem();
    timeOption120sec = new JMenuItem();
    timeOption150sec = new JMenuItem();
    timeOption180sec = new JMenuItem();
    updateStatusOption = new JMenuItem();
    subOnlyToggle = new JCheckBoxMenuItem();
    slowModeMenu = new JMenu();
    slowModeOffOption = new JRadioButtonMenuItem();
    slowMode5secOption = new JRadioButtonMenuItem();
    slowMode10secOption = new JRadioButtonMenuItem();
    slowMode15secOption = new JRadioButtonMenuItem();
    slowMode30secOption = new JRadioButtonMenuItem();
    slowModeCustomOption = new JRadioButtonMenuItem();
    slowModeCustomOption.setToolTipText("Set a custom slow mode time with \"/slow (time in seconds)\" in chat");
    helpMenu = new JMenu();
    projectGithubOption = new JMenuItem();
    projectWikiOption = new JMenuItem();
    projectDetailsOption = new JMenuItem();
    channelPane = new DraggableTabbedPane();
    allChatsScroll = new JScrollPane();
    allChats = new JTextPane();
    dankLabel = new JLabel();
    scrollPane1 = new JScrollPane();
    userChat = new JTextArea();
    //======== Botnak ========
    {
        setMinimumSize(new Dimension(640, 404));
        setName("Botnak Control Panel");
        setTitle("Botnak | Please go to Preferences->Settings!");
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        setIconImage(new ImageIcon(getClass().getResource("/image/icon.png")).getImage());
        Container BotnakContentPane = getContentPane();
        //======== menuBar1 ========
        {
            //======== fileMenu ========
            {
                fileMenu.setText("File");
                //---- openBotnakFolderOption ----
                openBotnakFolderOption.setText("Open Botnak Folder");
                openBotnakFolderOption.addActionListener(e -> openBotnakFolderOptionActionPerformed());
                fileMenu.add(openBotnakFolderOption);
                //---- openLogViewerOption ----
                openLogViewerOption.setText("Open Log Viewer");
                openLogViewerOption.addActionListener(e -> openLogViewerOptionActionPerformed());
                //TODO
                openLogViewerOption.setEnabled(false);
                fileMenu.add(openLogViewerOption);
                //---- openSoundsOption ----
                openSoundsOption.setText("Open Sound Directory");
                openSoundsOption.addActionListener(e -> openSoundsOptionActionPerformed());
                fileMenu.add(openSoundsOption);
                fileMenu.addSeparator();
                //---- exitOption ----
                exitOption.setText("Save and Exit");
                exitOption.addActionListener(e -> exitButtonActionPerformed());
                fileMenu.add(exitOption);
            }
            menuBar1.add(fileMenu);
            //======== preferencesMenu ========
            {
                preferencesMenu.setText("Preferences");
                //======== botReplyMenu ========
                {
                    botReplyMenu.setText("Bot Reply");
                    //---- botReplyAll ----
                    botReplyAll.setText("Reply to all");
                    botReplyAll.addActionListener(e -> {
                        if (bot != null) {
                            Response r = bot.parseReplyType("2", Settings.accountManager.getUserAccount().getName());
                            logCurrent(r.getResponseText());
                        }
                    });
                    botReplyMenu.add(botReplyAll);
                    //---- botReplyJustYou ----
                    botReplyJustYou.setText("Reply to you");
                    botReplyJustYou.addActionListener(e -> {
                        if (bot != null) {
                            Response r = bot.parseReplyType("1", Settings.accountManager.getUserAccount().getName());
                            logCurrent(r.getResponseText());
                        }
                    });
                    botReplyMenu.add(botReplyJustYou);
                    //---- botReplyNobody ----
                    botReplyNobody.setText("Reply to none");
                    botReplyNobody.addActionListener(e -> {
                        if (bot != null) {
                            Response r = bot.parseReplyType("0", Settings.accountManager.getUserAccount().getName());
                            logCurrent(r.getResponseText());
                        }
                    });
                    botReplyNobody.setSelected(true);
                    botReplyMenu.add(botReplyNobody);
                }
                preferencesMenu.add(botReplyMenu);
                //---- autoReconnectToggle ----
                autoReconnectToggle.setText("Auto-Reconnect");
                autoReconnectToggle.setSelected(true);
                autoReconnectToggle.addItemListener(this::autoReconnectToggleItemStateChanged);
                preferencesMenu.add(autoReconnectToggle);
                //---- alwaysOnTopToggle ----
                alwaysOnTopToggle.setText("Always On Top");
                alwaysOnTopToggle.setSelected(false);
                alwaysOnTopToggle.addItemListener(this::alwaysOnTopToggleItemStateChanged);
                preferencesMenu.add(alwaysOnTopToggle);
                preferencesMenu.addSeparator();
                //---- settingsOption ----
                settingsOption.setText("Settings...");
                settingsOption.addActionListener(e -> settingsOptionActionPerformed());
                preferencesMenu.add(settingsOption);
            }
            menuBar1.add(preferencesMenu);
            //======== toolsMenu ========
            {
                toolsMenu.setText("Tools");
                //---- startRaffleOption ----
                startRaffleOption.setText("Create Raffle...");
                //TODO
                startRaffleOption.setEnabled(false);
                startRaffleOption.addActionListener(e -> startRaffleOptionActionPerformed());
                toolsMenu.add(startRaffleOption);
                //---- startVoteOption ----
                startVoteOption.setText("Create Vote...");
                //TODO
                startVoteOption.setEnabled(false);
                startVoteOption.addActionListener(e -> startVoteOptionActionPerformed());
                toolsMenu.add(startVoteOption);
                //---- soundsToggle ----
                soundsToggle.setText("Enable Sounds");
                soundsToggle.setSelected(true);
                soundsToggle.addActionListener(e -> soundsToggleItemStateChanged());
                toolsMenu.add(soundsToggle);
                //======== soundDelayMenu ========
                {
                    soundDelayMenu.setText("Sound Delay");
                    //---- soundDelayOffOption ----
                    soundDelayOffOption.setText("None (Off)");
                    soundDelayOffOption.addActionListener(e -> {
                        if (bot != null && bot.getBot() != null) {
                            Response r = SoundEngine.getEngine().setSoundDelay("0");
                            bot.getBot().sendMessage("#" + Settings.accountManager.getUserAccount().getName(), r.getResponseText());
                        }
                    });
                    soundDelayMenu.add(soundDelayOffOption);
                    //---- soundDelay5secOption ----
                    soundDelay5secOption.setText("5 seconds");
                    soundDelay5secOption.addActionListener(e -> {
                        if (bot != null && bot.getBot() != null) {
                            Response r = SoundEngine.getEngine().setSoundDelay("5");
                            bot.getBot().sendMessage("#" + Settings.accountManager.getUserAccount().getName(), r.getResponseText());
                        }
                    });
                    soundDelayMenu.add(soundDelay5secOption);
                    //---- soundDelay10secOption ----
                    soundDelay10secOption.setText("10 seconds");
                    soundDelay10secOption.addActionListener(e -> {
                        if (bot != null && bot.getBot() != null) {
                            Response r = SoundEngine.getEngine().setSoundDelay("10");
                            bot.getBot().sendMessage("#" + Settings.accountManager.getUserAccount().getName(), r.getResponseText());
                        }
                    });
                    soundDelay10secOption.setSelected(true);
                    soundDelayMenu.add(soundDelay10secOption);
                    //---- soundDelay20secOption ----
                    soundDelay20secOption.setText("20 seconds");
                    soundDelay20secOption.addActionListener(e -> {
                        if (bot != null && bot.getBot() != null) {
                            Response r = SoundEngine.getEngine().setSoundDelay("20");
                            bot.getBot().sendMessage("#" + Settings.accountManager.getUserAccount().getName(), r.getResponseText());
                        }
                    });
                    soundDelayMenu.add(soundDelay20secOption);
                    //---- soundDelayCustomOption ----
                    soundDelayCustomOption.setText("Custom (Use chat)");
                    soundDelayCustomOption.setEnabled(false);
                    soundDelayMenu.add(soundDelayCustomOption);
                }
                toolsMenu.add(soundDelayMenu);
                //======== soundPermissionMenu ========
                {
                    soundPermissionMenu.setText("Sound Permission");
                    //---- soundPermEveryoneOption ----
                    soundPermEveryoneOption.setText("Everyone");
                    soundPermEveryoneOption.addActionListener(e -> {
                        if (bot != null && bot.getBot() != null) {
                            Response r = SoundEngine.getEngine().setSoundPermission("0");
                            bot.getBot().sendMessage("#" + Settings.accountManager.getUserAccount().getName(), r.getResponseText());
                        }
                    });
                    soundPermissionMenu.add(soundPermEveryoneOption);
                    //---- soundPermSDMBOption ----
                    soundPermSDMBOption.setText("Subs, Donors, Mods, Broadcaster");
                    soundPermSDMBOption.addActionListener(e -> {
                        if (bot != null && bot.getBot() != null) {
                            Response r = SoundEngine.getEngine().setSoundPermission("1");
                            bot.getBot().sendMessage("#" + Settings.accountManager.getUserAccount().getName(), r.getResponseText());
                        }
                    });
                    soundPermSDMBOption.setSelected(true);
                    soundPermissionMenu.add(soundPermSDMBOption);
                    //---- soundPermDMBOption ----
                    soundPermDMBOption.setText("Donors, Mods, Broadcaster");
                    soundPermDMBOption.addActionListener(e -> {
                        if (bot != null && bot.getBot() != null) {
                            Response r = SoundEngine.getEngine().setSoundPermission("2");
                            bot.getBot().sendMessage("#" + Settings.accountManager.getUserAccount().getName(), r.getResponseText());
                        }
                    });
                    soundPermissionMenu.add(soundPermDMBOption);
                    //---- soundPermModAndBroadOption ----
                    soundPermModAndBroadOption.setText("Mods and Broadcaster Only");
                    soundPermModAndBroadOption.addActionListener(e -> {
                        if (bot != null && bot.getBot() != null) {
                            Response r = SoundEngine.getEngine().setSoundPermission("3");
                            bot.getBot().sendMessage("#" + Settings.accountManager.getUserAccount().getName(), r.getResponseText());
                        }
                    });
                    soundPermissionMenu.add(soundPermModAndBroadOption);
                    //---- soundPermBroadOption ----
                    soundPermBroadOption.setText("Broadcaster Only");
                    soundPermBroadOption.addActionListener(e -> {
                        if (bot != null && bot.getBot() != null) {
                            Response r = SoundEngine.getEngine().setSoundPermission("4");
                            bot.getBot().sendMessage("#" + Settings.accountManager.getUserAccount().getName(), r.getResponseText());
                        }
                    });
                    soundPermissionMenu.add(soundPermBroadOption);
                }
                toolsMenu.add(soundPermissionMenu);
                //---- manageTextCommandsOption ----
                manageTextCommandsOption.setText("Manage Text Commands...");
                //TODO
                manageTextCommandsOption.setEnabled(false);
                manageTextCommandsOption.addActionListener(e -> manageTextCommandsOptionActionPerformed());
                toolsMenu.add(manageTextCommandsOption);
                toolsMenu.addSeparator();
                //======== runAdMenu ========
                {
                    runAdMenu.setText("Run Ad");
                    //---- timeOption30sec ----
                    timeOption30sec.setText("30 sec");
                    timeOption30sec.addActionListener(e -> {
                        if (bot != null && bot.getBot() != null) {
                            Response r = bot.playAdvert(Settings.accountManager.getUserAccount().getKey(), "30", Settings.accountManager.getUserAccount().getName());
                            bot.getBot().sendMessage("#" + Settings.accountManager.getUserAccount().getName(), r.getResponseText());
                            ThreadEngine.submit(() -> {
                                try {
                                    Thread.sleep(30000);
                                    logCurrent("The 30-second advertisement has ended.");
                                } catch (InterruptedException ignored) {
                                }
                            });
                        }
                    });
                    runAdMenu.add(timeOption30sec);
                    //---- timeOption60sec ----
                    timeOption60sec.setText("1 min");
                    timeOption60sec.addActionListener(e -> {
                        if (bot != null && bot.getBot() != null) {
                            Response r = bot.playAdvert(Settings.accountManager.getUserAccount().getKey(), "1m", Settings.accountManager.getUserAccount().getName());
                            bot.getBot().sendMessage("#" + Settings.accountManager.getUserAccount().getName(), r.getResponseText());
                            ThreadEngine.submit(() -> {
                                try {
                                    Thread.sleep(60000);
                                    logCurrent("The 1-minute advertisement has ended.");
                                } catch (InterruptedException ignored) {
                                }
                            });
                        }
                    });
                    runAdMenu.add(timeOption60sec);
                    //---- timeOption90sec ----
                    timeOption90sec.setText("1 min 30 sec");
                    timeOption90sec.addActionListener(e -> {
                        if (bot != null && bot.getBot() != null) {
                            Response r = bot.playAdvert(Settings.accountManager.getUserAccount().getKey(), "1m30s", Settings.accountManager.getUserAccount().getName());
                            bot.getBot().sendMessage("#" + Settings.accountManager.getUserAccount().getName(), r.getResponseText());
                            ThreadEngine.submit(() -> {
                                try {
                                    Thread.sleep(90000);
                                    logCurrent("The 1-minute 30-second advertisement has ended.");
                                } catch (InterruptedException ignored) {
                                }
                            });
                        }
                    });
                    runAdMenu.add(timeOption90sec);
                    //---- timeOption120sec ----
                    timeOption120sec.setText("2 min");
                    timeOption120sec.addActionListener(e -> {
                        if (bot != null && bot.getBot() != null) {
                            Response r = bot.playAdvert(Settings.accountManager.getUserAccount().getKey(), "2m", Settings.accountManager.getUserAccount().getName());
                            bot.getBot().sendMessage("#" + Settings.accountManager.getUserAccount().getName(), r.getResponseText());
                            ThreadEngine.submit(() -> {
                                try {
                                    Thread.sleep(120000);
                                    logCurrent("The 2 minute advertisement has ended.");
                                } catch (InterruptedException ignored) {
                                }
                            });
                        }
                    });
                    runAdMenu.add(timeOption120sec);
                    //---- timeOption150sec ----
                    timeOption150sec.setText("2 min 30 sec");
                    timeOption150sec.addActionListener(e -> {
                        if (bot != null && bot.getBot() != null) {
                            Response r = bot.playAdvert(Settings.accountManager.getUserAccount().getKey(), "2m30s", Settings.accountManager.getUserAccount().getName());
                            bot.getBot().sendMessage("#" + Settings.accountManager.getUserAccount().getName(), r.getResponseText());
                            ThreadEngine.submit(() -> {
                                try {
                                    Thread.sleep(150000);
                                    logCurrent("The 2 minute 30 second advertisement has ended.");
                                } catch (InterruptedException ignored) {
                                }
                            });
                        }
                    });
                    runAdMenu.add(timeOption150sec);
                    //---- timeOption180sec ----
                    timeOption180sec.setText("3 min");
                    timeOption180sec.addActionListener(e -> {
                        if (bot != null && bot.getBot() != null) {
                            Response r = bot.playAdvert(Settings.accountManager.getUserAccount().getKey(), "3m", Settings.accountManager.getUserAccount().getName());
                            bot.getBot().sendMessage("#" + Settings.accountManager.getUserAccount().getName(), r.getResponseText());
                            ThreadEngine.submit(() -> {
                                try {
                                    Thread.sleep(180000);
                                    logCurrent("The 3 minute advertisement has ended.");
                                } catch (InterruptedException ignored) {
                                }
                            });
                        }
                    });
                    runAdMenu.add(timeOption180sec);
                }
                toolsMenu.add(runAdMenu);
                //---- updateStatusOption ----
                updateStatusOption.setText("Update Status...");
                updateStatusOption.addActionListener(e -> updateStatusOptionActionPerformed());
                toolsMenu.add(updateStatusOption);
                //---- subOnlyToggle ----
                subOnlyToggle.setText("Sub-only Chat");
                subOnlyToggle.addActionListener(e -> subOnlyToggleItemStateChanged());
                toolsMenu.add(subOnlyToggle);
                //======== slowModeMenu ========
                {
                    slowModeMenu.setText("Slow Mode");
                    //---- slowModeOffOption ----
                    slowModeOffOption.setText("Off");
                    slowModeOffOption.addActionListener(e -> {
                        if (viewer != null) {
                            viewer.getViewer().sendRawMessage("#" + Settings.accountManager.getUserAccount().getName(), "/slowoff");
                        }
                    });
                    slowModeOffOption.setSelected(true);
                    slowModeMenu.add(slowModeOffOption);
                    //---- slowMode5secOption ----
                    slowMode5secOption.setText("5 seconds");
                    slowMode5secOption.addActionListener(e -> {
                        if (viewer != null) {
                            viewer.getViewer().sendRawMessage("#" + Settings.accountManager.getUserAccount().getName(), "/slow 5");
                        }
                    });
                    slowModeMenu.add(slowMode5secOption);
                    //---- slowMode10secOption ----
                    slowMode10secOption.setText("10 seconds");
                    slowMode10secOption.addActionListener(e -> {
                        if (viewer != null) {
                            viewer.getViewer().sendRawMessage("#" + Settings.accountManager.getUserAccount().getName(), "/slow 10");
                        }
                    });
                    slowModeMenu.add(slowMode10secOption);
                    //---- slowMode15secOption ----
                    slowMode15secOption.setText("15 seconds");
                    slowMode15secOption.addActionListener(e -> {
                        if (viewer != null) {
                            viewer.getViewer().sendRawMessage("#" + Settings.accountManager.getUserAccount().getName(), "/slow 15");
                        }
                    });
                    slowModeMenu.add(slowMode15secOption);
                    //---- slowMode30secOption ----
                    slowMode30secOption.setText("30 seconds");
                    slowMode30secOption.addActionListener(e -> {
                        if (viewer != null) {
                            viewer.getViewer().sendRawMessage("#" + Settings.accountManager.getUserAccount().getName(), "/slow 30");
                        }
                    });
                    slowModeMenu.add(slowMode30secOption);
                    //---- slowModeCustomOption ----
                    slowModeCustomOption.setText("Custom (use chat)");
                    slowModeCustomOption.setEnabled(false);
                    slowModeMenu.add(slowModeCustomOption);
                }
                toolsMenu.add(slowModeMenu);
            }
            menuBar1.add(toolsMenu);
            //======== helpMenu ========
            {
                helpMenu.setText("Help");
                //---- projectGithubOption ----
                projectGithubOption.setText("Botnak Github");
                projectGithubOption.addActionListener(e -> projectGithubOptionActionPerformed());
                helpMenu.add(projectGithubOption);
                //---- projectWikiOption ----
                projectWikiOption.setText("Botnak Wiki");
                projectWikiOption.addActionListener(e -> projectWikiOptionActionPerformed());
                helpMenu.add(projectWikiOption);
                JMenuItem bugReport = new JMenuItem("Report an Issue");
                bugReport.addActionListener(e -> Utils.openWebPage("https://github.com/Gocnak/Botnak/issues/new"));
                helpMenu.add(bugReport);
                helpMenu.addSeparator();
                //---- projectDetailsOption ----
                projectDetailsOption.setText("About...");
                projectDetailsOption.addActionListener(e -> projectDetailsOptionActionPerformed());
                helpMenu.add(projectDetailsOption);
            }
            menuBar1.add(helpMenu);
        }
        setJMenuBar(menuBar1);
        //======== channelPane ========
        {
            channelPane.setFocusable(false);
            channelPane.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
            channelPane.setAutoscrolls(true);
            channelPane.addChangeListener(Constants.tabListener);
            channelPane.addMouseListener(Constants.tabListener);
            //======== allChatsScroll ========
            {
                allChatsScroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
                //---- allChats ----
                allChats.setEditable(false);
                allChats.setForeground(Color.white);
                allChats.setBackground(Color.black);
                allChats.setFont(new Font("Calibri", Font.PLAIN, 16));
                allChats.setMargin(new Insets(0, 0, 0, 0));
                allChats.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
                allChats.addMouseListener(Constants.listenerURL);
                allChats.addMouseListener(Constants.listenerName);
                allChats.setEditorKit(Constants.wrapEditorKit);
                allChatsScroll.setViewportView(allChats);
            }
            channelPane.addTab("System Logs", allChatsScroll);
            //---- dankLabel ----
            dankLabel.setText("Dank memes");
            channelPane.addTab("+", dankLabel);
            channelPane.setEnabledAt(channelPane.getTabCount() - 1, false);
            channelPane.addMouseListener(new NewTabListener());
        }
        //======== scrollPane1 ========
        {
            scrollPane1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
            //---- userChat ----
            userChat.setFont(new Font("Consolas", Font.PLAIN, 12));
            userChat.setLineWrap(true);
            userChat.setWrapStyleWord(true);
            userChat.addKeyListener(new ListenerUserChat(userChat));
            scrollPane1.setViewportView(userChat);
        }
        GroupLayout BotnakContentPaneLayout = new GroupLayout(BotnakContentPane);
        BotnakContentPane.setLayout(BotnakContentPaneLayout);
        BotnakContentPaneLayout.setHorizontalGroup(BotnakContentPaneLayout.createParallelGroup().addComponent(channelPane, GroupLayout.DEFAULT_SIZE, 0, Short.MAX_VALUE).addComponent(scrollPane1));
        BotnakContentPaneLayout.setVerticalGroup(BotnakContentPaneLayout.createParallelGroup().addGroup(BotnakContentPaneLayout.createSequentialGroup().addComponent(channelPane, GroupLayout.DEFAULT_SIZE, 393, Short.MAX_VALUE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(scrollPane1, GroupLayout.PREFERRED_SIZE, 41, GroupLayout.PREFERRED_SIZE)));
        addComponentListener(new ComponentAdapter() {

            @Override
            public void componentResized(ComponentEvent e) {
                if (channelPane != null) {
                    channelPane.scrollDownPanes();
                }
            }
        });
        addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent e) {
                exitButtonActionPerformed();
            }
        });
        pack();
        setLocationRelativeTo(getOwner());
    }
    //---- botReplyGroup ----
    ButtonGroup botReplyGroup = new ButtonGroup();
    botReplyGroup.add(botReplyAll);
    botReplyGroup.add(botReplyJustYou);
    botReplyGroup.add(botReplyNobody);
    //---- soundDelayGroup ----
    ButtonGroup soundDelayGroup = new ButtonGroup();
    soundDelayGroup.add(soundDelayOffOption);
    soundDelayGroup.add(soundDelay5secOption);
    soundDelayGroup.add(soundDelay10secOption);
    soundDelayGroup.add(soundDelay20secOption);
    soundDelayGroup.add(soundDelayCustomOption);
    //---- soundPermissionGroup ----
    ButtonGroup soundPermissionGroup = new ButtonGroup();
    soundPermissionGroup.add(soundPermEveryoneOption);
    soundPermissionGroup.add(soundPermSDMBOption);
    soundPermissionGroup.add(soundPermDMBOption);
    soundPermissionGroup.add(soundPermModAndBroadOption);
    soundPermissionGroup.add(soundPermBroadOption);
    //---- slowModeGroup ----
    ButtonGroup slowModeGroup = new ButtonGroup();
    slowModeGroup.add(slowModeOffOption);
    slowModeGroup.add(slowMode5secOption);
    slowModeGroup.add(slowMode10secOption);
    slowModeGroup.add(slowMode15secOption);
    slowModeGroup.add(slowMode30secOption);
    slowModeGroup.add(slowModeCustomOption);
// JFormDesigner - End of component initialization  //GEN-END:initComponents
}
Also used : IRCBot(irc.IRCBot) Heartbeat(thread.heartbeat.Heartbeat) IRCViewer(irc.IRCViewer) DraggableTabbedPane(gui.DraggableTabbedPane) SimpleAttributeSet(javax.swing.text.SimpleAttributeSet) StyleConstants(javax.swing.text.StyleConstants) Response(util.Response) Constants(util.Constants) Message(irc.message.Message) ArrayList(java.util.ArrayList) FaceManager(face.FaceManager) BotnakTrayIcon(gui.BotnakTrayIcon) Utils(util.Utils) Map(java.util.Map) MessageQueue(irc.message.MessageQueue) TabPulse(thread.TabPulse) Command(util.comm.Command) SoundEngine(sound.SoundEngine) ListenerUserChat(gui.listeners.ListenerUserChat) PrintWriter(java.io.PrintWriter) CombinedChatPane(gui.CombinedChatPane) StringWriter(java.io.StringWriter) Settings(util.settings.Settings) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) File(java.io.File) ThreadEngine(thread.ThreadEngine) java.awt(java.awt) ConsoleCommand(util.comm.ConsoleCommand) java.awt.event(java.awt.event) NewTabListener(gui.listeners.NewTabListener) ChatPane(gui.ChatPane) javax.swing(javax.swing) NewTabListener(gui.listeners.NewTabListener) DraggableTabbedPane(gui.DraggableTabbedPane) Response(util.Response) ListenerUserChat(gui.listeners.ListenerUserChat)

Example 8 with Response

use of util.Response in project Botnak by Gocnak.

the class GUIStatus method saveButtonActionPerformed.

private void saveButtonActionPerformed() {
    if (getChannel() == null || getKey() == null) {
        setTitle("Please Login First!");
        return;
    }
    playingGameToggle.setSelected("".equals(gameText.getText()));
    Response r = APIRequests.Twitch.setStatusOfStream(getKey().getKey(), getChannel(), titleText.getText(), gameText.isEnabled() ? gameText.getText() : "");
    if (r.isSuccessful()) {
        setTitle("Status successfully updated!");
        if (!gameText.isEnabled())
            gameText.setText("");
    } else {
        setTitle("Status failed to update!");
    }
    ThreadEngine.submit(() -> {
        try {
            Thread.sleep(5000);
            setTitle("Change Stream Status");
        } catch (InterruptedException ignored) {
        }
    });
}
Also used : Response(util.Response)

Example 9 with Response

use of util.Response in project Botnak by Gocnak.

the class FaceManager method handleFace.

/**
     * Either adds a face to the image map or changes a face to another variant.
     * If the face image size is too big, it is scaled (using Scalr) to fit the 26 pixel height limit.
     *
     * @param s The string from the chat.
     * @return The response of the method.
     */
public static Response handleFace(String s) {
    Response toReturn = new Response();
    boolean localCheck = ("".equals(Settings.defaultFaceDir.getValue()) || Settings.defaultFaceDir.getValue().equals("null"));
    String[] split = s.split(" ");
    String command = split[0];
    //name of the face, used for file name, and if regex isn't supplied, becomes the regex
    String name = split[1];
    String regex;
    //or the URL...
    String file;
    if (command.equalsIgnoreCase("addface")) {
        if (faceMap.containsKey(name)) {
            //!addface is not !changeface, remove the face first or do changeface
            toReturn.setResponseText("Failed to add face, " + name + " already exists!");
            return toReturn;
        }
        if (split.length == 4) {
            //!addface <name> <regex> <URL or file>
            regex = split[2];
            //regex check
            if (!Utils.checkRegex(regex)) {
                toReturn.setResponseText("Failed to add face, the supplied regex does not compile!");
                return toReturn;
            }
            //name check (for saving the file)
            if (Utils.checkName(name)) {
                toReturn.setResponseText("Failed to add face, the supplied name is not Windows-friendly!");
                return toReturn;
            }
            file = split[3];
            if (file.startsWith("http")) {
                //online
                return downloadFace(file, Settings.faceDir.getAbsolutePath(), Utils.setExtension(name, ".png"), regex, //save locally
                FACE_TYPE.NORMAL_FACE);
            } else {
                //local
                if (Utils.checkName(file) || localCheck) {
                    if (!localCheck)
                        toReturn.setResponseText("Failed to add face, the supplied name is not Windows-friendly!");
                    else
                        toReturn.setResponseText("Failed to add face, the local directory is not set properly!");
                    return toReturn;
                }
                return downloadFace(new File(Settings.defaultFaceDir.getValue() + File.separator + file), Settings.faceDir.getAbsolutePath(), Utils.setExtension(name, ".png"), regex, FACE_TYPE.NORMAL_FACE);
            }
        } else if (split.length == 3) {
            //!addface <name> <URL or file> (name will be the regex, case sensitive)
            file = split[2];
            //regex (this should never be a problem, however...)
            if (!Utils.checkRegex(name)) {
                toReturn.setResponseText("Failed to add face, the supplied name is not a valid regex!");
                return toReturn;
            }
            //name check (for saving the file)
            if (Utils.checkName(name)) {
                toReturn.setResponseText("Failed to add face, the supplied name is not Windows-friendly!");
                return toReturn;
            }
            if (file.startsWith("http")) {
                //online
                return downloadFace(file, Settings.faceDir.getAbsolutePath(), Utils.setExtension(name, ".png"), name, //name is regex, so case sensitive
                FACE_TYPE.NORMAL_FACE);
            } else {
                //local
                if (Utils.checkName(file) || localCheck) {
                    if (!localCheck)
                        toReturn.setResponseText("Failed to add face, the supplied name is not Windows-friendly!");
                    else
                        toReturn.setResponseText("Failed to add face, the local directory is not set properly!");
                    return toReturn;
                }
                return downloadFace(new File(Settings.defaultFaceDir.getValue() + File.separator + file), Settings.faceDir.getAbsolutePath(), Utils.setExtension(name, ".png"), //<- this will be the regex, so case sensitive
                name, FACE_TYPE.NORMAL_FACE);
            }
        }
    } else if (command.equalsIgnoreCase("changeface")) {
        //replace entirely
        if (faceMap.containsKey(name)) {
            //!changeface is not !addface, the map MUST contain it
            if (split.length == 5) {
                //!changeface <name> 2 <new regex> <new URL/file>
                try {
                    //gotta make sure the number is the ^
                    if (Integer.parseInt(split[2]) != 2) {
                        toReturn.setResponseText("Failed to change face, make sure to designate the \"2\" in the command!");
                        return toReturn;
                    }
                } catch (Exception e) {
                    toReturn.setResponseText("Failed to change face, the indicator number cannot be parsed!");
                    return toReturn;
                }
                regex = split[3];
                //regex check
                if (!Utils.checkRegex(regex)) {
                    toReturn.setResponseText("Failed to add face, the supplied regex does not compile!");
                    return toReturn;
                }
                //name check (for saving the file)
                if (Utils.checkName(name)) {
                    toReturn.setResponseText("Failed to add face, the supplied name is not Windows-friendly!");
                    return toReturn;
                }
                file = split[4];
                if (file.startsWith("http")) {
                    //online
                    return downloadFace(file, Settings.faceDir.getAbsolutePath(), Utils.setExtension(name, ".png"), regex, //save locally
                    FACE_TYPE.NORMAL_FACE);
                } else {
                    //local
                    if (Utils.checkName(file) || localCheck) {
                        if (!localCheck)
                            toReturn.setResponseText("Failed to add face, the supplied name is not Windows-friendly!");
                        else
                            toReturn.setResponseText("Failed to add face, the local directory is not set properly!");
                        return toReturn;
                    }
                    return downloadFace(new File(Settings.defaultFaceDir.getValue() + File.separator + file), Settings.faceDir.getAbsolutePath(), Utils.setExtension(name, ".png"), //< this will be the regex, so case sensitive
                    regex, FACE_TYPE.NORMAL_FACE);
                }
            } else if (split.length == 4) {
                //!changeface <name> <numb> <newregex>|<new URL or file>
                int type;
                try {
                    //gotta check the number
                    type = Integer.parseInt(split[2]);
                } catch (Exception e) {
                    toReturn.setResponseText("Failed to change face, the indicator number cannot be parsed!");
                    return toReturn;
                }
                Face face = faceMap.get(name);
                if (type == 0) {
                    //regex change; !changeface <name> 0 <new regex>
                    regex = split[3];
                    if (Utils.checkRegex(regex)) {
                        faceMap.put(name, new Face(regex, face.getFilePath()));
                        toReturn.setResponseText("Successfully changed the regex for face: " + name + " !");
                        toReturn.wasSuccessful();
                    } else {
                        toReturn.setResponseText("Failed to change the regex, the new regex could not be compiled!");
                    }
                } else if (type == 1) {
                    //file change; !changeface <name> 1 <new URL/file>
                    file = split[3];
                    if (file.startsWith("http")) {
                        //online
                        return downloadFace(file, Settings.faceDir.getAbsolutePath(), Utils.setExtension(name, ".png"), face.getRegex(), //save locally
                        FACE_TYPE.NORMAL_FACE);
                    } else {
                        //local
                        if (Utils.checkName(file) || localCheck) {
                            if (!localCheck)
                                toReturn.setResponseText("Failed to add face, the supplied name is not Windows-friendly!");
                            else
                                toReturn.setResponseText("Failed to add face, the local directory is not set properly!");
                            return toReturn;
                        }
                        return downloadFace(new File(Settings.defaultFaceDir.getValue() + File.separator + file), Settings.faceDir.getAbsolutePath(), Utils.setExtension(name, ".png"), face.getRegex(), FACE_TYPE.NORMAL_FACE);
                    }
                }
            }
        } else {
            toReturn.setResponseText("Failed to change face, the face " + name + " does not exist!");
        }
    }
    return toReturn;
}
Also used : Response(util.Response) File(java.io.File)

Example 10 with Response

use of util.Response in project Botnak by Gocnak.

the class SoundEngine method setSoundPermission.

public Response setSoundPermission(String first) {
    Response toReturn = new Response();
    try {
        int perm = Integer.parseInt(first);
        if (perm > -1 && perm < 5) {
            setPermission(perm);
            toReturn.wasSuccessful();
            toReturn.setResponseText("Sound permission successfully changed to: " + Utils.getPermissionString(perm));
        } else {
            toReturn.setResponseText("Failed to set sound permission, the permission must be from 0 to 4!");
        }
    } catch (Exception ignored) {
        toReturn.setResponseText("Failed to set sound permission, usage: !setsoundperm (permission)");
    }
    return toReturn;
}
Also used : Response(util.Response)

Aggregations

Response (util.Response)14 File (java.io.File)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 FaceManager (face.FaceManager)1 BotnakTrayIcon (gui.BotnakTrayIcon)1 ChatPane (gui.ChatPane)1 CombinedChatPane (gui.CombinedChatPane)1 DraggableTabbedPane (gui.DraggableTabbedPane)1 ListenerUserChat (gui.listeners.ListenerUserChat)1 NewTabListener (gui.listeners.NewTabListener)1 IRCBot (irc.IRCBot)1 IRCViewer (irc.IRCViewer)1 Message (irc.message.Message)1 MessageQueue (irc.message.MessageQueue)1 java.awt (java.awt)1 java.awt.event (java.awt.event)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1