Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 107 lines (96 sloc) 2.474 kb
a4592d8 Astro littlemuc: mk exec
authored
1 #!/usr/bin/ruby
2
556687e Astro a little MUC
authored
3 require 'readline'
4 require 'xmpp4r'
5 require 'xmpp4r/version'
6 require 'xmpp4r/muc'
7
8 class Color
9 class Reset
10 def self::to_s
11 "\e[0m\e[37m"
12 end
13 end
14
15 class Black < Color
16 def num; 30; end
17 end
18 class Red < Color
19 def num; 31; end
20 end
21 class Green < Color
22 def num; 32; end
23 end
24 class Yellow < Color
25 def num; 33; end
26 end
27 class Blue < Color
28 def num; 34; end
29 end
30 class Magenta < Color
31 def num; 35; end
32 end
33 class Cyan < Color
34 def num; 36; end
35 end
36 class White < Color
37 def num; 37; end
38 end
39
40 def self::to_s
41 new.to_s
42 end
43
44 def to_s
45 "\e[1m\e[#{num}m"
46 end
47 end
48
49 class Time
50 def f
51 strftime '%H:%M'
52 end
53 end
54
027bc9f Astro littlemuc as running at chat@ssh.hq.c3d2.de
authored
55 MUC = 'c3d2@muc.hq.c3d2.de'
556687e Astro a little MUC
authored
56
027bc9f Astro littlemuc as running at chat@ssh.hq.c3d2.de
authored
57 Readline::completion_proc = lambda { |*a| [] }
556687e Astro a little MUC
authored
58 nick = nil
59 while nick.to_s == ''
60 nick = Readline::readline('Your nick: ')
61 end
027bc9f Astro littlemuc as running at chat@ssh.hq.c3d2.de
authored
62 cl = Jabber::Client.new("#{nick}@anonxmpp.hq.c3d2.de/ssh chat@ssh.hq.c3d2.de")
7290e2d Astro littlemuc: add Version::SimpleResponder
authored
63 Jabber::Version::SimpleResponder.new(cl, 'Astro\'s LittleMUC', '0.0',
64 "XMPP4R-#{Jabber::XMPP4R_VERSION} on Ruby-#{RUBY_VERSION}")
556687e Astro a little MUC
authored
65 puts "#{Color::Yellow}Connecting...#{Color::Reset}"
66 cl.connect
67 puts "#{Color::Yellow}Authenticating...#{Color::Reset}"
027bc9f Astro littlemuc as running at chat@ssh.hq.c3d2.de
authored
68 cl.auth_anonymous
556687e Astro a little MUC
authored
69 puts "#{Color::Green}Joining room #{Color::Yellow}#{MUC}#{Color::Reset}"
70 muc = Jabber::MUC::SimpleMUCClient.new(cl)
71 muc.on_message { |time,nick,text|
72 print "#{Color::Blue}[#{time.f}]" if time
73 puts "#{Color::Yellow}<#{nick}> #{Color::Reset}#{text}"
74 }
75 muc.on_room_message { |time,text|
76 print "#{Color::Blue}[#{time.f}]" if time
77 puts "#{Color::Green}#{text}"
78 }
79 muc.on_private_message { |time,nick,text|
80 print "#{Color::Blue}[#{time.f}]" if time
81 puts "#{Color::Red}<#{msg.from.to_s}> #{Color::Yellow}#{msg.body}#{Color::Reset}"
82 }
83 muc.on_join { |time,nick|
84 print "#{Color::Blue}[#{time.f}]" if time
85 puts "#{Color::Magenta}#{nick} has joined#{Color::Reset}"
86 }
87 muc.on_leave { |time,nick|
88 print "#{Color::Blue}[#{time.f}]" if time
89 puts "#{Color::Magenta}#{nick} has left#{Color::Reset}"
90 }
91 muc.on_self_leave { |time,nick|
92 puts "#{Color::Blue}You have left the room#{Color::Reset}"
93 exit
94 }
95 muc.join("#{MUC}/#{nick}")
96 puts "#{Color::Green}Welcome to #{Color::Yellow}#{MUC}#{Color::Reset}"
97
98
99 while line = Readline::readline("")
100 begin
689612c Astro littlemuc: do net send empty messages
authored
101 muc.say line if line.size >= 1
556687e Astro a little MUC
authored
102 rescue Exception => e
103 puts "#{Color::Red}#{e.class}: #{e.to_s}#{Color::Reset}"
104 puts "#{Color::Magenta}#{e.backtrace.join("\n")}"
105 end
106 end
Something went wrong with that request. Please try again.