From 9bc1c6156c52f0869517453bf00f48803ba26820 Mon Sep 17 00:00:00 2001 From: Gocnak Date: Sun, 26 Apr 2015 03:04:48 -0400 Subject: [PATCH] 2.3 Added: Full !song support with last.fm (closes #53 but see the wiki on github) Icon enums (one step closer towards #57, thanks @jbzdarkid!) Donation total for a user printed out upon another donation Fixed: FileChooser for Sounds now compares correctly (closes #71) Channel manager null fix (closes #73) User Chat index sets correctly (you can up arrow -> enter spam again) Issue with User Suggestion panel still showing Imgur URLs are corrected to i.imgur URLs (namefaces) Luminosity values should be better now Subscriber count streak does not increase for repeat messages Minor code improvements (thanks @jbzdarkid and @tsteinholz !) --- src/main/java/face/IconEnum.java | 22 ++++ src/main/java/face/Icons.java | 123 ++++++++++++++++++ src/main/java/gui/ChatPane.java | 34 ++--- src/main/java/gui/IconEnum.java | 17 --- src/main/java/gui/Icons.java | 121 ----------------- src/main/java/irc/Donor.java | 23 ++-- src/main/java/irc/IRCViewer.java | 19 ++- .../lib/pircbot/org/jibble/pircbot/User.java | 2 +- src/main/java/util/Constants.java | 3 +- src/main/java/util/misc/Raffle.java | 2 +- .../java/util/settings/DonationManager.java | 3 +- version.txt | 18 ++- 12 files changed, 200 insertions(+), 187 deletions(-) create mode 100644 src/main/java/face/IconEnum.java create mode 100644 src/main/java/face/Icons.java delete mode 100644 src/main/java/gui/IconEnum.java delete mode 100644 src/main/java/gui/Icons.java diff --git a/src/main/java/face/IconEnum.java b/src/main/java/face/IconEnum.java new file mode 100644 index 0000000..313d618 --- /dev/null +++ b/src/main/java/face/IconEnum.java @@ -0,0 +1,22 @@ +package face; + +public enum IconEnum { + NONE(""), + MOD("Mod"), + BROADCASTER("Broadcaster"), + GLOBALMOD("Global Mod"), + ADMIN("Admin"), + STAFF("Staff"), + TURBO("Turbo"), + SUBSCRIBER("Subscriber"), + DONOR_BASIC("Donor"), + DONOR_LOW("Donor"), + DONOR_MEDIUM("Donor"), + DONOR_HIGH("Donor"), + DONOR_INSANE("Donor"); + + public String type; + IconEnum(String type) { + this.type = type; + } +} diff --git a/src/main/java/face/Icons.java b/src/main/java/face/Icons.java new file mode 100644 index 0000000..251d390 --- /dev/null +++ b/src/main/java/face/Icons.java @@ -0,0 +1,123 @@ +package face; + +import gui.ChatPane; +import gui.GUIMain; +import lib.scalr.Scalr; + +import javax.imageio.ImageIO; +import javax.swing.*; +import java.awt.image.BufferedImage; +import java.net.URL; + +/** + * A class which specifies special chat icons, or 'badges'. + * This allows for easier creation of custom icons, and + * should be easily adaptable to create custom donation + * levels. + * + * @author Joseph Blackman + * @date 4/10/2015 + */ + +public class Icons { + + /** + * For a specified icon, returns the file containing the + * image, resized to fit into the chat window. + * + * @param i the type of icon to get + * @return the icon along with what type it is + */ + + public static BotnakIcon getIcon(IconEnum i, String channel) { + ImageIcon icon = null; + switch (i) { + case MOD: + icon = sizeIcon(GUIMain.currentSettings.modIcon); + break; + case BROADCASTER: + icon = sizeIcon(GUIMain.currentSettings.broadIcon); + break; + case ADMIN: + icon = sizeIcon(GUIMain.currentSettings.adminIcon); + break; + case STAFF: + icon = sizeIcon(GUIMain.currentSettings.staffIcon); + break; + case TURBO: + icon = sizeIcon(GUIMain.currentSettings.turboIcon); + break; + case SUBSCRIBER: + URL subIcon = FaceManager.getSubIcon(channel); + if (subIcon != null) { + icon = sizeIcon(subIcon); + } + break; + case DONOR_BASIC: + icon = sizeIcon(ChatPane.class.getResource("/image/green.png")); + break; + case DONOR_LOW: + icon = sizeIcon(ChatPane.class.getResource("/image/bronze.png")); + break; + case DONOR_MEDIUM: + icon = sizeIcon(ChatPane.class.getResource("/image/silver.png")); + break; + case DONOR_HIGH: + icon = sizeIcon(ChatPane.class.getResource("/image/gold.png")); + break; + case DONOR_INSANE: + icon = sizeIcon(ChatPane.class.getResource("/image/diamond.png")); + break; + case GLOBALMOD: + icon = sizeIcon(ChatPane.class.getResource("/image/globalmod.png")); + break; + case NONE: + break; + default: + break; + } + return new BotnakIcon(i, icon); + } + + /** + * Resize an icon to match the chat font size. This has the + * effect of allowing users to submit images of any size. + * + * @param image the image URL + * @return ImageIcon the resized image + */ + + private static ImageIcon sizeIcon(URL image) { + ImageIcon icon; + try { + BufferedImage img = ImageIO.read(image); + int size = GUIMain.currentSettings.font.getSize(); + img = Scalr.resize(img, Scalr.Method.ULTRA_QUALITY, size, size); + icon = new ImageIcon(img); + icon.getImage().flush(); + return icon; + } catch (Exception e) { + icon = new ImageIcon(image); + } + return icon; + } + + //Wrapper class for logging purposes + public static class BotnakIcon { + public IconEnum t; + public ImageIcon ii; + + public IconEnum getType() { + return t; + } + + public ImageIcon getImage() { + return ii; + } + + public BotnakIcon(IconEnum type, ImageIcon icon) { + t = type; + ii = icon; + } + } +} \ No newline at end of file diff --git a/src/main/java/gui/ChatPane.java b/src/main/java/gui/ChatPane.java index 62a8647..c41eccc 100644 --- a/src/main/java/gui/ChatPane.java +++ b/src/main/java/gui/ChatPane.java @@ -1,10 +1,10 @@ package gui; import face.FaceManager; +import face.IconEnum; +import face.Icons; import gui.listeners.ListenerName; import gui.listeners.ListenerURL; -import gui.Icons; -import gui.IconEnum; import irc.Donor; import irc.message.Message; import irc.message.MessageQueue; @@ -327,31 +327,31 @@ public void onMessage(MessageWrapper m, boolean showChannel) { } StyleConstants.setForeground(user, c); if (channel.substring(1).equals(sender)) { - insertIcon(m, IconEnum.Broadcaster, null); + 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.None, null); + insertIcon(m, IconEnum.MOD, null); } } if (u.isGlobalMod()) { - insertIcon(m, IconEnum.GlobalMod, null); + insertIcon(m, IconEnum.GLOBALMOD, null); } if (u.isDonor()) { insertIcon(m, u.getDonationStatus(), null); } if (u.isStaff()) { - insertIcon(m, IconEnum.Staff, null); + insertIcon(m, IconEnum.STAFF, null); } if (u.isAdmin()) { - insertIcon(m, IconEnum.Admin, null); + insertIcon(m, IconEnum.ADMIN, null); } boolean isSubscriber = u.isSubscriber(channel); if (isSubscriber) { - insertIcon(m, IconEnum.Subscriber, channel); + insertIcon(m, IconEnum.SUBSCRIBER, channel); } if (u.isTurbo()) { - insertIcon(m, IconEnum.Turbo, null); + insertIcon(m, IconEnum.TURBO, null); } //name stuff print(m, " ", GUIMain.norm); @@ -467,20 +467,21 @@ public void onIconMessage(MessageWrapper m, IconEnum status) { Message message = m.getLocal(); print(m, "\n", GUIMain.norm); for (int i = 0; i < 5; i++) { - insertIcon(m, status, (status == IconEnum.Subscriber ? message.getChannel() : null)); + insertIcon(m, status, (status == IconEnum.SUBSCRIBER ? message.getChannel() : null)); } - print(m, " " + message.getContent() + (status == IconEnum.Subscriber ? (" (" + (subCount + 1) + ") ") : " "), GUIMain.norm); + print(m, " " + message.getContent() + (status == IconEnum.SUBSCRIBER ? (" (" + (subCount + 1) + ") ") : " "), GUIMain.norm); for (int i = 0; i < 5; i++) { - insertIcon(m, status, (status == IconEnum.Subscriber ? message.getChannel() : null)); + insertIcon(m, status, (status == IconEnum.SUBSCRIBER ? message.getChannel() : null)); } } catch (Exception e) { GUIMain.log(e.getMessage()); } - if (status == IconEnum.Subscriber) subCount++; + boolean shouldIncrement = status == IconEnum.SUBSCRIBER && m.getLocal().getExtra() != null;//checking for repeat messages + if (shouldIncrement) subCount++; } public void onSub(MessageWrapper m) { - onIconMessage(m, IconEnum.Subscriber); + onIconMessage(m, IconEnum.SUBSCRIBER); } public void onDonation(MessageWrapper m) { @@ -490,10 +491,11 @@ public void onDonation(MessageWrapper m) { public void insertIcon(MessageWrapper m, IconEnum type, String channel) { SimpleAttributeSet attrs = new SimpleAttributeSet(); - ImageIcon icon = Icons.getIcon(type, channel); - StyleConstants.setIcon(attrs, icon); + Icons.BotnakIcon icon = Icons.getIcon(type, channel); + StyleConstants.setIcon(attrs, icon.getImage()); try { print(m, " ", null); + print(m, icon.getType().type, attrs); } catch (Exception e) { GUIMain.log("INSERT ICON " + e.getMessage()); } diff --git a/src/main/java/gui/IconEnum.java b/src/main/java/gui/IconEnum.java deleted file mode 100644 index d6fc249..0000000 --- a/src/main/java/gui/IconEnum.java +++ /dev/null @@ -1,17 +0,0 @@ -package gui; - -public enum IconEnum { - None, - Mod, - Broadcaster, - Admin, - Staff, - Turbo, - Subscriber, - Donator_basic, - Donator_low, - Donator_medium, - Donator_high, - Donator_insane, - GlobalMod -} diff --git a/src/main/java/gui/Icons.java b/src/main/java/gui/Icons.java deleted file mode 100644 index e6ae7f1..0000000 --- a/src/main/java/gui/Icons.java +++ /dev/null @@ -1,121 +0,0 @@ -package gui; - -import face.FaceManager; -import java.awt.image.BufferedImage; -import java.net.URL; -import javax.imageio.ImageIO; -import javax.swing.ImageIcon; -import lib.scalr.Scalr; - -/** -* A class which specifies special chat icons, or 'badges'. -* This allows for easier creation of custom icons, and -* should be easily adaptable to create custom donation -* levels. -* -* @author Joseph Blackman -* @date 4/10/2015 -*/ - -public class Icons { - - /** - * For a specified icon, returns the file containing the - * image, resized to fit into the chat window. - * - * @param Icon the icon to get - * @return ImageIcon the icon file - */ - - public static ImageIcon getIcon(IconEnum i, String channel) { - String kind = ""; - ImageIcon icon = null; - switch (i) { - case Mod: - kind = "Mod"; - icon = sizeIcon(GUIMain.currentSettings.modIcon); - break; - case Broadcaster: - kind = "Broadcaster"; - icon = sizeIcon(GUIMain.currentSettings.broadIcon); - break; - case Admin: - kind = "Admin"; - icon = sizeIcon(GUIMain.currentSettings.adminIcon); - break; - case Staff: - kind = "Staff"; - icon = sizeIcon(GUIMain.currentSettings.staffIcon); - break; - case Turbo: - kind = "Turbo"; - icon = sizeIcon(GUIMain.currentSettings.turboIcon); - break; - case Subscriber: - kind = "Subscriber"; - URL subIcon = FaceManager.getSubIcon(channel); - if (subIcon != null) { - icon = sizeIcon(subIcon); - } - break; - case Donator_basic: - kind = "Donator"; - icon = sizeIcon(ChatPane.class.getResource("/image/green.png")); - break; - case Donator_low: - kind = "Donator"; - icon = sizeIcon(ChatPane.class.getResource("/image/bronze.png")); - break; - case Donator_medium: - kind = "Donator"; - icon = sizeIcon(ChatPane.class.getResource("/image/silver.png")); - break; - case Donator_high: - kind = "Donator"; - icon = sizeIcon(ChatPane.class.getResource("/image/gold.png")); - break; - case Donator_insane: - kind = "Donator"; - icon = sizeIcon(ChatPane.class.getResource("/image/diamond.png")); - break; - case GlobalMod: - kind = "GlobalMod"; - icon = sizeIcon(ChatPane.class.getResource("/image/globalmod.png")); - break; - case None: - default: - break; - } - - try { - print(channel, kind, null); - } catch (Exception e) { - GUIMain.log("INSERT ICON " + e.getMessage()); - } - - return icon; - } - - /** - * Resize an icon to match the chat font size. This has the - * effect of allowing users to submit images of any size. - * - * @param URL the image URL - * @return ImageIcon the resized image - */ - - private static ImageIcon sizeIcon(URL image) { - ImageIcon icon; - try { - BufferedImage img = ImageIO.read(image); - int size = GUIMain.currentSettings.font.getSize(); - img = Scalr.resize(img, Scalr.Method.ULTRA_QUALITY, size, size); - icon = new ImageIcon(img); - icon.getImage().flush(); - return icon; - } catch (Exception e) { - icon = new ImageIcon(image); - } - return icon; - } -} \ No newline at end of file diff --git a/src/main/java/irc/Donor.java b/src/main/java/irc/Donor.java index d0179b4..5bf6425 100644 --- a/src/main/java/irc/Donor.java +++ b/src/main/java/irc/Donor.java @@ -1,6 +1,6 @@ package irc; -import gui.IconEnum; +import face.IconEnum; /** * Created by Nick on 1/26/14. @@ -50,19 +50,12 @@ public String getName() { * @return The int status of the user, or -1 if they have none. */ public static IconEnum getDonationStatus(Double donated) { - if (donated > 0 && donated < 10) { - return IconEnum.Donator_basic; - } else if (donated >= 10 && donated < 50) { - return IconEnum.Donator_low; - } else if (donated >= 50 && donated < 100) { - return IconEnum.Donator_medium; - } else if (donated >= 100 && donated < 500) { - return IconEnum.Donator_high; - } else if (donated >= 500) { - return IconEnum.Donator_insane; - } else { - return IconEnum.None; - } + if (donated >= 500) return IconEnum.DONOR_INSANE; + else if (donated >= 100) return IconEnum.DONOR_HIGH; + else if (donated >= 50) return IconEnum.DONOR_MEDIUM; + else if (donated >= 10) return IconEnum.DONOR_LOW; + else if (donated > 0) return IconEnum.DONOR_BASIC; + return IconEnum.NONE; } /** @@ -73,4 +66,4 @@ public static IconEnum getDonationStatus(Double donated) { public void addDonated(double toAdd) { donated += toAdd; } -} +} \ No newline at end of file diff --git a/src/main/java/irc/IRCViewer.java b/src/main/java/irc/IRCViewer.java index 6ea4233..68a7282 100644 --- a/src/main/java/irc/IRCViewer.java +++ b/src/main/java/irc/IRCViewer.java @@ -80,15 +80,20 @@ public void onOp(String channel, String recepient) { @Override public void onNewSubscriber(String channel, String line, String newSub) { - if (line.endsWith("subscribed!")) {//new sub - if (channel.substring(1).equalsIgnoreCase(GUIMain.currentSettings.accountManager.getUserAccount().getName())) { + Message m = new Message().setChannel(channel).setType(Message.MessageType.SUB_NOTIFY).setContent(line); + if (channel.substring(1).equalsIgnoreCase(GUIMain.currentSettings.accountManager.getUserAccount().getName())) { + if (line.endsWith("subscribed!")) {//new sub if (GUIMain.currentSettings.subscriberManager.addNewSubscriber(newSub, channel)) return; + } else { + //it's the (blah blah has subbed for more than 1 month!) + //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 + m.setExtra(false);//anything other than "null" works } - } //else it's the (blah blah has subbed for more than 1 month!) - //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) - MessageQueue.addMessage(new Message().setChannel(channel).setType(Message.MessageType.SUB_NOTIFY).setContent(line)); + } //else it's someone else's channel, just print the message + MessageQueue.addMessage(m); } @Override diff --git a/src/main/java/lib/pircbot/org/jibble/pircbot/User.java b/src/main/java/lib/pircbot/org/jibble/pircbot/User.java index a151ed2..7417adc 100644 --- a/src/main/java/lib/pircbot/org/jibble/pircbot/User.java +++ b/src/main/java/lib/pircbot/org/jibble/pircbot/User.java @@ -14,7 +14,7 @@ General Public License (GPL) and the www.jibble.org Commercial License. package lib.pircbot.org.jibble.pircbot; import gui.GUIMain; -import gui.IconEnum; +import face.IconEnum; import irc.Donor; import java.awt.*; diff --git a/src/main/java/util/Constants.java b/src/main/java/util/Constants.java index edf091e..d302805 100644 --- a/src/main/java/util/Constants.java +++ b/src/main/java/util/Constants.java @@ -12,7 +12,7 @@ public class Constants { - public static final double VERSION = 2.29; + public static final double VERSION = 2.3; /** * All users may do it @@ -117,5 +117,4 @@ public String getDescription() { new NamedColor("BlueViolet", 138, 43, 226), new NamedColor("SpringGreen", 0, 255, 127) }; - } \ No newline at end of file diff --git a/src/main/java/util/misc/Raffle.java b/src/main/java/util/misc/Raffle.java index c88c2c5..001dfe9 100644 --- a/src/main/java/util/misc/Raffle.java +++ b/src/main/java/util/misc/Raffle.java @@ -100,4 +100,4 @@ private void pickWinner() { bot.sendMessage(channel, "Nobody entered the giveaway... BibleThump"); } } -} +} \ No newline at end of file diff --git a/src/main/java/util/settings/DonationManager.java b/src/main/java/util/settings/DonationManager.java index a2c728f..ccffda6 100644 --- a/src/main/java/util/settings/DonationManager.java +++ b/src/main/java/util/settings/DonationManager.java @@ -74,7 +74,8 @@ public void addDonation(Donation d, boolean isSub) { MessageQueue.addMessage(new Message() .setChannel(GUIMain.currentSettings.accountManager.getUserAccount().getName()) .setType(Message.MessageType.DONATION_NOTIFY) - .setContent(d.getFromWho() + " has just donated " + CURRENCY_SYMBOL + d.getAmount() + "! Lifetime total: " + CURRENCY_SYMBOL + don.getDonated() + ".") + .setContent(d.getFromWho() + " has just donated " + CURRENCY_SYMBOL + d.getAmount() + "! " + + "Lifetime total: " + CURRENCY_SYMBOL + don.getDonated() + " .") .setExtra(d)); } } diff --git a/version.txt b/version.txt index 540d2af..766bcf4 100644 --- a/version.txt +++ b/version.txt @@ -1,12 +1,18 @@ -2.29 +2.3 Added: -Global Moderator support (closes #58) -Message clearing/cleanup is now on MessageQueue +Full !song support with last.fm (closes #53 but see the wiki on github) +Icon enums (one step closer towards #57, thanks @jbzdarkid!) +Donation total for a user printed out upon another donation Fixed: -Subscriber sounds now don't trigger twice -Font issue (closes #68) -Null Pointer with checking Subscribers (closes #69) \ No newline at end of file +FileChooser for Sounds now compares correctly (closes #71) +Channel manager null fix (closes #73) +User Chat index sets correctly (you can up arrow -> enter spam again) +Issue with User Suggestion panel still showing +Imgur URLs are corrected to i.imgur URLs (namefaces) +Luminosity values should be better now +Subscriber count streak does not increase for repeat messages +Minor code improvements (thanks @jbzdarkid and @tsteinholz !) \ No newline at end of file