syndi 0.1.1-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +12 -0
  3. data/CHANGELOG.md +0 -0
  4. data/Gemfile +8 -0
  5. data/LICENSE +28 -0
  6. data/README.md +104 -0
  7. data/Rakefile +30 -0
  8. data/WINDOWS.md +64 -0
  9. data/bin/syndi +102 -0
  10. data/bin/syndi-conf +47 -0
  11. data/conf/example.yml +101 -0
  12. data/docs/Events.md +103 -0
  13. data/docs/Upgrade.md +16 -0
  14. data/ext/csyndi/events.c +50 -0
  15. data/ext/csyndi/extconf.rb +20 -0
  16. data/ext/csyndi/integer.c +53 -0
  17. data/ext/csyndi/libauto.c +37 -0
  18. data/ext/csyndi/logger.c +229 -0
  19. data/include/syndi.h +22 -0
  20. data/include/syndi/csyndi.h +38 -0
  21. data/include/syndi/events.h +19 -0
  22. data/include/syndi/integer.h +17 -0
  23. data/include/syndi/logger.h +56 -0
  24. data/lib/csyndi.so +0 -0
  25. data/lib/syndi.rb +137 -0
  26. data/lib/syndi/actress.rb +12 -0
  27. data/lib/syndi/api.rb +7 -0
  28. data/lib/syndi/api/object.rb +29 -0
  29. data/lib/syndi/bot.rb +266 -0
  30. data/lib/syndi/config.rb +113 -0
  31. data/lib/syndi/dsl/base.rb +74 -0
  32. data/lib/syndi/dsl/irc.rb +13 -0
  33. data/lib/syndi/events.rb +130 -0
  34. data/lib/syndi/irc.rb +8 -0
  35. data/lib/syndi/irc/common.rb +63 -0
  36. data/lib/syndi/irc/library.rb +89 -0
  37. data/lib/syndi/irc/object/channel.rb +21 -0
  38. data/lib/syndi/irc/object/entity.rb +90 -0
  39. data/lib/syndi/irc/object/message.rb +99 -0
  40. data/lib/syndi/irc/object/user.rb +139 -0
  41. data/lib/syndi/irc/protocol.rb +161 -0
  42. data/lib/syndi/irc/protocol/numerics.rb +60 -0
  43. data/lib/syndi/irc/sasl/diffie_hellman.rb +36 -0
  44. data/lib/syndi/irc/sasl/mech.rb +7 -0
  45. data/lib/syndi/irc/sasl/mech/dh_blowfish.rb +83 -0
  46. data/lib/syndi/irc/sasl/mech/plain.rb +39 -0
  47. data/lib/syndi/irc/server.rb +301 -0
  48. data/lib/syndi/irc/state/channel_manager.rb +6 -0
  49. data/lib/syndi/irc/state/support.rb +142 -0
  50. data/lib/syndi/irc/state/user_manager.rb +6 -0
  51. data/lib/syndi/irc/std/commands.rb +99 -0
  52. data/lib/syndi/irc/std/numerics.rb +216 -0
  53. data/lib/syndi/jewel.rb +5 -0
  54. data/lib/syndi/jewel/specification.rb +121 -0
  55. data/lib/syndi/jewel/util.rb +27 -0
  56. data/lib/syndi/rubyext/string.rb +10 -0
  57. data/lib/syndi/verbosity.rb +10 -0
  58. data/lib/syndi/version.rb +38 -0
  59. data/spec/helper.rb +37 -0
  60. data/spec/syndi/events_spec.rb +89 -0
  61. data/tasks/compile.rake +15 -0
  62. data/tasks/install.rake +10 -0
  63. data/tasks/package.rake +13 -0
  64. data/tasks/spec.rake +12 -0
  65. metadata +243 -0
