Mod only commands in Java Pircbot

I can’t for the life of me figure out how to use the twitch API in java, nor can I figure out how I would handle mod only commands in Java, and I’ve tried multiple things, including making a separate ArrayList for mods that the bot can recognize. I’m at a loss now.

Not entirely sure I understand the question. To address the first part, from a very high level, from Java, to access the Twitch API you need to create a class that queries the various Twitch API calls via HTTPS. The data comes back in JSON format, you will need to use a class like org.json to parse that data and get the data out that you need.

Not sure I follow an ArrayList for mods? Do you mean you are trying to setup commands that the bot allows like !title and !game versus !users ?

I tried setting up an ArrayList that the bot recognized as mods itself. In other words it’s a separate mod command for the bot instead of twitch. I liked the idea since I’d be able to have two levels of mods but for some reason it wasn’t creating the txt document to save the list. Not too worried about that though. So I need to make a separate object to handle the APIs and use said object in the bot?

Ok so my understanding of what your trying to do is make some kind of mod only command, like !setGame or something that only a chat mod should be able to use.

Your on the right track with your List, your going to want to use the tags that are passed with PircbotX’s MessageEvent, via the event.getTags() method call. Here is the code I use to maintain the list.

ImmutableMap<String, String> userData = event.getTags();
if(userData.get("mod").equals("1") && !this.mods.contains(event.getUser().getNick().toLowerCase())) {

Where event is the MessageEvent passed from the onMessage method and mods is a List

NOTE: This will only register mods who have talked in chat, which if you put this at the top of your onMessage listener will be fine for command processing because they have to type in chat to do the command.

Then checking if the user issuing a command in an onMessage event is as easy as doing

<command checking> && this.mods.contains(event.getUser().getNick().toLowerCase())

Hope this helps! Feel free to ask if you have any more questions!

Edit: You should be using PircbotX as the other version is horribly outdated. Also make sure you CAP request for

Grayson Briggs

PircbotX? Can’t say I’ve heard of it. But you probably know more about it than me so I’m on it coach. I hope all of my code will transfer nciely

It should be mostly the same. Let me know if you have any trouble transitioning.

The more I understand PBX and the code used… Wouldn’t it be more simple to just store a boolean every time a message is recieved whether or not the sender was a mod or not and have something like if(isMod == true … )? Is it just personal preference?

What should I use to send messages, I tried both event.respond and event.getChannel.send().message(event.getChannel(), “String Message”) but neither has worked. I see the messages going through in the console so I know the reader is seeing them. Do I have to use PRIVMSG and what would the syntax for that be?

I use a list so that I can know if someone is a mod other then only when they send a message. So I always have a running list of who the mods are and can use the data for later purposes.
For sending IRC messages i use

bot.sendIRC().message(IRC_NAME, message);

Where bot is an instance of a PircbotX object, IRC_NAME is the name of my IRC channel like #riggedbananagaming and message is the String that I want to send. I’m unsure of any other methods that work because I haven’t tried them.

This isn’t working for me either…

Are you sure your connecting correctly? Are you sure your IRC name starts with a #? I know for a fact that this works, so it must be something on your end.

Yeah, I had the bot send a message every time a message was received in my twitch chat and it sent every time. For whatever reason, any time I type one of the commands I wrote in my if/else if ladder, it isn’t recognizing it. The message is being read fine, I have event.getMessage() printing out in the system just to make sure. I’m very confused as to why my if statements are failing, they were all working when I had them in regular PircBot

EDIT: It’s not even going into the if/else if ladder. I just put an else at the end to send a message and even that doesn’t work… I am incredibly confused

Edit 2: It has something to do with this line of code:

ImmutableMap<String, String> userData = event.getTags();

I temporarily disabled it and now my commands are working. This line if I’m not mistaken is for some reason returning or breaking or whatever. It’s stopping my code from going through.

Change that line to (and send me what is says)

try {
    Map userData = event.getTags();
} catch(Exception e) {

Make sure you are CAP request the because that is needed to get the data, the PircBotX wiki has info on how to do this

I found the issue and now it’s working perfectly! Thanks so much! Not sure if I’ll have any other questions but you’ve been a monster help

Glad I could help :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.