Automatic Command Run On Stream Start


#1

PhantomBot Version: 2.4.2 (Revision: 5c75a7b2)
OS Version: Windows Server 2016 10.0 (x86)
Java Version: 1.8.0_181-b13
Panel Version: 1.1
Stock PhantomBot: Yes

Is there a way I can have the bot automatically run a command when a Twitch stream goes online? Thanks.


#2

Is this a Feature Request or a Support question?

Do keep in mind that Twitch delays alerting the API to when a person goes online by several minutes. Logic would also have to built in to ignore the condition of getting online events within a certain time period as Twitch has been known to send incorrect data in the API (offline then online events although the stream never stopped).


#3

It’s a feature request if it isn’t already possible


#4

This solution doesn’t correspond with your feature request, but it solves your task, as if it were a support request.

  1. Stop your bot.
  2. Backup panelHandler.js located in yourBotFolder/scripts/handlers/ first, then open it in a text editor .
  3. Add the following code to a new line between lines #33 and #34:
    $.say($.inidb.get('command', 'yourCommandName'));
    Don’t forget to replace yourCommandName with your command name.
  4. Save panelHandler.js.

This instruction is relevant for version 2.4.2. I’m not responsible for any possible errors, crashes, data loss, etc. resulting from the operation of this modification.


#5

This will work but, remember, if the Twitch API experiences issues and sends a stream end and stream start event a few times (it has done that before) that the bot will spam chat even if the broadcast never ended.

Also again, the API does not tell us when the stream starts. It has a several minute delay. If it is expected that the bot says something the moment the streamer hits “Go Live” that is not going to happen.


#6

It’s not necesssary for it to be immediately when the streamer goes live. It’s just a clear to the !multi command.


#7

Fair enough, and if Twitch sends Offline/Online events several times during a stream and multi is cleared out when it is not desired?

This is why a complete use case is helpful. Need to determine the pitfalls.

For example. it sounds like you just want !multi to last a certain period of time. Would a timer that automatically clears the multi after a period of time be more useful?


#8

I just want the !multi to be active when the stream is online, and cleared once offline


#9

Like I said, the problem with that logic is Twitch has been known to send offline events mid-stream even if you never go offline. We can attempt to circumvent that with additional logic, but it may still turn out that your !multi data is wiped mid-stream when you wouldn’t want it to be.

We can see where upvotes take this It just needs to be clear that based on your requirement, you will risk having the !multi data removed inadvertently.


#10

How often in the year 2018 you are faced with fake offline event? Personally, I have not seen this for a long time, although I serve several channels. (A real interruption of a stream is another thing.)


#11

Well I did this: $.say($.inidb.get('command', 'multi clear'));, and when the streamer came online, the bot, in chat, said “null”


#12

At the time of writing the instruction there was no information yet that it is not about a custom command, but a subcommand of a default command.


#13

Use this one instead:
$.inidb.del('dualStreamCommand', 'otherChannels');
It silently clears the multistream link every time you start a stream, or restart your bot during a stream, or receive the fake offline-then-online event from Twitch.


#14

A bit, there have been several API outages and issues with the API not returning proper data. Last time was yesterday when there was a site-wide outage that caused problems. API issues were reported where they were returning bad data or Unauthorized when they should not have.

So, yes. In 2018. :smiley:


#15

It doesn’t work


#16

I can’t help any more since I’ve tested this and it works for me.


#17

How long should it take once the streamer goes live?