-
Notifications
You must be signed in to change notification settings - Fork 8
/
mTwitch.StateToTopic.mrc
101 lines (95 loc) · 3.58 KB
/
mTwitch.StateToTopic.mrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
alias mTwitch.has.StateToTopic {
return 0000.0000.0010
}
alias mTwitch.StateToTopic {
if (!$isid && !$0 && $status == connected && $mTwitch.isServer) {
.timermTwitch.StateToTopic -io 1 300 mTwitch.StateToTopic
var %x = 1, %streams, %len, %y, %stream, %chan, %since, %game, %title, %topic, %host, %sub, %slow, %r9k
hmake mTwitch.StateToTopic.Streams 1
while ($scon(%x)) {
scon %x
if ($mTwitch.isServer) {
%y = 1
while ($chan(%y)) {
if ($me ison $v1) {
hadd mTwitch.StateToTopic.Streams $v2 -
}
inc %y
}
}
inc %x
}
%x = 1
while ($hget(mTwitch.StateToTopic.Streams, %x).item) {
%streams = $addtok(%streams, $mid($v1, 2-), 44)
if (!$calc($numtok(%streams, 44) % 10) || (%streams && %x == $hget(mTwitch.StateToTopic.Streams, 0).item)) {
JSONOpen -uw mTwitch.StateToTopic https://api.twitch.tv/kraken/streams?channel= $+ %streams
JSONUrlHeader mTwitch.StateToTopic Client-ID e8e68mu4x2sxsewuw6w82wpfuyprrdx
JSONUrlGet mTwitch.StateToTopic
if (!$JSONError) {
%len = $JSON(mTwitch.StateToTopic, streams, length)
%y = 0
while (%y < %len) {
%chan = $chr(35) $+ $JSON(mTwitch.StateToTopic, streams, %y, channel, name)
%since = $mTwitch.ConvertTime($JSON(mTwitch.StateToTopic, streams, %y, created_at))
%game = $JSON(mTwitch.StateToTopic, streams, %y, game)
%title = $JSON(mTwitch.StateToTopic, streams, %y, channel, status)
hadd -m mTwitch.StreamState $+(%chan, .online) $true
hadd -m mTwitch.StreamState $+(%chan, .playing) %game
hadd -m mTwitch.StreamState $+(%chan, .title) %title
hadd -m mTwitch.StateToTopic.Streams %chan Online since %since -- Playing: %game -- Title: %title
inc %y
}
}
JSONClose mTwitch.StateToTopic
%streams = $null
}
inc %x
}
%x = 1
while ($hget(mTwitch.StateToTopic.Streams, %x).item) {
scon -a mTwitch.StateToTopic.Set $v1
inc %x
}
hfree mTwitch.StateToTopic.Streams
}
}
alias -l mTwitch.StateToTopic.Set {
if ($mTwitch.isServer && !$mTwitch.isServer().isGroup && $me ison $1) {
var %topic = $hget(mTwitch.StateToTopic.Streams, $1)
var %host = $iif($mTwitch.StreamIsHosting($1), [Hosting: $+ $v1 $+ ])
var %sub = $iif($mTwitch.ChatIsSubOnly($1), [SubOnly])
var %slow = $iif($mTwitch.ChatIsSlow($1).dur, [Slow: $+ $ceil($calc($v1 /60)) $+ m])
var %r9k = $iif($mTwitch.ChatIsR9k($1), [R9K])
%topic = $iif(%topic == -, Offline, %topic) $regsubex($iif(%host || %sub || %slow || %r9k, -- %host %sub %slow %r9k), /\s(?=\x20|$)/g, $chr(32))
if ($chan($1).topic !== %topic) {
if (Offline* iswm $chan($1).topic && Online* iswm %topic) {
.signal mTwitch.Notifications.Online $1 $hget(mTwitch.StreamState, $1.playing)
}
.parseline -iqpt :jtv!jtv@jtv.twitch.tv TOPIC $1 : $+ %topic
}
}
}
on *:LOAD:{
if (!$mTwitch.has.Core) {
echo $color(info) -a [mTwitch->GroupChat] mTwitch.Core.mrc is required
.timer 1 0 .unload -rs $qt($script)
}
else {
mTwitch.StateToTopic
}
}
on *:START:{
if (!$mTwitch.has.Core) {
echo $color(info) -a [mTwitch->GroupChat] mTwitch.Core.mrc is required
.timer 1 0 .unload -rs $qt($script)
}
}
on *:UNLOAD: {
.timermTwitch.StateToTopic off
}
on me:*:JOIN:#:{
if ($mTwitch.isServer) {
.timermTwitch.StateToTopic.onJoin 1 5 mTwitch.StateToTopic
}
}