Search in sources :

Example 1 with Message

use of irc.message.Message in project Botnak by Gocnak.

the class GUIMain method log.

/**
     * Logs a message to the chat console under all white, SYS username.
     * This should only be used for serious reports, like exception reporting and
     * other status updates.
     *
     * @param message The message to log.
     */
public static void log(Object message) {
    if (message == null)
        return;
    String toPrint;
    // Moved here to allow for changing message type to something like error for throwables
    Message.MessageType type = Message.MessageType.LOG_MESSAGE;
    if (message instanceof Throwable) {
        Throwable t = (Throwable) message;
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        t.printStackTrace(pw);
        // stack trace as a string
        toPrint = sw.toString();
        pw.close();
    } else {
        // Not a throwable.. Darn strings
        toPrint = message.toString();
    }
    if (chatPanes == null || chatPanes.isEmpty()) {
        //allowing for errors to at least go somewhere
        System.out.println(toPrint == null ? "Null toPrint!" : toPrint);
    } else {
        MessageQueue.addMessage(new Message(toPrint, type));
    }
}
Also used : Message(irc.message.Message) StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter)

Example 2 with Message

use of irc.message.Message in project Botnak by Gocnak.

the class ChatPane method insertUpdate.

@Override
public void insertUpdate(DocumentEvent e) {
    maybeScrollToBottom();
    if (Settings.cleanupChat.getValue()) {
        try {
            if (e.getDocument().getText(e.getOffset(), e.getLength()).contains("\n")) {
                cleanupCounter++;
            }
        } catch (Exception ignored) {
        }
        if (cleanupCounter > Settings.chatMax.getValue()) {
            /* cleanup every n messages */
            if (!messageOut) {
                MessageQueue.addMessage(new Message().setType(Message.MessageType.CLEAR_TEXT).setExtra(this));
                messageOut = true;
            }
        }
    }
}
Also used : Message(irc.message.Message)

Example 3 with Message

use of irc.message.Message in project Botnak by Gocnak.

the class ChatPane method onIconMessage.

/**
     * Handles inserting icons before and after the message.
     *
     * @param m      The message itself.
     * @param status IconEnum.Subscriber for sub message, else pass Donor#getDonationStatus(d#getAmount())
     */
public void onIconMessage(MessageWrapper m, IconEnum status) {
    try {
        Message message = m.getLocal();
        print(m, "\n", GUIMain.norm);
        for (int i = 0; i < 3; i++) {
            insertIcon(m, status, (status == IconEnum.SUBSCRIBER ? message.getChannel() : null));
        }
        print(m, " " + message.getContent() + (status == IconEnum.SUBSCRIBER ? (" (" + (subCount + 1) + ") ") : " "), GUIMain.norm);
        for (int i = 0; i < 3; i++) {
            insertIcon(m, status, (status == IconEnum.SUBSCRIBER ? message.getChannel() : null));
        }
    } catch (Exception e) {
        GUIMain.log(e);
    }
    //checking for repeat messages
    boolean shouldIncrement = ((status == IconEnum.SUBSCRIBER) && (m.getLocal().getExtra() == null));
    if (shouldIncrement)
        subCount++;
}
Also used : Message(irc.message.Message)

Example 4 with Message

use of irc.message.Message in project Botnak by Gocnak.

the class ChatPane method onMessage.

/**
     * This is the main message method when somebody sends a message to the channel.
     *
     * @param m The message from the chat.
     */
