Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.bubbles.twitchbot.gui.bottabs;
- import java.applet.Applet;
- import java.applet.AudioClip;
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.util.ArrayList;
- import javax.swing.AbstractAction;
- import javax.swing.Action;
- import javax.swing.JButton;
- import javax.swing.JLabel;
- import javax.swing.JScrollPane;
- import javax.swing.JTextArea;
- import javax.swing.JTextPane;
- import javax.swing.KeyStroke;
- import javax.swing.SpringLayout;
- import javax.swing.text.BadLocationException;
- import javax.swing.text.DefaultCaret;
- import javax.swing.text.Style;
- import javax.swing.text.StyleConstants;
- import javax.swing.text.StyledDocument;
- import me.bubbles.twitchbot.TwitchBot;
- import me.bubbles.twitchbot.command.PermissionLevel;
- import me.bubbles.twitchbot.gui.BotTab;
- import me.bubbles.twitchbot.gui.BotWindow;
- import me.bubbles.twitchbot.gui.bottabs.ConsoleTab.Level;
- import me.bubbles.twitchbot.utils.BotUser;
- import me.bubbles.twitchbot.utils.UserUtils;
- public class ChatTab extends BotTab {
- private static final long serialVersionUID = 1L;
- private JScrollPane scrollPane;
- private JTextArea txtrMessage;
- private JScrollPane scrollPane_1;
- private static JTextArea txtrViewers;
- private static JTextPane txtChat;
- private static StyledDocument chat;
- private static Style style;
- private static JLabel lblViewers;
- private static AudioClip clip;
- /**
- * Create the panel.
- */
- public ChatTab() {
- clip = Applet.newAudioClip(BotWindow.class.getResource("/me/bubbles/twitchbot/res/notify.wav"));
- setBackground(Color.DARK_GRAY);
- SpringLayout springLayout = new SpringLayout();
- setLayout(springLayout);
- JButton btnSend = new JButton("Send");
- btnSend.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- String message = txtrMessage.getText().replace(" i ", " I ");
- output(BotWindow.getTwitchBot().getBotName(), message);
- BotWindow.getTwitchBot().messageChannel(message);
- txtrMessage.setText("");
- txtrMessage.requestFocus();
- }
- });
- btnSend.setBackground(Color.LIGHT_GRAY);
- springLayout.putConstraint(SpringLayout.SOUTH, btnSend, -10, SpringLayout.SOUTH, this);
- springLayout.putConstraint(SpringLayout.EAST, btnSend, -10, SpringLayout.EAST, this);
- add(btnSend);
- scrollPane = new JScrollPane();
- springLayout.putConstraint(SpringLayout.NORTH, scrollPane, -30, SpringLayout.SOUTH, this);
- springLayout.putConstraint(SpringLayout.WEST, scrollPane, 10, SpringLayout.WEST, this);
- springLayout.putConstraint(SpringLayout.SOUTH, scrollPane, -10, SpringLayout.SOUTH, this);
- springLayout.putConstraint(SpringLayout.EAST, scrollPane, -10, SpringLayout.WEST, btnSend);
- add(scrollPane);
- txtrMessage = new JTextArea();
- txtrMessage.setForeground(Color.DARK_GRAY);
- txtrMessage.setBackground(Color.LIGHT_GRAY);
- txtrMessage.setWrapStyleWord(true);
- txtrMessage.setLineWrap(true);
- scrollPane.setViewportView(txtrMessage);
- scrollPane_1 = new JScrollPane();
- springLayout.putConstraint(SpringLayout.WEST, scrollPane_1, 10, SpringLayout.WEST, this);
- springLayout.putConstraint(SpringLayout.SOUTH, scrollPane_1, -10, SpringLayout.NORTH, scrollPane);
- springLayout.putConstraint(SpringLayout.EAST, scrollPane_1, -218, SpringLayout.EAST, this);
- add(scrollPane_1);
- txtChat = new JTextPane();
- txtChat.setBackground(Color.LIGHT_GRAY);
- chat = txtChat.getStyledDocument();
- txtChat.setFont(new Font("Serif", Font.BOLD, 12));
- txtChat.setEditable(false);
- txtChat.setCaretPosition(txtChat.getDocument().getLength());
- scrollPane_1.setViewportView(txtChat);
- JLabel lblChat = new JLabel("Chat");
- springLayout.putConstraint(SpringLayout.NORTH, scrollPane_1, 6, SpringLayout.SOUTH, lblChat);
- springLayout.putConstraint(SpringLayout.NORTH, lblChat, 0, SpringLayout.NORTH, this);
- springLayout.putConstraint(SpringLayout.WEST, lblChat, 0, SpringLayout.WEST, scrollPane);
- lblChat.setLabelFor(this);
- lblChat.setForeground(new Color(0, 0, 0));
- lblChat.setBackground(Color.LIGHT_GRAY);
- add(lblChat);
- txtrViewers = new JTextArea();
- txtrViewers.setEditable(false);
- txtrViewers.setBackground(Color.LIGHT_GRAY);
- lblViewers = new JLabel("Viewers Followers: " + TwitchBot.followers.size());
- springLayout.putConstraint(SpringLayout.NORTH, lblViewers, 0, SpringLayout.NORTH, lblChat);
- springLayout.putConstraint(SpringLayout.EAST, lblViewers, -90, SpringLayout.EAST, this);
- add(lblViewers);
- JScrollPane scrollPane_2 = new JScrollPane();
- springLayout.putConstraint(SpringLayout.NORTH, scrollPane_2, 20, SpringLayout.NORTH, this);
- springLayout.putConstraint(SpringLayout.WEST, scrollPane_2, 6, SpringLayout.EAST, scrollPane_1);
- springLayout.putConstraint(SpringLayout.SOUTH, scrollPane_2, -6, SpringLayout.NORTH, btnSend);
- springLayout.putConstraint(SpringLayout.EAST, scrollPane_2, -10, SpringLayout.EAST, this);
- scrollPane_2.add(txtrViewers);
- scrollPane_2.setViewportView(txtrViewers);
- add(scrollPane_2);
- DefaultCaret caret = (DefaultCaret) txtChat.getCaret();
- caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
- caret.setLocation(0, chat.getLength());
- DefaultCaret caret_1 = (DefaultCaret) txtrMessage.getCaret();
- caret_1.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
- txtrMessage.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "sendMessage");
- Action sendMessage = new AbstractAction() {
- private static final long serialVersionUID = 1L;
- public void actionPerformed(ActionEvent arg0) {
- String message = txtrMessage.getText().replace(" i ", " I ");
- output(BotWindow.getTwitchBot().getBotName(), message);
- BotWindow.getTwitchBot().messageChannel(message);
- BotWindow.getTwitchBot().refreshViewers();
- txtrMessage.setText("");
- txtrMessage.requestFocus();
- }
- };
- txtrMessage.getActionMap().put("sendMessage", sendMessage);
- }
- static int i = 0;
- public static void output(String name, String message) {
- message.replace("Kappa", "PLACE HOLDER");
- if (BotWindow.getTwitchBot().inStream()) {
- if (message.toLowerCase().contains(BotWindow.getTwitchBot().getBotName().toLowerCase())
- || message.toLowerCase().contains(BotWindow.getTwitchBot().getChannel(false).toLowerCase())) {
- clip.play();
- }
- if (i == 0) {
- style = txtChat.addStyle("I'm a Style", null);
- StyleConstants.setForeground(style, Color.GRAY);
- StyleConstants.isBold(style);
- try {
- chat.insertString(chat.getLength(), "[" + UserUtils.capitalizeName(name) + "]: " + message + "\n",
- style);
- } catch (BadLocationException e) {
- }
- i = 1;
- } else {
- style = txtChat.addStyle("I'm a Style", null);
- StyleConstants.setForeground(style, Color.DARK_GRAY);
- StyleConstants.isBold(style);
- try {
- chat.insertString(chat.getLength(), "[" + UserUtils.capitalizeName(name) + "]: " + message + "\n",
- style);
- } catch (BadLocationException e) {
- }
- i = 0;
- }
- } else
- ConsoleTab.output(Level.Alert, "You must be in a channel before you can chat!");
- }
- public static void viewers(ArrayList<BotUser> viewers) {
- txtrViewers.setText("");
- lblViewers.setText("Viewers: " + viewers.size() + " Followers: " + TwitchBot.followers.size());
- for (BotUser user : TwitchBot.viewers) {
- if (user.getPermissionLevel() == PermissionLevel.MOD) {
- if (user.getUsername().equalsIgnoreCase(BotWindow.getTwitchBot().getChannel(false))) {
- txtrViewers.append(UserUtils.capitalizeName(user.getUsername()) + " - Streamer\n");
- } else {
- if (TwitchBot.followers.contains(user.getUsername())) {
- txtrViewers.append(UserUtils.capitalizeName(user.getUsername()) + "- Following - Mod\n");
- } else {
- txtrViewers.append(UserUtils.capitalizeName(user.getUsername()) + "- Mod\n");
- }
- }
- } else {
- if (TwitchBot.followers.contains(user.getUsername().toLowerCase())) {
- txtrViewers.append(UserUtils.capitalizeName(user.getUsername()) + " - Following\n");
- } else {
- txtrViewers.append(UserUtils.capitalizeName(user.getUsername()) + "\n");
- }
- }
- }
- }
- public void load() {
- this.setVisible(true);
- txtrMessage.requestFocus();
- }
- public void unload() {
- this.setVisible(false);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement