tok124

timer function

Oct 25th, 2021
866
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let timer = 0,
  2. test;
  3.  
  4. function startTimer() {
  5.   if(timer > 0) {
  6.     timer--
  7.     cb.sendNotice(timer+" minutes left on the Timer")
  8.   }else{
  9.     cb.sendNotice("Time is Up !")
  10.     stopTimer()
  11.   }
  12.   test = cb.setTimeout(startTimer, 1000)
  13. }
  14.  
  15. function stopTimer() {
  16.   cb.cancelTimeout(test)
  17. }
  18.  
  19. cb.onMessage(msg => {
  20.   if((msg.is_mod == true || msg.user == cb.room_slug) && msg.m.includes("/starttimer")){
  21.     msg['X-Span'] = true
  22.     message = msg.m.split(" ")
  23.     timer = parseInt(message[1])
  24.     startTimer()
  25.   }
  26.   if(msg.m.includes("/stoptimer")) {
  27.     stopTimer()
  28.   }
  29. })
RAW Paste Data