Update cooldown counting procedures.

This commit is contained in:
Mayhem 2013-09-19 10:59:38 +02:00
parent a56b6765cb
commit 499288e6da
2 changed files with 43 additions and 46 deletions

View File

@ -1,3 +1,9 @@
Update posting cooldown timers to match 4chan settings:
- Cooldown may vary between inter-thread and intra-thread replies.
- Cooldown may vary when posting a file or not.
- Cooldown does not take sageing into account anymore.
- Timers vary across boards.
### 3.11.2 - *2013-09-17* ### 3.11.2 - *2013-09-17*
Updated post and deletion cooldown timers to match 4chan changes: they are now twice longer. Updated post and deletion cooldown timers to match 4chan changes: they are now twice longer.

View File

@ -227,20 +227,19 @@ QR =
cooldown: cooldown:
init: -> init: ->
return unless Conf['Cooldown'] return unless Conf['Cooldown']
board = g.BOARD.ID setTimers = (e) => QR.cooldown.types = e.detail
QR.cooldown.types = $.on window, 'cooldown:timers', setTimers
thread: switch board $.globalEval 'window.dispatchEvent(new CustomEvent("cooldown:timers", {detail: cooldowns}))'
when 'q' then 86400 $.off window, 'cooldown:timers', setTimers
else 600 for type of QR.cooldown.types
sage: if board is 'q' then 600 else 120 QR.cooldown.types[type] = +QR.cooldown.types[type]
file: if board is 'q' then 300 else 60
post: if board is 'q' then 150 else 60
QR.cooldown.upSpd = 0 QR.cooldown.upSpd = 0
QR.cooldown.upSpdAccuracy = .5 QR.cooldown.upSpdAccuracy = .5
$.get "cooldown.#{board}", {}, (item) -> key = "cooldown.#{g.BOARD}"
QR.cooldown.cooldowns = item["cooldown.#{board}"] $.get key, {}, (item) ->
QR.cooldown.cooldowns = item[key]
QR.cooldown.start() QR.cooldown.start()
$.sync "cooldown.#{board}", QR.cooldown.sync $.sync key, QR.cooldown.sync
start: -> start: ->
return unless Conf['Cooldown'] return unless Conf['Cooldown']
return if QR.cooldown.isCounting return if QR.cooldown.isCounting
@ -254,30 +253,17 @@ QR =
QR.cooldown.start() QR.cooldown.start()
set: (data) -> set: (data) ->
return unless Conf['Cooldown'] return unless Conf['Cooldown']
{req, post, isReply, delay} = data {req, post, isReply, threadID, delay} = data
start = if req then req.uploadEndTime else Date.now() start = if req then req.uploadEndTime else Date.now()
if delay if delay
cooldown = {delay} cooldown = {delay}
else else
if post.file if post.file
upSpd = post.file.size / ((req.uploadEndTime - req.uploadStartTime) / $.SECOND) upSpd = post.file.size / ((start - req.uploadStartTime) / $.SECOND)
QR.cooldown.upSpdAccuracy = ((upSpd > QR.cooldown.upSpd * .9) + QR.cooldown.upSpdAccuracy) / 2 QR.cooldown.upSpdAccuracy = ((upSpd > QR.cooldown.upSpd * .9) + QR.cooldown.upSpdAccuracy) / 2
QR.cooldown.upSpd = upSpd QR.cooldown.upSpd = upSpd
isSage = /sage/i.test post.email hasFile = !!post.file
hasFile = !!post.file cooldown = {isReply, hasFile, threadID}
type = unless isReply
'thread'
else if isSage
'sage'
else if hasFile
'file'
else
'post'
cooldown =
isReply: isReply
isSage: isSage
hasFile: hasFile
timeout: start + QR.cooldown.types[type] * $.SECOND
QR.cooldown.cooldowns[start] = cooldown QR.cooldown.cooldowns[start] = cooldown
$.set "cooldown.#{g.BOARD}", QR.cooldown.cooldowns $.set "cooldown.#{g.BOARD}", QR.cooldown.cooldowns
QR.cooldown.start() QR.cooldown.start()
@ -295,12 +281,12 @@ QR =
QR.status() QR.status()
return return
setTimeout QR.cooldown.count, $.SECOND clearTimeout QR.cooldown.timeout
QR.cooldown.timeout = setTimeout QR.cooldown.count, $.SECOND
now = Date.now() now = Date.now()
post = QR.posts[0] post = QR.posts[0]
isReply = post.thread isnt 'new' isReply = post.thread isnt 'new'
isSage = /sage/i.test post.email
hasFile = !!post.file hasFile = !!post.file
seconds = null seconds = null
{types, cooldowns, upSpd, upSpdAccuracy} = QR.cooldown {types, cooldowns, upSpd, upSpdAccuracy} = QR.cooldown
@ -314,26 +300,31 @@ QR =
QR.cooldown.unset start QR.cooldown.unset start
continue continue
if 'timeout' of cooldown
# XXX tmp conversion from previous cooldowns
QR.cooldown.unset start
continue
if isReply is cooldown.isReply if isReply is cooldown.isReply
# Only cooldowns relevant to this post can set the seconds value. # Only cooldowns relevant to this post can set the seconds variable:
# Unset outdated cooldowns that can no longer impact us. # reply cooldown with a reply, thread cooldown with a thread
elapsed = Math.floor (now - start) / $.SECOND
continue if elapsed < 0 # clock changed since then?
type = unless isReply type = unless isReply
'thread' 'thread'
else if isSage and cooldown.isSage else if hasFile
'sage' 'image'
else if hasFile and cooldown.hasFile
'file'
else else
'post' 'reply'
elapsed = Math.floor (now - start) / $.SECOND maxTimer = Math.max types[type], types[type + '_intra'] or 0
if elapsed >= 0 # clock changed since then? unless start <= now <= start + maxTimer * $.SECOND
seconds = Math.max seconds, types[type] - elapsed QR.cooldown.unset start
if Conf['Cooldown Prediction'] and hasFile and upSpd type += '_intra' if isReply and +post.thread is cooldown.threadID
seconds -= Math.floor post.file.size / upSpd * upSpdAccuracy seconds = Math.max seconds, types[type] - elapsed
seconds = Math.max seconds, 0
unless start <= now <= cooldown.timeout
QR.cooldown.unset start
if seconds and Conf['Cooldown Prediction'] and hasFile and upSpd
seconds -= Math.floor post.file.size / upSpd * upSpdAccuracy
seconds = Math.max seconds, 0
# Update the status when we change posting type. # Update the status when we change posting type.
# Don't get stuck at some random number. # Don't get stuck at some random number.
# Don't interfere with progress status updates. # Don't interfere with progress status updates.
@ -1137,7 +1128,7 @@ QR =
else else
post.rm() post.rm()
QR.cooldown.set {req, post, isReply} QR.cooldown.set {req, post, isReply, threadID}
URL = if threadID is postID # new thread URL = if threadID is postID # new thread
"/#{g.BOARD}/res/#{threadID}" "/#{g.BOARD}/res/#{threadID}"