1
+ on ( "ready" , function ( ) {
2
+ "use strict" ;
3
+ on ( "chat:message" , function ( msg ) {
4
+ var args ;
5
+ if ( msg . type === "api" ) {
6
+ args = msg . content . split ( / \s + / ) ;
7
+ if ( args [ 0 ] . match ( / ^ ! C l o c k / i) ) {
8
+ let time = parseInt ( args [ 1 ] , 10 ) || 0 ;
9
+ if ( time ) {
10
+ let due = _ . now ( ) + time * 1000 ,
11
+ tokens = _ . chain ( msg . selected )
12
+ . map ( ( o ) => getObj ( 'graphic' , o . _id ) )
13
+ . reject ( _ . isUndefined )
14
+ . value ( ) ,
15
+ names = _ . map ( tokens , ( t ) => t . get ( 'name' ) ) ,
16
+ numCheck ,
17
+ updateClock = ( ) => {
18
+ let num = Math . ceil ( ( due - _ . now ( ) ) / 1000 ) ;
19
+ if ( num > 0 ) {
20
+ _ . map ( tokens , ( t ) => t . set ( 'status_stopwatch' , num ) ) ;
21
+ if ( numCheck !== num ) {
22
+ sendChat ( "" , "Turn Time Remaining: " + num ) ;
23
+ numCheck = num ;
24
+ }
25
+ _ . delay ( updateClock , 200 ) ;
26
+ } else {
27
+ _ . map ( tokens , ( t ) => t . set ( 'status_stopwatch' , false ) ) ;
28
+ sendChat ( "TurnClock" , "!Sound: Buzzer" ) ;
29
+ sendChat ( "" , "Turn Over!" ) ;
30
+ }
31
+ } ;
32
+ sendChat ( "TurnClock" , "!Sound: Ticking Clock" ) ;
33
+ sendChat ( "" , "TurnClock Started on: " + names . join ( ', ' ) ) ;
34
+ updateClock ( ) ;
35
+ }
36
+ }
37
+ }
38
+ } ) ;
39
+ on ( "chat:message" , function ( msg ) {
40
+ if ( msg . type === "api" && msg . content === "!Sound: Ticking Clock" ) {
41
+ PlaySound ( 'Sound: Ticking Clock' , 6000 ) ;
42
+ } ;
43
+ if ( msg . type === "api" && msg . content === "!Sound: Buzzer" ) {
44
+ PlaySound ( 'Sound: Buzzer' , 1000 ) ;
45
+ } ;
46
+ } ) ;
47
+ } ) ;
48
+
49
+ function PlaySound ( trackname , time ) {
50
+ var track = findObjs ( { type : 'jukeboxtrack' , title : trackname } ) [ 0 ] ;
51
+ if ( track ) {
52
+ if ( track . get ( 'playing' ) === false ) {
53
+
54
+ track . set ( 'playing' , false ) ;
55
+ track . set ( 'softstop' , false ) ;
56
+ //track.set('volume', 100);
57
+ log ( track ) ;
58
+ if ( track ) {
59
+ track . set ( 'playing' , true ) ;
60
+ log ( 'playing' ) ;
61
+ setTimeout ( function ( ) { track . set ( 'playing' , false ) ; log ( 'stopping sound' ) ; } , time ) ;
62
+ log ( track ) ;
63
+ }
64
+ else {
65
+ log ( "No track found" ) ;
66
+ }
67
+ }
68
+ else { track . set ( 'playing' , false ) ;
69
+
70
+ } }
71
+ }
0 commit comments