wires-ircbot 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f3451cb8200a223c45aa51fcd674345554c2ec47
4
+ data.tar.gz: aa94f22a14421cababfb3f95a74a1f67384b81ea
5
+ SHA512:
6
+ metadata.gz: af3e45f3a4e5e49d28282e3d06092f7d5f01703aa087ef8802a41cf173fb39adb056ae7cbf9f9eb1c566d74e4c5ab0715b8666f1e4811864ec6f9218969e35f4
7
+ data.tar.gz: 55baabb54c833ca8ff895f7cb373cc4800dfaedaa36abab5c3be0896e91bfcb35a7bf7ca04dfc2d50352920161cb93fd4f480511e14fe593a78b99a9785693cc
data/LICENSE ADDED
@@ -0,0 +1,2 @@
1
+ Copyright (c) 2013 : Joe McIlvain
2
+ All rights reserved.
@@ -0,0 +1,44 @@
1
+
2
+
3
+ module IRC
4
+
5
+ def self.parse_message m
6
+ if m.command=='376'
7
+ return [end_of_motd:[
8
+ prefix: m.prefix,
9
+ target: m.args[0],
10
+ text: m.args[1..-1].join(' ')[1..-1]
11
+ ]]
12
+ end
13
+
14
+ if m.command=='PING'
15
+ return [ping:[
16
+ prefix: m.args[0],
17
+ target: (m.args[1] or m.args[0])
18
+ ]]
19
+ end
20
+
21
+ if m.command=='PRIVMSG'
22
+ return [privmsg:[
23
+ user: (User.new m.prefix),
24
+ channel: m.args[0],
25
+ text: m.args[1..-1].join(' ')[1..-1]
26
+ ]]
27
+ end
28
+
29
+ if m.command=='JOIN'
30
+ return [join:[
31
+ user: (User.new m.prefix),
32
+ channel: m.args[0]
33
+ ]]
34
+ end
35
+
36
+ if m.command=='PART'
37
+ return [part:[
38
+ user: (User.new m.prefix),
39
+ channel: m.args[0],
40
+ text: m.args[1..-1].join(' ')[1..-1]
41
+ ]]
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,16 @@
1
+
2
+ module IRC
3
+ class Bot
4
+ def default_handlers
5
+
6
+ on :ping do |e|
7
+ pong e.target
8
+ end
9
+
10
+ on :end_of_motd do |event|
11
+ @channels.each { |c| join c }
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+
2
+ module IRC
3
+ class Bot
4
+
5
+ def privmsg(target, *msg)
6
+ return if target==@nick # Don't try to send to self
7
+ send_command :privmsg, "#{target} :#{msg.join ' '}"
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+
2
+ module IRC
3
+ class User
4
+
5
+ attr_accessor :string, :nick, :user, :host
6
+
7
+ def self.new(str)
8
+ (m = str.match /^(.+?)(?:(?:!(.+?))?@(.+?))?$/) ? super(*m.to_a) : nil
9
+ end
10
+
11
+ def initialize(*args)
12
+ @string, @nick, @user, @host = *args
13
+ end
14
+
15
+ def to_s; @string; end
16
+
17
+ end
18
+ end
@@ -0,0 +1,66 @@
1
+
2
+ require 'wires'
3
+ include Wires::Convenience
4
+
5
+ require 'thread'
6
+ require 'socket'
7
+
8
+ require_relative "ircbot/user"
9
+ require_relative "ircbot/events"
10
+ require_relative "ircbot/handlers"
11
+ require_relative "ircbot/overrides"
12
+
13
+
14
+ module IRC
15
+ class Bot
16
+
17
+ def initialize(**kwargs, &block)
18
+ kwargs.each_pair { |k,v| instance_variable_set("@#{k}",v) }
19
+ instance_eval &block
20
+ init_handlers
21
+ end
22
+
23
+
24
+ def init_handlers
25
+ on :message do |m|
26
+ m = IRC.parse_message m
27
+ begin fire_and_wait m
28
+ rescue ArgumentError
29
+ end
30
+ end
31
+ default_handlers
32
+ end
33
+
34
+
35
+ def connect!
36
+ @socket = TCPSocket.open(@server, @port)
37
+
38
+ nick @nick
39
+ user @nick, 0, '*', (@realname or @nick)
40
+
41
+ while (m = @socket.gets.match /^((?::(.+?) )?(\w+) (.*?)\r\n)$/)
42
+ fire_and_wait [message:[
43
+ *(m[4].split ' '),
44
+ string: m[1].rstrip,
45
+ prefix: m[2],
46
+ command: m[3]]]
47
+ end
48
+ end
49
+
50
+
51
+ def send_command(cmd, *args)
52
+ args.map! { |x| x.to_s }
53
+ cmd = [cmd.to_s.upcase, *args].join(' ')
54
+ @socket.puts(cmd+"\r")
55
+ puts "\033[1m<< #{cmd}\033[22m"
56
+ end
57
+
58
+
59
+ def method_missing(meth, *args)
60
+ @socket and meth!=:to_a ?
61
+ send_command(meth, *args) :
62
+ super
63
+ end
64
+
65
+ end
66
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wires-ircbot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Joe McIlvain
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: wires
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.4.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.4.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: wires-test
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: jemc-reporter
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Wires extension gem for creating flexible, dynamic IRC bots.
70
+ email: joe.eli.mac@gmail.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - lib/wires/ircbot/user.rb
76
+ - lib/wires/ircbot/overrides.rb
77
+ - lib/wires/ircbot/events.rb
78
+ - lib/wires/ircbot/handlers.rb
79
+ - lib/wires/ircbot.rb
80
+ - LICENSE
81
+ homepage: https://github.com/jemc/wires-ircbot/
82
+ licenses:
83
+ - 'Copyright (c) Joe McIlvain. All rights reserved '
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.0.3
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: wires-ircbot
105
+ test_files: []