0

I was wondering how I would add a command for 'UpTime' in my commands that will show how long the twitch channel has been live for.

This is my whole code: https://pastebin.com/ty8J3vYS

I'm not sure if I add it into my commands with things added to it with another case such as

case "uptime":
    irc.sendChatMessage("");
break;
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
byLimbo
  • 1
  • 1
  • 4

1 Answers1

1

You can use Twitch's own API for this. Using this URL:

https://api.twitch.tv/kraken/streams/CHANNEL_ID

CHANNEL_ID is numeric, so you'll have to find out what yours is.

Will return json, and within it contains the key created_at, which tells you when a stream went live, and from there you can calculate how long the stream has been live for. (curr_date - created_at)

Although, you will need a Client-ID when sending the API request. You can read more about that here:

https://blog.twitch.tv/client-id-required-for-kraken-api-calls-afbb8e95f843

Here is the documentation on Twitch's API: https://dev.twitch.tv/docs/

ThePerplexedOne
  • 2,920
  • 15
  • 30
  • I'm sorry if this is a stupid question, but I kinda forgot how to add API to C#, C# and I don't get along too well. Also would I add `(curr_date - created_at)` in my Uptime case? – byLimbo May 23 '17 at 12:43
  • is there anyway to being able to have the command to show me how long its been streaming for? As in "This stream has been live for 3 hours & 32minutes"? Or is it only possible to have it be like"Stream started at 7:30PM"? – byLimbo May 23 '17 at 12:54
  • You will have to make the request and do the calculations. – ThePerplexedOne May 23 '17 at 13:07
  • Is there an easy way to use this API to determine when someone else's stream started, even if it has recently ended? For example, when someone raids me, I want my bot to turn off follower-only chat when my channel is raided, but only if the raid is from a channel whose last broadcast was longer than 30 minutes to prevent using fake raids. – StarCrashr Feb 16 '20 at 18:59