KittehOrg / KittehIRCClientLib

An IRC client library in Java
https://kitteh.dev/kicl/
MIT License
146 stars 34 forks source link

When user modes aren't available lots of exceptions are thrown #137

Closed iamkobold closed 8 years ago

iamkobold commented 8 years ago

Using the kitteh library against Twitch IRC which is apparently not true IRC but close enough.

When receiving messages that look like :jtv MODE #<CHANNEL> +o <NICK> the following exception happens for every user.

Caused by: java.lang.ClassCastException: org.kitteh.irc.client.library.implementation.ModeData$IRCChannelUserMode cannot be cast to java.lang.Comparable at java.util.TreeMap.compare(TreeMap.java:1290) at java.util.TreeMap.put(TreeMap.java:538) at java.util.TreeSet.add(TreeSet.java:255) at java.util.AbstractCollection.addAll(AbstractCollection.java:344) at java.util.TreeSet.addAll(TreeSet.java:312) at org.kitteh.irc.client.library.implementation.ActorProvider$IRCChannelSnapshot.<init>(ActorProvider.java:402) at org.kitteh.irc.client.library.implementation.ActorProvider$IRCChannelSnapshot.<init>(ActorProvider.java:377) at org.kitteh.irc.client.library.implementation.ActorProvider$IRCChannel.lambda$snapshot$22(ActorProvider.java:214) at org.kitteh.irc.client.library.implementation.ActorProvider$IRCStaleable.snapshot(ActorProvider.java:156) at org.kitteh.irc.client.library.implementation.ActorProvider$IRCChannel.snapshot(ActorProvider.java:214) at org.kitteh.irc.client.library.implementation.EventListener.mode(EventListener.java:1028)

I did actually try the following hack upon a successful connection to fake this server message since the TwitchIRC doesn't send it for whatever reason. Cause looking into the stack trace it doesn't seem to understand the user modes?

try {
       Method hackMethod = client.getClass().getDeclaredMethod("handleLine", String.class);
       hackMethod.setAccessible(true);
       hackMethod.invoke(client, String.format(":tmi.twitch.tv 005 %s PREFIX=(ov)+ CHANTYPES=# :are supported by this server", client.getNick()));
       hackMethod.setAccessible(false);
    } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
                java.util.logging.Logger.getLogger(TwitchChatClient.class.getName()).log(Level.SEVERE, null, ex);
}

I don't want to say this is a bug in the library since TwitchIRC isn't normal IRC but would be cool to get some insight how to work around this. Using version 2.3.0 by the way

mbax commented 8 years ago

Huh! That is certainly something special. I appreciate the work you did you try debugging it.

I'm setting a reminder for myself to look into this tonight (US time).

iamkobold commented 8 years ago

Thanks from what i dug into; the twitch IRC servers don't ever send the 005 line telling the client what the modes and channel types are. So i am guessing when mode messages come through it doesn't now how to map moderators versus non-moderators.

Again I tried to fake the 005 line; and it helped in an older version of the library but now it just generates tons of exceptions like what is shown above.

mbax commented 8 years ago

Just to note a few other fun twitch features:

However, this should be fixed for 2.3.1

mbax commented 8 years ago

Fixed. https://github.com/KittehOrg/KittehIRCClientLib/commit/9632c9664975f35b7b20abfa4910d13de783d333

2.3.1 pushed for a trip to maven central. Hopefully will be available shortly.