yaib 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/Gemfile.lock +26 -0
- data/README.textile +5 -0
- data/Rakefile +2 -0
- data/lib/yaib.rb +20 -0
- data/lib/yaib/bot.rb +59 -0
- data/lib/yaib/channel.rb +12 -0
- data/lib/yaib/config.rb +16 -0
- data/lib/yaib/irc.rb +51 -0
- data/lib/yaib/message.rb +24 -0
- data/lib/yaib/respond.rb +15 -0
- data/lib/yaib/responder.rb +8 -0
- data/lib/yaib/string.rb +26 -0
- data/lib/yaib/user.rb +10 -0
- data/lib/yaib/version.rb +3 -0
- data/log/yaib.log +1 -0
- data/spec/yaib_spec.rb +11 -0
- data/yaib.gemspec +21 -0
- metadata +112 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
yaib (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.1.2)
|
10
|
+
mocha (0.9.12)
|
11
|
+
rspec (2.5.0)
|
12
|
+
rspec-core (~> 2.5.0)
|
13
|
+
rspec-expectations (~> 2.5.0)
|
14
|
+
rspec-mocks (~> 2.5.0)
|
15
|
+
rspec-core (2.5.1)
|
16
|
+
rspec-expectations (2.5.0)
|
17
|
+
diff-lcs (~> 1.1.2)
|
18
|
+
rspec-mocks (2.5.0)
|
19
|
+
|
20
|
+
PLATFORMS
|
21
|
+
ruby
|
22
|
+
|
23
|
+
DEPENDENCIES
|
24
|
+
mocha
|
25
|
+
rspec
|
26
|
+
yaib!
|
data/README.textile
ADDED
data/Rakefile
ADDED
data/lib/yaib.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'yaib/version'
|
2
|
+
require 'yaib/irc'
|
3
|
+
require 'yaib/config'
|
4
|
+
require 'yaib/bot'
|
5
|
+
require 'yaib/respond'
|
6
|
+
require 'yaib/channel'
|
7
|
+
require 'yaib/message'
|
8
|
+
require 'yaib/string'
|
9
|
+
require 'yaib/responder'
|
10
|
+
require 'yaib/user'
|
11
|
+
require 'logger'
|
12
|
+
|
13
|
+
module YAIB
|
14
|
+
def self.construct
|
15
|
+
@config = Config.new
|
16
|
+
yield @config
|
17
|
+
@config.log.info("Creating Bot")
|
18
|
+
@bot = Bot.new(@config)
|
19
|
+
end
|
20
|
+
end
|
data/lib/yaib/bot.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
module YAIB
|
2
|
+
class Bot
|
3
|
+
attr_accessor :channels
|
4
|
+
attr_reader :channels, :irc, :config
|
5
|
+
|
6
|
+
def initialize(conf)
|
7
|
+
@config = conf
|
8
|
+
@config.log.info("Connecting to IRC Server")
|
9
|
+
@irc = IRC.new(config.server, config.port, config.nick, config.name, config.host, config.pass, config.log)
|
10
|
+
@channels = {}
|
11
|
+
@users = {}
|
12
|
+
@listeners = []
|
13
|
+
@commands = []
|
14
|
+
@config.listeners.each do |responder|
|
15
|
+
@listeners.push responder.new(config)
|
16
|
+
end
|
17
|
+
@config.commands.each do |responder|
|
18
|
+
@commands.push responder.new(config)
|
19
|
+
end
|
20
|
+
@config.log.info("Joining Channels")
|
21
|
+
config.channels.each do |channel|
|
22
|
+
@channels[channel] = Channel.new(channel, self)
|
23
|
+
end
|
24
|
+
loop do
|
25
|
+
recv
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def recv
|
30
|
+
msg = @irc.recv
|
31
|
+
@config.log.info("Recieved: #{msg}")
|
32
|
+
if msg =~ /PING/
|
33
|
+
@irc.send("PONG #{@config.host}")
|
34
|
+
else
|
35
|
+
if msg.privmsg?
|
36
|
+
msg = YAIB::Message.new(msg, self)
|
37
|
+
@listeners.each do |listen|
|
38
|
+
listen.listen(msg)
|
39
|
+
end
|
40
|
+
@commands.each do |cmd|
|
41
|
+
if msg.message =~ /^#{config.prefix}#{cmd.matcher}/
|
42
|
+
cmd.execute(msg)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def return_user(inick, chan)
|
50
|
+
user = @users[inick]
|
51
|
+
unless user
|
52
|
+
user = User.new(inick, self)
|
53
|
+
@users[inick] = user
|
54
|
+
end
|
55
|
+
user.channel = chan
|
56
|
+
user
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/yaib/channel.rb
ADDED
data/lib/yaib/config.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
module YAIB
|
2
|
+
class Config
|
3
|
+
attr_accessor :nick, :name, :channels, :server, :port, :log, :host, :pass, :listeners, :prefix, :commands
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@nick = "yaib-bot"
|
7
|
+
@name = "yaib-bot"
|
8
|
+
@channels = []
|
9
|
+
@port = 6667
|
10
|
+
@host = "arcath.net"
|
11
|
+
@log = Logger.new("log/yaib.log", "weekly")
|
12
|
+
@listeners = []
|
13
|
+
@prefix = "!"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/yaib/irc.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
module YAIB
|
2
|
+
class IRC
|
3
|
+
require 'socket'
|
4
|
+
|
5
|
+
def initialize(server, port, nick, name, host, pass, log)
|
6
|
+
@log = log
|
7
|
+
@log.info("Creating Connection")
|
8
|
+
@con = TCPSocket.new(server, port)
|
9
|
+
@log.info("Sending Identification")
|
10
|
+
send("USER #{nick} #{host} bla :#{name}")
|
11
|
+
send("NICK #{nick}")
|
12
|
+
@log.info("Getting Response")
|
13
|
+
msg = recv
|
14
|
+
while msg !~ /^:.* 001.*/
|
15
|
+
@log.info("Received: #{msg}")
|
16
|
+
if msg =~ /433/
|
17
|
+
@log.info("Nickname was taken adding a _")
|
18
|
+
nick += "_"
|
19
|
+
send("NICK #{nick}")
|
20
|
+
end
|
21
|
+
msg = @con.recv(512)
|
22
|
+
end
|
23
|
+
@log.info("Setting nickname variable")
|
24
|
+
@nick = nick
|
25
|
+
end
|
26
|
+
|
27
|
+
def recv
|
28
|
+
@con.recv(512)
|
29
|
+
end
|
30
|
+
|
31
|
+
def send(s)
|
32
|
+
s = s.gsub(/\n/,'').gsub(/\r/,'')
|
33
|
+
@log.info("Sending: #{s}")
|
34
|
+
@con.send(s + "\n", 0)
|
35
|
+
end
|
36
|
+
|
37
|
+
def join(channel)
|
38
|
+
@log.info("Joining #{channel}")
|
39
|
+
send("JOIN #{channel}")
|
40
|
+
msg = recv
|
41
|
+
while msg =~ /25[0-5]/
|
42
|
+
msg = nil
|
43
|
+
msg = recv unless msg =~ /255/
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def part(channel)
|
48
|
+
send("PART #{channel}")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/yaib/message.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module YAIB
|
2
|
+
class Message
|
3
|
+
attr_reader :message, :user, :channel
|
4
|
+
|
5
|
+
def initialize(rawmsg, bot)
|
6
|
+
@message, rawchan, rawuser = parse(rawmsg)
|
7
|
+
if rawchan == bot.config.nick then
|
8
|
+
@channel = bot.return_user rawuser, rawuser
|
9
|
+
@user = @channel
|
10
|
+
else
|
11
|
+
@channel = bot.channels[rawchan]
|
12
|
+
@user = bot.return_user rawuser, rawchan
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse(rawmsg)
|
17
|
+
[rawmsg.scan(/.* PRIVMSG .*? \:(.*)/).join, rawmsg.scan(/.* PRIVMSG (.*?) \:.*/).join, rawmsg.split(/\!/)[0].sub(/^\:/,'')]
|
18
|
+
end
|
19
|
+
|
20
|
+
def privmsg(s)
|
21
|
+
@channel.privmsg(s)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/yaib/respond.rb
ADDED
data/lib/yaib/string.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
class String
|
2
|
+
def privmsg?
|
3
|
+
self=~/^\:.*!.*\@.*PRIVMSG\ .* \:.*/
|
4
|
+
end
|
5
|
+
def part?
|
6
|
+
self=~/^\:.*!.*\@.*PART\ \#.*/
|
7
|
+
end
|
8
|
+
def quit?
|
9
|
+
self=~/^\:.*!.*\@.*QUIT\ :.*/
|
10
|
+
end
|
11
|
+
def join?
|
12
|
+
self=~/^\:.*!.*\@.*JOIN\ :\#.*/
|
13
|
+
end
|
14
|
+
def op?
|
15
|
+
self=~/^\:.*!.* MODE \#.* \+o .*/
|
16
|
+
end
|
17
|
+
def deop?
|
18
|
+
self=~/^\:.*!.* MODE \#.* \-o .*/
|
19
|
+
end
|
20
|
+
def invite?
|
21
|
+
self=~/^\:.*!.* INVITE .* \:.*/
|
22
|
+
end
|
23
|
+
def ping?
|
24
|
+
self=~/^PING :.*/
|
25
|
+
end
|
26
|
+
end
|
data/lib/yaib/user.rb
ADDED
data/lib/yaib/version.rb
ADDED
data/log/yaib.log
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Logfile created on Sun Apr 24 11:21:38 +0100 2011 by logger.rb/22285
|
data/spec/yaib_spec.rb
ADDED
data/yaib.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "yaib/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "yaib"
|
7
|
+
s.version = YAIB::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Adam \"Arcath\" Laycock"]
|
10
|
+
s.email = ["gems@arcath.net"]
|
11
|
+
s.homepage = "http://www.arcath.net"
|
12
|
+
s.summary = "Yet Another IRC Bot Framework"
|
13
|
+
|
14
|
+
s.add_development_dependency "rspec"
|
15
|
+
s.add_development_dependency "mocha"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yaib
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Adam "Arcath" Laycock
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-04-28 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rspec
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: mocha
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
description:
|
50
|
+
email:
|
51
|
+
- gems@arcath.net
|
52
|
+
executables: []
|
53
|
+
|
54
|
+
extensions: []
|
55
|
+
|
56
|
+
extra_rdoc_files: []
|
57
|
+
|
58
|
+
files:
|
59
|
+
- Gemfile
|
60
|
+
- Gemfile.lock
|
61
|
+
- README.textile
|
62
|
+
- Rakefile
|
63
|
+
- lib/yaib.rb
|
64
|
+
- lib/yaib/bot.rb
|
65
|
+
- lib/yaib/channel.rb
|
66
|
+
- lib/yaib/config.rb
|
67
|
+
- lib/yaib/irc.rb
|
68
|
+
- lib/yaib/message.rb
|
69
|
+
- lib/yaib/respond.rb
|
70
|
+
- lib/yaib/responder.rb
|
71
|
+
- lib/yaib/string.rb
|
72
|
+
- lib/yaib/user.rb
|
73
|
+
- lib/yaib/version.rb
|
74
|
+
- log/yaib.log
|
75
|
+
- spec/yaib_spec.rb
|
76
|
+
- yaib.gemspec
|
77
|
+
has_rdoc: true
|
78
|
+
homepage: http://www.arcath.net
|
79
|
+
licenses: []
|
80
|
+
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
hash: 3
|
92
|
+
segments:
|
93
|
+
- 0
|
94
|
+
version: "0"
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
hash: 3
|
101
|
+
segments:
|
102
|
+
- 0
|
103
|
+
version: "0"
|
104
|
+
requirements: []
|
105
|
+
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 1.6.2
|
108
|
+
signing_key:
|
109
|
+
specification_version: 3
|
110
|
+
summary: Yet Another IRC Bot Framework
|
111
|
+
test_files:
|
112
|
+
- spec/yaib_spec.rb
|