root/lang/ruby/nadoka plugins/timerbot.nb @ 3784

Revision 3784, 1.8 kB (checked in by shyouhei, 5 years ago)

lang/ruby/nadoka plugins: import.

Line 
1#!/bin/ruby -Ku
2# Copyright(c) 2005 URABE, Shyouhei.
3#
4# Permission is hereby granted, free of  charge, to any person obtaining a copy
5# of  this code, to  deal in  the code  without restriction,  including without
6# limitation  the rights  to  use, copy,  modify,  merge, publish,  distribute,
7# sublicense, and/or sell copies of the code, and to permit persons to whom the
8# code is furnished to do so, subject to the following conditions:
9#
10#        The above copyright notice and this permission notice shall be
11#        included in all copies or substantial portions of the code.
12#
13# THE  CODE IS  PROVIDED "AS  IS",  WITHOUT WARRANTY  OF ANY  KIND, EXPRESS  OR
14# IMPLIED,  INCLUDING BUT  NOT LIMITED  TO THE  WARRANTIES  OF MERCHANTABILITY,
15# FITNESS FOR A PARTICULAR PURPOSE  AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
16# AUTHOR  OR  COPYRIGHT  HOLDER BE  LIABLE  FOR  ANY  CLAIM, DAMAGES  OR  OTHER
17# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18# OUT OF  OR IN CONNECTION WITH  THE CODE OR THE  USE OR OTHER  DEALINGS IN THE
19# CODE.
20
21require 'time'
22
23class TimerBot < Nadoka::NDK_Bot
24        def on_privmsg p, c, s
25                return unless /\A *(alarm|alert)/n.match(s)
26                m = /\A *(alarm|alert) *(on|at) *(.*) *>(.*)/e.match(NKF.nkf('-Jem0', s))
27                return if m.nil?
28                t = Time.parse m[3]
29                if t > Time.now then
30                        Thread.start do
31                                sleep t - Time.now
32                                send_privmsg c, "#{p.nick}: #{NKF.nkf('-Ejm0', m[4])} (timer)"
33                        end
34                        send_notice c, "ok, will send you a notice on #{t}"
35                else
36                        send_notice c, "#{Time.now - t} sec before..."
37                end
38        rescue
39                send_notice c, "malformed request, sorry."
40        end
41end
42
43
44# Local Variables:
45# mode: ruby
46# coding: utf-8
47# indent-tabs-mode: t
48# tab-width: 3
49# ruby-indent-level: 3
50# fill-column: 79
51# default-justification: full
52# End:
53# vi: ts=3 sw=3
Note: See TracBrowser for help on using the browser.