0

I'm a beginner java user, and beginning streamer on Twitch.tv. I have been working on developing an IRC bot all night that would streamline moderation on my channel (I want to have that level of customization that using a cookie cutter IRC bot can't give).

One thing that is stumbling me is poll creation. I have looked through the Pirc javadocs and there is no command as far as I can see that checks for messages sent by a channel op, which is crucial to keeping trolls from creating polls, and with my limited knowledge I do not know how to grab extra parameters from a message.

What I want is this:

!poll <question> <c1> <c2> <c3> <seconds>

Any help here? I will add you to my thanks screen on my outro for each stream.

2 Answers2

0

From my quick look through the PIRC javadocs, it looks like the method you want is #onMessage(String channel, String sender, String login, String hostname, String message)

From here, you can get any information required. Now depending on how you're handling incoming messages, all you need to do it search for the command, which in this case is "!poll" which you'll receive from the message string. From there, you can further parse the information, and do what you want with it.

If you haven't been using them already, the javadocs for pirc are location here: http://www.jibble.org/javadocs/pircbot/index.html

JD Davis
  • 3,517
  • 4
  • 28
  • 61
0

As Jdsfighter said, you need to use the onMessage(...) method from the PircBot superclass. This method is called whenever a message is sent to your channel. I kinda assume you have understood this by now, as making the bot react to chat is alpha and omega when making an IRC bot.

When concerned with Moderators (Operators in IRC terms), the Twitch IRC servers behave in a way that isnt completely understood by PircBot, and I have not been successfull with the User.isOp(...) method from the User class. What I've found successfull is to include the following in my Bot class (not the main class):

Set<String> OPs = new HashSet<String>();

protected void onUserMode(String channel, String sourceNick, String sourceLogin, String sourceHostname, String recipient) {
    recipient = recipient.split(" ")[2];
    OPs.add(recipient);
}

This Method is called whenever you see a line begining with MODE in the console, like this one:

jtv MODE #channel +o moderatorName

Now, you need to make a method that is called whenever the message recieved starts with "!poll", and checks if the sender of the message is in the OPs Set.

Here's an outline for you, to be placed in the onMessage() method

if (message.toLowerCase().startsWith("!poll") {
    if (OPs.contains(sender)) {
            //TODO Add body
    }
}

Now you just have to make some code that catches the rest of the line after "!Poll" and posts a message back to the channel about the different poll options.

You obviously need somewhere to store your alternatives and how many votes they get each, I suggest simply two arrays, one String[] and one int[].