public void onMessage(MessageWrapper m, boolean showChannel) {
    if (textPane == null)
        return;
    Message message = m.getLocal();
    String sender = message.getSender().toLowerCase();
    String channel = message.getChannel();
    String mess = message.getContent();
    boolean isMe = (message.getType() == Message.MessageType.ACTION_MESSAGE);
    try {
        print(m, "\n" + getTime(), GUIMain.norm);
        User u = Settings.channelManager.getUser(sender, true);
        SimpleAttributeSet user = getUserSet(u);
        if (channel.substring(1).equals(sender)) {
            insertIcon(m, IconEnum.BROADCASTER, null);
        }
        if (u.isOp(channel)) {
            if (!channel.substring(1).equals(sender) && !u.isStaff() && !u.isAdmin() && !u.isGlobalMod()) {
                //not the broadcaster again
                insertIcon(m, IconEnum.MOD, null);
            }
        }
        if (u.isGlobalMod()) {
            insertIcon(m, IconEnum.GLOBAL_MOD, null);
        }
        if (u.isStaff()) {
            insertIcon(m, IconEnum.STAFF, null);
        }
        if (u.isAdmin()) {
            insertIcon(m, IconEnum.ADMIN, null);
        }
        boolean isSubscriber = u.isSubscriber(channel);
        if (isSubscriber) {
            insertIcon(m, IconEnum.SUBSCRIBER, channel);
        } else {
            if (Utils.isMainChannel(channel)) {
                Optional<Subscriber> sub = Settings.subscriberManager.getSubscriber(sender);
                if (sub.isPresent() && !sub.get().isActive()) {
                    insertIcon(m, IconEnum.EX_SUBSCRIBER, channel);
                }
            }
        }
        if (u.isTurbo()) {
            insertIcon(m, IconEnum.TURBO, null);
        }
        if (u.isPrime())
            insertIcon(m, IconEnum.PRIME, null);
        //Cheering
        int cheerTotal = u.getCheer(channel);
        if (cheerTotal > 0) {
            insertIcon(m, Donor.getCheerStatus(cheerTotal), null);
        }
        // Third party donor
        if (Settings.showDonorIcons.getValue()) {
            if (u.isDonor()) {
                insertIcon(m, u.getDonationStatus(), null);
            }
        }
        //name stuff
        print(m, " ", GUIMain.norm);
        SimpleAttributeSet userColor = new SimpleAttributeSet(user);
        FaceManager.handleNameFaces(sender, user);
        if (showChannel) {
            print(m, determineName(u), user);
            print(m, " (" + channel.substring(1) + ")" + (isMe ? " " : ": "), GUIMain.norm);
        } else {
            print(m, determineName(u), user);
            print(m, (!isMe ? ": " : " "), userColor);
        }
        //keyword?
        SimpleAttributeSet set;
        if (Utils.mentionsKeyword(mess)) {
            set = Utils.getSetForKeyword(mess);
        } else {
            set = (isMe ? userColor : GUIMain.norm);
        }
        //URL, Faces, rest of message
        printMessage(m, mess, set, u);
        if (BotnakTrayIcon.shouldDisplayMentions() && !Utils.isTabSelected(index)) {
            if (mess.toLowerCase().contains(Settings.accountManager.getUserAccount().getName().toLowerCase())) {
                GUIMain.getSystemTrayIcon().displayMention(m.getLocal());
            }
        }
        if (Utils.isMainChannel(channel))
            //check status of the sub, has it been a month?
            Settings.subscriberManager.updateSubscriber(u, channel, isSubscriber);
        if (shouldPulse())
            GUIMain.instance.pulseTab(this);
    } catch (Exception e) {
        GUIMain.log(e);
    }
}
Also used : SimpleAttributeSet(javax.swing.text.SimpleAttributeSet) User(lib.pircbot.User) Message(irc.message.Message) Subscriber(irc.Subscriber)

Example 5 with Message

use of irc.message.Message in project Botnak by Gocnak.

the class IRCViewer method onResubscribe.

@Override
public void onResubscribe(String channel, String newSub, String msg) {
    Message m = new Message(channel, msg, Message.MessageType.SUB_NOTIFY);
    if (Utils.isMainChannel(channel)) {
        //it's the (blah blah has subbed for more than X month(s)!)
        //Botnak already handles this, so we can construct this message again since the user feels entitled
        //to tell us they've remained subbed... again
        //the catch is the message they send isn't automatic, so there's a chance it won't be sent (ex: on an IRC client, shy, etc)
        //HOWEVER, we will make sure Botnak does not increment the sub counter for this
        Optional<Subscriber> s = Settings.subscriberManager.getSubscriber(newSub);
        if (s.isPresent() && !s.get().isActive()) {
            //fixes issue #87 (I hope)
            s.get().setActive(true);
        }
        //anything other than "null" works
        m = m.setExtra(false);
        Settings.subscriberManager.notifyTrayIcon(m.getContent(), true);
    }
    MessageQueue.addMessage(m);
}
Also used : Message(irc.message.Message)

Aggregations

Message (irc.message.Message)10 Subscriber (irc.Subscriber)3 Donor (irc.Donor)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 SimpleAttributeSet (javax.swing.text.SimpleAttributeSet)1 User (lib.pircbot.User)1