<commit_before>local ev = require'ev'

if(not ivar2.timers) then ivar2.timers = {} end

local alarm = function(self, source, destination, time, message)
	local hour = time:match'(%d+)[ht]'
	local min = time:match'(%d+)m'
	local sec = time:match'(%d+)s'

	local duration = 0
	if(hour) then duration = duration + (hour * 60 * 60) end
	if(min) then duration = duration + (min * 60) end
	if(sec) then duration = duration + sec end

	-- 60 days or more?
	local nick = source.nick
	if(duration >= (60 * 60 * 24 * 60) or duration == 0) then
		return self:Msg(dest, src, "%s: :'(", nick)
	end

	local id = 'Alarm: ' .. nick
	if(self.timers[id]) then
		-- message is probably changed.
		self.timers[id]:stop(ivar2.Loop)
	end

	local timer = ev.Timer.new(
		function(loop, timer, revents)
			if(#message == 0) then message = 'Timer finished.' end
			self:Msg('privmsg', destination, source, '%s: %s', nick, message or 'Timer finished.')
		end,
		duration
	)

	self:Notice(source.nick, "I'll poke you at %s.", os.date('%Y-%m-%d %X %Z', os.time() + duration))<commit_msg>alarm: Support timers lasting for n weeks/days.<commit_after>local ev = require'ev'

if(not ivar2.timers) then ivar2.timers = {} end

local alarm = function(self, source, destination, time, message)
	local weeks = time:match'(%d+)[w]'
	local days = time:match'(%d+)[d]'
	local hour = time:match'(%d+)[ht]'
	local min = time:match'(%d+)m'
	local sec = time:match'(%d+)s'

	local duration = 0
	if(weeks) then duration = duration + (weeks * 60 * 60 * 24 * 7) end
	if(days) then duration = duration + (days * 60 * 60 * 24) end
	if(hour) then duration = duration + (hour * 60 * 60) end
	if(min) then duration = duration + (min * 60) end
	if(sec) then duration = duration + sec end

	-- 60 days or more?
	local nick = source.nick
	if(duration >= (60 * 60 * 24 * 60) or duration == 0) then
		return self:Msg(dest, src, "%s: :'(", nick)
	end

	local id = 'Alarm: ' .. nick
	if(self.timers[id]) then
		-- message is probably changed.
		self.timers[id]:stop(ivar2.Loop)
	end

	local timer = ev.Timer.new(
		function(loop, timer, revents)
			if(#message == 0) then message = 'Timer finished.' end
			self:Msg('privmsg', destination, source, '%s: %s', nick, message or 'Timer finished.')
		end,
		duration
	)

	self:Notice(source.nick, "I'll poke you at %s.", os.date('%Y-%m-%d %X %Z', os.time() + duration))
{'fraction_non_alphanumeric': 0.17154989384288746, 'fraction_numerical': 0.024203821656050957, 'mean_word_length': 3.877846790890269, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2177419', 'n_tokens_mistral': 943, 'n_tokens_neox': 847, 'n_words': 266}