@@ -0,0 +1,21 @@
1
+ # Copyright (c) 2013, Autumn Perrault, et al. All rights reserved.
2
+ # This free software is distributed under the FreeBSD license (see LICENSE).
3
+
4
+ # Namespace: IRC
5
+ module IRC
6
+
7
+ # Namespace: Object
8
+ module Object
9
+
10
+ # A class which represents an individual IRC channel, its associated
11
+ # properties, the users which it contains, and methods to interact with it.
12
+ class Channel
13
+
14
+
15
+ end # class Channel
16
+
17
+ end # module Object
18
+
19
+ end # module IRC
20
+
21
+ # vim: set ts=4 sts=2 sw=2 et:
@@ -0,0 +1,90 @@
1
+ # Copyright (c) 2013, Autumn Perrault, et al. All rights reserved.
2
+ # This free software is distributed under the FreeBSD license (see LICENSE).
3
+
4
+ module Syndi
5
+
6
+ module IRC
7
+
8
+ module Object
9
+
10
+ # A superclass which represents an IRC 'entity'; i.e., a channel or user.
11
+ # It acts as a base for {Syndi::IRC::Object::User} and {Syndi::IRC::Object::Channel}.
12
+ #
13
+ # @api IRC
14
+ # @since 4.0.0
15
+ # @author noxgirl
16
+ #
17
+ # @!attribute [r] irc
18
+ # @return [Syndi::IRC::Server] The IRC server on which this entity exists.
19
+ #
20
+ # @!attribute [r] name
21
+ # @return [String] The name of the entity.
22
+ class Entity
23
+
24
+ attr_reader :irc, :name
25
+
26
+ # New instance.
27
+ #
28
+ # @param [Syndi::IRC::Server] irc The server.
29
+ # @param [Symbol] type Either +:channel+ or +:user+.
30
+ # @param [String] name The name of this entity (nickname or channel name).
31
+ def initialize(irc, type, name)
32
+ @irc = irc
33
+ @entity_type = type
34
+ @name = name
35
+ end
36
+
37
+ # @return [true, false] Whether we're a channel.
38
+ def channel?
39
+ @entity_type == :channel ? true : false
40
+ end
41
+
42
+ # @return [true, false] Whether we're a user.
43
+ def user?
44
+ @entity_type == :user ? true : false
45
+ end
46
+
47
+ # Send a message to this entity. This will additionally divide messages
48
+ # which are too long into multiple messages.
49
+ #
50
+ # This will call irc:onMsg with +self+ and +message+.
51
+ #
52
+ # @param [String] message The message.
53
+ # @param [true, false] notice Whether this should be a /notice as opposed
54
+ # to a /msg.
55
+ def msg(message, notice=false)
56
+
57
+ command = (notice == false ? 'PRIVMSG' : 'NOTICE')
58
+ len = ":#{@irc.nick}!#{@irc.user}@#{@irc.mask} #{command} #@name :".length
59
+ raw = ":#{@irc.nick}!#{@irc.user}@#{@irc.mask} #{command} #@name :#{message}\r\n"
60
+
61
+ if raw.length > 512
62
+
63
+ msgs = []
64
+ nmessage = message
65
+ until raw.length <= 512
66
+ msgs << nmessage.slice!(0, 512-len)
67
+ raw = ":#{@irc.nick}!#{@irc.user}@#{@irc.mask} #{command} #@name :#{nmessage}\r\n"
68
+ end
69
+
70
+ msgs.each { |m| @irc.snd "#{command} #@name :#{m}" }
71
+
72
+ else
73
+ @irc.snd "#{command} #@name :#{message}"
74
+ end
75
+
76
+ $m.events.call 'irc:onMsg', self, message
77
+
78
+ end # def msg
79
+
80
+ def to_s; @name; end
81
+
82
+ end # class Entity
83
+
84
+ end # module Object
85
+
86
+ end # module IRC
87
+
88
+ end # module Syndi
89
+
90
+ # vim: set ts=4 sts=2 sw=2 et:
@@ -0,0 +1,99 @@
1
+ # Copyright (c) 2013, Autumn Perrault, et al. All rights reserved.
2
+ # This free software is distributed under the FreeBSD license (see LICENSE).
3
+
4
+ # Namespace: IRC
5
+ module IRC
6
+
7
+ # Namespace: Object
8
+ module Object
9
+
10
+ # A class which represents an IRC message, its associated properties, and
11
+ # offers methods for working with the message.
12
+ #
13
+ # @since 4.0.0
14
+ # @author noxgirl
15
+ # @api IRC
16
+ #
17
+ # @!attribute [r] irc
18
+ # @return [IRC::Server] The server on which the message was received.
19
+ #
20
+ # @!attribute [r] sender
21
+ # @return [IRC::Object::User] The user from whom the message was received.
22
+ #
23
+ # @!attribute [r] body
24
+ # @return [Array<String>] The body of the message, divided into elements by its spaces.
25
+ #
26
+ # @!attribute [r] nature
27
+ # @return [Symbol] The nature of the message, +:notice+ or +:msg+.
28
+ #
29
+ # @!attribute [r] channel
30
+ # @return [nil] If this message was received privately and not through a channel, this is nil.
31
+ # @return [IRC::Object::Channel] If it was received through a channel, the channel in question.
32
+ # @see #in_channel?
33
+ class Message
34
+
35
+ attr_reader :irc, :sender, :body, :nature, :channel
36
+
37
+ # Process a new message.
38
+ #
39
+ # @param [IRC::Server] irc The server on which the message was received.
40
+ # @param [IRC::Object::User] sender The user from whom the message was received.
41
+ # @param [String] body The body of the message.
42
+ # @param [Symbol] nature The nature of the message: either a +:notice+ or a +:msg+.
43
+ # @param [IRC::Object::Channel] channel If it was received through a channel, the channel.
44
+ #
45
+ # @example
46
+ # message = IRC::Object::Message.new(irc, user, body, :msg, channel)
47
+ def initialize(irc, sender, body, nature=:notice, channel=nil)
48
+
49
+ @irc = irc
50
+ @sender = sender
51
+ @body = body
52
+ @nature = nature
53
+ @channel = channel
54
+
55
+ end
56
+
57
+ # Reply to this message.
58
+ #
59
+ # @param [String] msg The message with which to reply.
60
+ # @param [true, false] in_channel If the response should be in-channel (assuming it was received in a channel), specify +true+.
61
+ # If it should be private regardless of where it was received, specify +false+.
62
+ #
63
+ # @note Essentially reply() exists to simplify the API.
64
+ # Rather than necessitating that commands use endless, illegible conditional
65
+ # nests to determine what to do, reply() is available so the API will just
66
+ # use some common sense to do it for them.
67
+ #
68
+ # @example
69
+ # msg.reply("The bar is of foo, indeed.", true)
70
+ #
71
+ # @todo Unfinished.
72
+ def reply(msg, in_channel)
73
+
74
+ case [@channel.nil, in_channel, @nature]
75
+
76
+ # Respond in-channel if this was sent to a channel *and* in_channel
77
+ # is specified as true.
78
+ when false, true, :msg
79
+ irc.msg(@channel, msg)
80
+
81
+ # Likewise for channel notices.
82
+ when false, true, :notice
83
+
84
+ end
85
+
86
+ end
87
+
88
+ # Checks whether the message was received through a channel.
89
+ #
90
+ # @return [true, false]
91
+ def in_channel?; @channel.nil?; end
92
+
93
+ end # class Message
94
+
95
+ end # module Object
96
+
97
+ end # module IRC
98
+
99
+ # vim: set ts=4 sts=2 sw=2 et:
@@ -0,0 +1,139 @@
1
+ # Copyright (c) 2013, Autumn Perrault, et al. All rights reserved.
2
+ # This free software is distributed under the FreeBSD license (see LICENSE).
3
+
4
+ module Syndi
5
+
6
+ # Namespace: IRC
7
+ module IRC
8
+
9
+ # Namespace: Object
10
+ module Object
11
+
12
+ # A class which represents an individual user on IRC, and which provides
13
+ # useful data regarding said user, and methods using which to interact
14
+ # with the user.
15
+ #
16
+ # @api IRC
17
+ # @since 4.0.0
18
+ # @author noxgirl
19
+ #
20
+ # @!attribute irc
21
+ # @return [Syndi::IRC::Server] The server on which the user is located.
22
+ #
23
+ # @!attribute nick
24
+ # @return [String] The user's nickname.
25
+ #
26
+ # @!attribute user
27
+ # @return [String] If known, the user's username or ident.
28
+ # @return [nil] If unknown.
29
+ # @see #user_known?
30
+ #
31
+ # @!attribute host
32
+ # @return [String] If known, the user's hostname or mask.
33
+ # @return [nil] If unknown.
34
+ # @see #host_known?
35
+ #
36
+ # @!attribute account
37
+ # @return [String] If the user is logged in, their account name.
38
+ # @see #logged_in?
39
+ #
40
+ # @!attribute away
41
+ # @return [true] If the user is away.
42
+ # @return [false] If the user is present.
43
+ class User < Entity
44
+
45
+ attr_reader :nick, :user, :host, :account, :away
46
+
47
+ # Process a new user.
48
+ #
49
+ # @param [Syndi::IRC::Server] irc The server the user is on.
50
+ # @param [String] nickname The user's nickname.
51
+ # @param [String] username The user's username or ident.
52
+ # @param [String] hostname The user's hostname or mask.
53
+ # @param [true, false] away Whether the user is away: +true+ or +false+.
54
+ #
55
+ # @example
56
+ # user = Syndi::IRC::Object::User.new(irc, 'missfoo', 'cowmilk', 'the.night.is.lovely', false)
57
+ def initialize(irc, nickname, username=nil, hostname=nil, away=false)
58
+
59
+ super(irc, :user, nickname) # Entity#initialize
60
+ @nick = nickname
61
+ @user = username
62
+ @host = hostname
63
+ @away = away
64
+ @account = nil
65
+
66
+ end
67
+
68
+ # If the user logs into an account, this is used to specify the name of
69
+ # the account with which ze has identified.
70
+ #
71
+ # @param [String] accountname The name of the account.
72
+ #
73
+ # @example
74
+ # user.login('root')
75
+ def login(accountname)
76
+ unless accountname.nil?
77
+ @account = accountname
78
+ end
79
+ end
80
+
81
+ # If the user logs out of hir account, this is used to update their
82
+ # logged-in status.
83
+ def logout
84
+ @account = nil
85
+ end
86
+
87
+ # Update the user's known away status.
88
+ #
89
+ # @param [true, false] new The user's new away status, which should be +true+ or +false+.
90
+ def away=(new)
91
+ if new == true or new == false
92
+ @away = new
93
+ end
94
+ end
95
+
96
+ # Update the user's known hostname or mask.
97
+ #
98
+ # @param [String] new The user's new hostname.
99
+ def host=(new); @host = new unless new.nil?; end
100
+
101
+ # Update the user's known nickname.
102
+ #
103
+ # @param [String] new The user's new nickname.
104
+ def nick=(new); @nick = new unless new.nil?; end
105
+
106
+ # Update the user's known username or ident.
107
+ #
108
+ # @param [String] new The user's new username.
109
+ def user=(new); @user = new unless new.nil?; end
110
+
111
+ # This will check whether the user's username is known.
112
+ #
113
+ # @return [true] If known.
114
+ # @return [false] If Unknown.
115
+ def user_known?; @user.nil? ? false : true; end
116
+
117
+ # This will check whether the user's hostname is known.
118
+ #
119
+ # @return [true] If known.
120
+ # @return [false] If Unknown.
121
+ def host_known?; @host.nil? ? false : true; end
122
+
123
+ # This will check whether the user is logged in.
124
+ #
125
+ # @return [true] If known.
126
+ # @return [false] If Unknown.
127
+ def logged_in?; @account.nil? ? false : true; end
128
+
129
+ def inspect; "#<Syndi::IRC::Object::User: irc=#@irc nick=#@nick account=#@account>"; end
130
+
131
+ end # class User
132
+
133
+ end # module Object
134
+
135
+ end # module IRC
136
+
137
+ end # module Syndi
138
+
139
+ # vim: set ts=4 sts=2 sw=2 et:
@@ -0,0 +1,161 @@
1
+ # Copyright (c) 2013, Autumn Perrault, et al. All rights reserved.
2
+ # This free software is distributed under the FreeBSD license (see LICENSE).
3
+
4
+ require 'syndi/irc/protocol/numerics'
5
+
6
+ module Syndi
7
+ module IRC
8
+
9
+ # A class for parsing of data per the specifications of the IRC protocol,
10
+ # v3.1.
11
+ #
12
+ # @see http://tools.ietf.org/html/rfc1459
13
+ # @see http://ircv3.atheme.org/
14
+ #
15
+ # @since 4.0.0
16
+ class Protocol
17
+
18
+ # Construct a new IRC data parser.
19
+ #
20
+ # @param [Syndi::IRC::Library] lib The IRC library instance.
21
+ def initialize lib
22
+ extend Syndi::IRC::Protocol::Numerics
23
+ lib.events.on :receive, &method(:parse)
24
+ end
25
+
26
+ # Parse IRC data.
27
+ #
28
+ # @param [Syndi::IRC::Server] irc The IRC connection.
29
+ # @param [String] raw The data received.
30
+ def parse irc, raw
31
+
32
+ params = raw.split(/\s+/)
33
+ command = (raw =~ /^:/ ? params[1] : params[0]).dc
34
+
35
+ # Check if we process this command.
36
+ if respond_to? "on_#{command}"
37
+ send("on_#{command}", irc, raw, params)
38
+ end
39
+
40
+ end
41
+
42
+ # AUTHENTICATE
43
+ #
44
+ # @param [Syndi::IRC::Server] irc The IRC connection.
45
+ # @param [String] raw The data received.
46
+ # @param [Array<String>] params The data received divided by +\s+ through
47
+ # regexp.
48
+ def on_authenticate irc, raw, params
49
+ username = $m.conf['irc'][irc.s]['SASL']['username']
50
+ password = $m.conf['irc'][irc.s]['SASL']['password']
51
+
52
+ if irc.supp.sasl_method == :dh_blowfish
53
+ crypt = Syndi::IRC::SASL::Mech::DHBlowfish.encrypt(username, password, params.last)
54
+ elsif irc.supp.sasl_method == :plain
55
+ crypt = Syndi::IRC::SASL::Mech::Plain.encrypt(username, password, params.last)
56
+ end
57
+
58
+ while crypt.length >= 400
59
+ irc.snd "AUTHENTICATE #{crypt.slice!(0, 400)}"
60
+ end
61
+
62
+ if crypt.length > 0
63
+ irc.snd "AUTHENTICATE #{crypt}"
64
+ else
65
+ irc.snd('AUTHENTICATE +')
66
+ end
67
+ # And we're done!
68
+ end
69
+
70
+ # CAP
71
+ #
72
+ # @param [Syndi::IRC::Server] irc The IRC connection.
73
+ # @param [String] raw The data received.
74
+ # @param [Array<String>] params The data received divided by +\s+ through
75
+ # regexp.
76
+ def on_cap irc, raw, params
77
+ case params[3]
78
+
79
+ when 'LS'
80
+ params[4].gsub!(/^:/, '')
81
+ cap_ls(irc, params[4..-1])
82
+ when 'ACK'
83
+ params[4].gsub!(/^:/, '')
84
+ cap_ack(irc, params[4..-1])
85
+ end
86
+ end
87
+
88
+ # PING
89
+ #
90
+ # Return a PONG.
91
+ #
92
+ # @param [Syndi::IRC::Server] irc The IRC connection.
93
+ # @param [String] raw The data received.
94
+ # @param [Array<String>] params The data received divided by +\s+ through
95
+ # regexp.
96
+ def on_ping irc, raw, params
97
+ irc.snd("PONG #{params[1]}")
98
+ end
99
+
100
+ #######
101
+ private
102
+ #######
103
+
104
+ # CAP LS
105
+ #
106
+ # Currently, Syndi's capabilities include the multi-prefix, sasl,
107
+ # account-notify, away-notify, and extended-join extensions.
108
+ #
109
+ # @param [Syndi::IRC::Server] irc The IRC connection.
110
+ # @param [Array<String>] list List of capabilities.
111
+ def cap_ls irc, list
112
+
113
+ req = []
114
+
115
+ # Every extension possible will be used except SASL, which requires
116
+ # special configuration.
117
+ %w[multi-prefix account-notify away-notify extended-join].each do |ext|
118
+ req.push ext if list.include? ext
119
+ end
120
+
121
+ if $m.conf['irc'][irc.s]['SASL'] and list.include? 'sasl'
122
+ require 'syndi/irc/sasl/mech'
123
+ req.push 'sasl'
124
+ end
125
+
126
+ # Send CAP REQ.
127
+ irc.snd("CAP REQ :#{req.join(' ')}") unless req.empty?
128
+
129
+ end
130
+
131
+ # CAP ACK
132
+ #
133
+ # We must save all capabilities into +irc.supp.cap+, and initiate SASL
134
+ # if possible.
135
+ #
136
+ # @param [Syndi::IRC::Server] irc The IRC connection.
137
+ # @param [Array<String>] list List of capabilities.
138
+ def cap_ack irc, list
139
+
140
+ irc.supp.cap = list
141
+
142
+ if list.include? 'sasl'
143
+ irc.supp.sasl_id << $m.clock.spawn($m.conf['irc'][irc.s]['SASL']['timeout']||10, :once, irc) do |s|
144
+ $m.error "SASL authentication on #{s} failed: authentication procedure timed out."
145
+ s.snd('AUTHENTICATE *')
146
+ s.cap_end
147
+ end
148
+ irc.authenticate :dh_blowfish
149
+ else
150
+ irc.snd('CAP END') # end capability negotiation and complete registration
151
+ end
152
+
153
+ end
154
+
155
+ end # class Protocol
156
+
157
+ end # module IRC
158
+
159
+ end # module Syndi
160
+
161
+ # vim: set ts=4 sts=2 sw=2 et: