What's the best way to check if the bot's account is a moderator in the channel?

I’m not really sure what the best way to check this is.

I figured the best way would be to just save the status of the account every time the MODE message gets sent, but I can’t figure out how those messages get sent. Like, I can receive them when they are sent. But they don’t seem to get sent when an account’s demodded, or when you join a stream. They just kinda appear whenever they want, seemingly random. Sometimes I won’t see them for like 30 minutes, and other times they’ll practically be spamming my log.

I’d like to prevent my bot from sending too many messages and breaking the over-zealous limits imposed on the chat, but it doesn’t seem like there’s actually anyway to do that besides just keeping the limit to 20 mesages, or hoping users don’t demod my bot.

Am I missing something here, or is there really no way to check if my bot’s a mod without sending a message?

What sort of bot is it? mIRC script? Perl? Python? PHP?

You could do an API check for the moderators section via: http://tmi.twitch.tv/group/user/example/chatters

If you are using an mIRC script something like this example would do the job:

Before you join any channels, run:

/raw CAP REQ :twitch.tv/membership

Then have a remote script for:

ON *:TEXT:!welcome:#mystream: {
if ($me isop $chan) {
if ($nick isop $chan) {
if (%flood) { return }
set -u10 %flood On
msg #mystream Welcome to the channel }
} }

What this does, is it watches the channel “MyStream” for the “!welcome” command, once it finds it, it checks if you are “Op” aka Moderator in that channel, and it checks if the person trying to do the command is a Moderator also… if both are try it checks if the variable %flood exists. If it does, it halts and goes back to checking for triggers. If there was no %flood variable then it set’s it for 10 seconds counting down to a 0 (self destruct).

This will effectively prevent this command from going off again for 10 seconds. Making all your commands use the same variable will prevent any of them from triggering.

If you wanted the command to work for any user and not just moderators you could do
ON *:TEXT:!welcome:#mystream: {
if ($me isop $chan) {
if (%flood) { return }
set -u10 %flood On
msg #mystream Welcome to the channel }

It’s written in python. I’ve never used mIRC before, but I’m going to assume that script relies on the MODE messages sent over IRC?

If I get demodded and send 40 messages before that MODE message gets sent, am I going to be IP banned from twitch for spamming, or does that rate limit only change when the MODE messages are sent?

The +o/-o mode messages seem a bit unreliable. Aside from that, there are different ways to know if the account your are connected with is mod:

  • The mentioned (not officially supported) chatters API, which you would have to pull regularly to check mod status (http://tmi.twitch.tv/group/user/<channel>/chatters).
  • You could parse the /mods command response in chat, which would be simliar to the API because you have to pull it.
  • With commands/tags capability enabled you get a USERSTATE message after every message you send, containing the user-type tag which tells you if you have mod powers (Twitch IRC documentation).

Either way, there is no way to have instant notification of mod status changing, so you should be careful with sending messages either way.

I feel it is reasonably more practical to not be sending enough messages to make you get globalled to start with.

If you are in a position where you are sending that many messages you’ll likely be the main channel bot and when demodded the bot is banned to block whatever malfunction is occuring. So you need not worry about it (generally speaking)

You should be looking at USERSTATE as @tduva suggests or parsing .mods

1 Like

The issue I have with using the chatters API is that I wouldn’t be able to get the information before every message sent, so it would be just as unreliable as the +o/-o mode messages.

Also, with the USERSTATE message, that only shows after I send messages. So if I send 20 as a mod and then get unmodded, the bot would assume it’s still a mod and send another message then find out it shouldn’t have sent 20 messages.

It seems like there really is just no good way to prevent the bot from going over the rate limits in some cases. That’s kinda unfortunate. You’d think if they’d implement these limits, they’d make it possible to avoid going over them.

If you are sending 40 lines at that quick interval, and the bot isn’t operating in 20+ channels, you must have one annoying bot. You could just do a delay between commands.

Why are you assuming that your bot is going to get unmodded for this to be a problem?

If you are modded it’s held server side and the check is there, the actual chat flag has very little bearing as that can flop on/off at will.

1 Like

You could parse /mods every 60 seconds or so, but seriously, is your bot really sending 40 lines in less than 60 seconds? What is it doing? flooding?

Sending /mods counts as one of those 40 lines by the way…

I meant to say 20 messages, not 40. I sincerely doubt my bot would reach 40 messages in 30 seconds, but 20 messages in 30 seconds is, while still fairly high, definitely within reason.

I’m assuming my bot is going to get unmodded and cause this to happen because it’s a possibility. It’s definitely not going to be happening every day, but I’d have liked to have been able to avoid it.

By the way Matt, sending /mods also counts towards the rate limit, so the same problem exists with that anyway.

It looks like there’s just no good way to avoid this besides just hoping the bot doesn’t get unmodded. That’s unfortunate.

I have a bot that sits in about 11 channels on average, with my normal command delay I never come close to 20 messages in 30 seconds. Each channel can do 1 command per 6-10 seconds. I suppose a very popular bot in 30 active channels could come close. In that case I would probably just start spawning multiple bots, each with a set of 5-10 channels it joins. I don’t think it’s IP rate limited but user rate limited. (Can someone confirm?) I suppose it’s not the best solution but I would help.

It’s connection limited, not user or IP, if what I’ve been told is correct.

My bot easily reaches 20 commands in 30 seconds in one channel. Often? No. But if a user wants to set up for example a command that replies to tildes with more tildes, and everybody spams tildes, reaching 20 messages in 30 seconds is totally possible.

Then if, for whatever reason, it gets unmodded shortly after that, for whatever reason, and it sends another glorious tilde, my bot’s now IP banned.

Again, I agree that it’s not really something that’s going to be happening often. Usually when a bot’s unmodded it’s not during a stream when chat’s active, because the channel owner decided it doesn’t want/need the bot anymore. But I was just wondering if it was possible to see whether or not my account was a moderator in the channel without sending a message.

I really hope they re-work how the rate limiting works.

The rate limiting is the way it is, because no matter what you think, no chat is entertaining/interesting/fun for very long when a bot is flooding it with anything even remotely near 20 commands in 30 seconds. If your bot is not rate limiting it’s replies it will be abused sooner or later. Even a 5 second pause between responding to the next query will limit the bot to 6 messages in 30 seconds. You will never have to worry whether you are modded or not.

There is no way to 100% reliably detect that you’ve been unmodded in the middle of sending lots of messages. USERSTATE will be the fastest one to tell and even that will be late, if you’re over 20 messages in the last 30 seconds. That’s why I don’t rely on it in my code at all.

1 Like

The primary focus of my bot is allowing complete customization with it. So if a user wants the bot to be able to spam their chat, they can do that. Regardless of my personal opinion on it.

I’m just going to use USERSTATE and hope it doesn’t get unmodded shortly after going over that cap. Then throw proxies at it if it happens to happen.

Oh well.

The flood protection is there for a reason and saying you will flood anyway and evade the ban isn’t probably something you should say on an official twitch forum.

I have a few commands that “Flood” but it’s a single command that sends the message 3-8 times over 10 seconds or so. So if they have a very active chat, it will still be noticed. I also make my bot reply with the IRC ACTION format to make my text the color of my name. It stands out quite well and doesn’t trigger any flood protection.

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