-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyamabiko.rb
84 lines (47 loc) · 1.66 KB
/
yamabiko.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/local/bin/ruby -wKs
=begin
= yamabiko.rb version 0.1.0 2001/11/30 - 2002/11/28
Copyright (c) 2001 2002 [email protected]
This program is free software. You can re-distribute and/or
modify this program under the same terms as Ruby itself,
Ruby Distribute License or GNU General Public License.
== What is This?
search quoted words
=end
require 'msnm'
class YamabikoSessionHandler < Net::InstantMessaging::MSNMessenger::SessionHandler
def handle_message( peer_id, peer_nick, msg_header, msg_body )
if msg_header =~ /\r\nContent-Type: text\/plain/um
queue_message(msg_body) # echo ( output as same as input )
end
end
def on_join( peer_id, peer_nick )
queue_message( 'hello ' + peer_id )
end
end
class YamabikoSessionHandlerFactory
def create( msnm, session )
YamabikoSessionHandler.new( msnm, session )
end
end
if __FILE__ == $0
USERID = '***@hotmail.com' # account for an IM agent
PASSWD = '***' # password
# start logging
logfile = $stdout
Net::InstantMessaging::MSNMessenger::ProtocolHandler.logfile = logfile
now = Time.now
process_tag = now.strftime('%Y%m%d%H%M%S') + now.usec.to_s
logfile << "process start #{process_tag}\n"
# initialize service
msnm = Net::InstantMessaging::MSNMessenger.new( USERID, PASSWD,
YamabikoSessionHandlerFactory.new )
msnm.ns.synchronize
msnm.ns.privacy_mode :BLP_ALLOW
# start service
msnm.ns.online
msnm.listen # -> listening...
msnm.logout
# finish logging
logfile << "process finish #{process_tag}\n"
end