Search in sources :

Example 6 with Message

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

the class DonationManager method addDonation.

public void addDonation(Donation d, boolean isLocal) {
    if (!donationsContains(d.getDonationID()) || isLocal) {
        if (donations.add(d)) {
            Donor don = getDonor(d.getFromWho());
            if (don == null) {
                don = new Donor(d.getFromWho(), d.getAmount());
                addDonor(don);
            } else {
                don.addDonated(d.getAmount());
            }
            if (!isLocal) {
                Settings.DONATIONS.save();
                Settings.DONORS.save();
                setLastDonation(d);
                if (BotnakTrayIcon.shouldDisplayDonations()) {
                    GUIMain.getSystemTrayIcon().displayDonation(d);
                }
                MessageQueue.addMessage(new Message().setChannel(Settings.accountManager.getUserAccount().getName()).setType(Message.MessageType.DONATION_NOTIFY).setContent(String.format("%s has just donated %s! Lifetime total: %s ", d.getFromWho(), getCurrencyFormat().format(d.getAmount()), getCurrencyFormat().format(don.getDonated()))).setExtra(d));
            }
        }
    }
}
Also used : Donor(irc.Donor) Message(irc.message.Message)

Example 7 with Message

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

the class SubscriberManager method addNewSubscriber.

public boolean addNewSubscriber(String name, String channel) {
    Optional<Subscriber> subscriber = getSubscriber(name);
    if (!subscriber.isPresent()) {
        //brand spanking new sub, live as botnak caught it
        addSub(new Subscriber(name, LocalDateTime.now(), true, 0));
        notifyTrayIcon(name + " has just subscribed!", false);
        playSubscriberSound();
    //we're going to return false (end of method) so that Botnak generates the message
    //like it did before this manager was created and implemented (and because less of the same code is better eh?)
    } else if (subscriber.get().isActive()) {
        //this may have been twitchnotify telling us twice, discard without messing up sounds
        return true;
    } else {
        //re-sub!
        //if we got the message, this means a month has passed, and they cancelled
        //question: should the streak still matter, if they're quick enough to resub?
        //answer: Botnak automatically acknowledges them for their continued support anyways, and
        // if they decide to cancel just to get the notification again, they deserve their streak to be reset
        String content = name + " has just RE-subscribed!";
        MessageQueue.addMessage(new Message().setContent(content).setChannel(channel).setType(Message.MessageType.SUB_NOTIFY));
        notifyTrayIcon(content, false);
        playSubscriberSound();
        subscriber.get().resetStreak();
        subscriber.get().setStarted(LocalDateTime.now());
        subscriber.get().setActive(true);
        setLastSubscriber(subscriber.get());
        return true;
    }
    return false;
}
Also used : Message(irc.message.Message) Subscriber(irc.Subscriber)

Example 8 with Message

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

the class SubscriberManager method updateSubscriber.

/**
     * How's our little friend doing?
     * <p>
     * Called from the Channel class of Pircbot, this method
     * updates the sub's status (donation-wise) based on how
     * many months it's been since they first subbed, and checks
     * to see if the person subscribed while offline (new or not).
     *
     * @param u               The user object of the potential subscriber.
     * @param channel         Your channel name, for the messages.
     * @param currentlyActive Boolean used to determine current sub status of the user.
     */
public void updateSubscriber(User u, String channel, boolean currentlyActive) {
    if (u.getNick().equalsIgnoreCase(Settings.accountManager.getUserAccount().getName()))
        return;
    //you will always be your own sub, silly
    Optional<Subscriber> s = getSubscriber(u.getNick());
    if (s.isPresent()) {
        if (s.get().isActive()) {
            int streak = s.get().getStreak();
            int monthsSince = (int) (s.get().getStarted().until(LocalDateTime.now(), ChronoUnit.DAYS) / 32);
            if (monthsSince > streak) {
                if (currentlyActive) {
                    String content = s.get().getName() + " has continued their subscription for over " + (monthsSince) + ((monthsSince) > 1 ? " months!" : " month!");
                    MessageQueue.addMessage(new Message().setChannel(channel).setType(Message.MessageType.SUB_NOTIFY).setContent(content));
                    //this will most likely be 1
                    s.get().incrementStreak(monthsSince - streak);
                    playSubscriberSound();
                } else {
                    //we're offering a month to re-sub
                    s.get().setActive(false);
                    s.get().resetStreak();
                }
            }
        } else {
            if (currentlyActive) {
                // this has the potential to be an offline re-sub:
                // botnak will know that the sub is currently alive if it catches it live, (see the other use of SUB_NOTIFY)
                // however if the person subscribes offline, botnak has no way of telling, and
                // the next time they talk is the only time Botnak (and perhaps you as well) knows for sure that they did
                // so, we need to update the date the user subbed to now, ensure their streak is reset, and
                // make botnak send a "thanks for subbing offline" message
                //or twitchnotify could have been a douchenozzle and did not send the message
                String content = s.get().getName() + " has RE-subscribed offline!";
                if (Settings.botAnnounceSubscribers.getValue()) {
                    Settings.accountManager.getBot().sendMessage(channel, ".me " + u.getNick() + " has just RE-subscribed!");
                }
                MessageQueue.addMessage(new Message().setContent(content).setType(Message.MessageType.SUB_NOTIFY).setChannel(channel));
                s.get().resetStreak();
                s.get().setStarted(LocalDateTime.now());
                s.get().setActive(true);
                playSubscriberSound();
                setLastSubscriber(s.get());
                notifyTrayIcon(content, false);
            }
        }
    } else {
        if (currentlyActive) {
            //or twitchnotify could have been a douchenozzle and did not send the message
            if (Settings.botAnnounceSubscribers.getValue()) {
                Settings.accountManager.getBot().sendMessage(channel, ".me " + u.getNick() + " has just subscribed!");
            }
            String content = u.getNick().toLowerCase() + " has subscribed offline!";
            MessageQueue.addMessage(new Message().setContent(content).setType(Message.MessageType.SUB_NOTIFY).setChannel(channel));
            addSub(new Subscriber(u.getNick().toLowerCase(), LocalDateTime.now(), true, 0));
            playSubscriberSound();
            notifyTrayIcon(content, false);
        }
    }
}
Also used : Message(irc.message.Message) Subscriber(irc.Subscriber)

Example 9 with Message

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

the class IRCViewer method onNewSubscriber.

@Override
public void onNewSubscriber(String channel, String line, String newSub) {
    Message m = new Message(channel, line, Message.MessageType.SUB_NOTIFY);
    if (Utils.isMainChannel(channel) && line.endsWith("subscribed!")) {
        if (Settings.subscriberManager.addNewSubscriber(newSub, channel))
            return;
    }
    //else it's someone else's channel, just print the message
    MessageQueue.addMessage(m);
}
Also used : Message(irc.message.Message)

Example 10 with Message

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

the class IRCViewer method onHosting.

@Override
public void onHosting(final String channel, final String target, String viewers) {
    Message m = new Message().setChannel(channel).setType(Message.MessageType.HOSTING_NOTIFY);
    if ("-".equals(target))
        m.setContent("Exited host mode.");
    else {
        String content = channel + " is now hosting " + target;
        String viewCount;
        if ("-".equals(viewers)) {
            viewCount = ".";
        } else {
            viewCount = " for " + viewers + " viewer" + (viewers.compareTo("1") > 0 ? "s." : ".");
        }
        m.setContent(content + viewCount);
    }
    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