root/lang/ruby/citrus/trunk/lib/citrus/plugin.rb

Revision 6578, 1.5 kB (checked in by cho45, 7 months ago)

lang/ruby/chokan/branches/citrus/lib/citrus/plugin.rb,
lang/ruby/chokan/branches/citrus/spec/core_spec.rb:

Core のテストに DummyCore? をつかわないように。
より実地に近い環境でのテストになってよい

  • Property svn:executable set to *
Line 
1#!/usr/bin/env ruby
2
3require "rubygems"
4require "net/irc"
5
6module Citrus
7        class Plugin
8                include Net::IRC
9                include Constants
10
11                include GetText
12
13                def initialize(core, config)
14                        @core, @config = core, config[self.class.name.sub(/.+::/, "")] || {}
15                end
16
17                def on_uped
18                end
19
20                def on_downed
21                end
22
23                def on_privmsg(prefix, channel, message)
24                end
25
26                def on_talk(prefix, target, message)
27                end
28
29                def on_notice(prefix, channel, message)
30                end
31
32                def on_join(prefix, channel)
33                end
34
35                def on_part(prefix, channel, message)
36                end
37
38                def on_kick(prefix, channels, nicks, message)
39                end
40
41                def on_invite(prefix, nick, channel)
42                end
43
44                def on_ctcp(prefix, target, message)
45                end
46
47                def on_mode(prefix, target, positive_mode, negative_mode)
48                end
49
50                def on_nick(prefix, new_nick)
51                end
52
53                def on_message(m)
54                end
55
56                def log(*args)
57                        prefix = self.class.to_s.sub(/^#<Module:0x[0-9a-f]+>::/, "")
58                        prefix = "[#{prefix}] "
59                        args.each do |l|
60                                @core.log "#{prefix} #{l}"
61                        end
62                end
63
64                def post(command, *params)
65                        m = Message.new(nil, command, params.map {|s|
66                                s.gsub(/\r|\n/, " ")
67                        })
68                        @core.socket << m
69                end
70
71                def datafile(name)
72                        myname = self.class.to_s.sub(/^.+::/, "")
73                        libdir = Pathname.new(@core.config.general["data_dir"]) + myname
74                        libdir.mkpath unless libdir.exist?
75                        libdir + name
76                end
77
78                %w[
79                        privmsg
80                        notice
81                        join
82                        part
83                        kick
84                        invite
85                        mode
86                ].each do |command|
87                        eval <<-EOS
88                                def #{command}(*params)
89                                        post #{command.upcase}, *params
90                                end
91                        EOS
92                end
93        end
94end
95
Note: See TracBrowser for help on using the browser.