erasmus 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +24 -0
- data/Rakefile +2 -0
- data/lib/bots.rb +9 -2
- data/lib/erasmus.rb +39 -14
- data/lib/erasmus/admin.rb +24 -0
- data/lib/erasmus/examples.rb +32 -0
- data/lib/erasmus/github.rb +46 -0
- data/lib/{utils.rb → erasmus/utils.rb} +1 -26
- metadata +22 -27
- data/README.rdoc +0 -18
- data/test/erasmus_test.rb +0 -7
- data/test/test_helper.rb +0 -10
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# erasmus
|
2
|
+
|
3
|
+
A simple, modular IRC bot/framework.
|
4
|
+
|
5
|
+
## Install
|
6
|
+
|
7
|
+
1. edit the file lib/bots.rb and define the bots you want to run.
|
8
|
+
2. Make sure the dependencies are installed:
|
9
|
+
* octopi (And it's dependency packages. I've listed their Ubuntu equivalents below)
|
10
|
+
* libxml2-dev
|
11
|
+
* libxslt-dev
|
12
|
+
* api_cache
|
13
|
+
|
14
|
+
## Note on Patches/Pull Requests
|
15
|
+
|
16
|
+
* Fork the project.
|
17
|
+
* Make your feature addition or bug fix.
|
18
|
+
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
19
|
+
* Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
20
|
+
* Send me a pull request. Bonus points for topic branches.
|
21
|
+
|
22
|
+
## Copyright
|
23
|
+
|
24
|
+
See LICENSE for details.
|
data/Rakefile
ADDED
data/lib/bots.rb
CHANGED
@@ -1,11 +1,18 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
# Define your bots in here.
|
4
|
+
|
3
5
|
require 'erasmus'
|
4
|
-
require 'utils'
|
6
|
+
require 'erasmus/utils'
|
7
|
+
require 'erasmus/github'
|
8
|
+
require 'erasmus/examples'
|
9
|
+
require 'erasmus/admin'
|
5
10
|
|
6
11
|
Erasmus::Bot.new("irc.freenode.net").join([
|
7
12
|
Erasmus::Channel.new('erasmus-testing') \
|
8
|
-
.extend(
|
13
|
+
.extend(Examples::Foo) \
|
14
|
+
.extend(Github::Issues) \
|
15
|
+
.extend(Admin::Control) \
|
9
16
|
.extend(Utils::Changelog) \
|
10
17
|
.extend(Utils::FlagFloodProtection), \
|
11
18
|
Erasmus::Channel.new('erasmus-testing2'),
|
data/lib/erasmus.rb
CHANGED
@@ -4,10 +4,12 @@ require 'socket'
|
|
4
4
|
|
5
5
|
module Erasmus
|
6
6
|
class Bot
|
7
|
-
attr_reader :nick
|
7
|
+
attr_reader :nick, :owner, :server
|
8
8
|
|
9
|
-
def initialize(server, port=6667)
|
10
|
-
@
|
9
|
+
def initialize(server, nick='mpu_test', owner='xiong_chiamiov', port=6667)
|
10
|
+
@server = server
|
11
|
+
@nick = nick
|
12
|
+
@owner = owner
|
11
13
|
@channels = {}
|
12
14
|
@socket = TCPSocket.open(server, port)
|
13
15
|
say "NICK #{@nick}"
|
@@ -46,6 +48,26 @@ module Erasmus
|
|
46
48
|
say "NOTICE ##{channel} :#{message}"
|
47
49
|
end
|
48
50
|
|
51
|
+
def whois(user)
|
52
|
+
say "WHOIS #{user}"
|
53
|
+
end
|
54
|
+
|
55
|
+
def acc(user)
|
56
|
+
if @server.include? 'freenode'
|
57
|
+
pm_user('nickserv', "ACC #{user}")
|
58
|
+
elsif @server.include? 'rizon'
|
59
|
+
pm_user('nickserv', "STATUS #{user}")
|
60
|
+
end
|
61
|
+
|
62
|
+
msg = @socket.gets
|
63
|
+
puts msg
|
64
|
+
return msg.rstrip()[-1..-1]
|
65
|
+
end
|
66
|
+
|
67
|
+
def handle_private_message(user, host, message)
|
68
|
+
pm_user(user, "erasmus")
|
69
|
+
end
|
70
|
+
|
49
71
|
def run
|
50
72
|
until @socket.eof? do
|
51
73
|
msg = @socket.gets
|
@@ -71,15 +93,12 @@ module Erasmus
|
|
71
93
|
end
|
72
94
|
end
|
73
95
|
|
74
|
-
def handle_private_message(user, host, message)
|
75
|
-
pm_user(user, 'hey!')
|
76
|
-
end
|
77
|
-
|
78
96
|
def quit
|
79
97
|
@channels.each do |name, channel|
|
80
98
|
channel.part
|
81
99
|
end
|
82
100
|
say 'QUIT'
|
101
|
+
exit
|
83
102
|
end
|
84
103
|
end
|
85
104
|
|
@@ -119,22 +138,26 @@ module Erasmus
|
|
119
138
|
@server.notice_channel(@name, message)
|
120
139
|
end
|
121
140
|
|
141
|
+
def whois(user)
|
142
|
+
@server.whois(user)
|
143
|
+
end
|
144
|
+
|
122
145
|
def handle_public_message(user, host, message)
|
123
|
-
if message =~ /^#{@server.nick}: (.*)$/
|
124
|
-
|
146
|
+
if message =~ /^#{@server.nick}: (\S+)\s(.*)$/
|
147
|
+
command = $1
|
148
|
+
arguments = $2.split(/\s/)
|
149
|
+
handle_flag(user, host, command, arguments, :hilight)
|
125
150
|
elsif message =~ /^#{@flag}(\S+)\s(.*)$/
|
126
151
|
command = $1
|
127
152
|
arguments = $2.split(/\s/)
|
128
|
-
handle_flag(user, host, command, arguments)
|
153
|
+
handle_flag(user, host, command, arguments, :flag)
|
129
154
|
end
|
130
155
|
end
|
131
156
|
|
132
|
-
def
|
133
|
-
end
|
134
|
-
def handle_flag(user, host, flag, arguments)
|
157
|
+
def handle_flag(user, host, flag, arguments, source)
|
135
158
|
if allowed? user
|
136
159
|
begin
|
137
|
-
@flags[flag].call(user, host, arguments)
|
160
|
+
@flags[flag].call(user, host, arguments, source)
|
138
161
|
rescue NoMethodError
|
139
162
|
#say("Sorry, there's no action associated with the flag #{flag}.")
|
140
163
|
end
|
@@ -159,4 +182,6 @@ module Erasmus
|
|
159
182
|
|
160
183
|
class NotAllowedException < StandardError
|
161
184
|
end
|
185
|
+
class AuthenticationError < StandardError
|
186
|
+
end
|
162
187
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Admin
|
2
|
+
module Control
|
3
|
+
def su(user)
|
4
|
+
# check if owner and idented
|
5
|
+
if !(user == @server.owner and @server.acc(user) == "3")
|
6
|
+
raise Erasmus::AuthenticationError
|
7
|
+
end
|
8
|
+
end
|
9
|
+
def self.extended(obj)
|
10
|
+
obj.instance_eval {
|
11
|
+
@flags['stop'] = lambda { |user, host, arguments, source|
|
12
|
+
begin
|
13
|
+
su user
|
14
|
+
@server.quit
|
15
|
+
rescue Erasmus::AuthenticationError
|
16
|
+
notice_user(user, "I'm sorry, but I can't allow you to do that.")
|
17
|
+
rescue Exception => e
|
18
|
+
raise
|
19
|
+
end
|
20
|
+
}
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Examples
|
2
|
+
module Foo
|
3
|
+
def handle_private_message(user, host, message)
|
4
|
+
pm_user(user, 'hey!')
|
5
|
+
end
|
6
|
+
|
7
|
+
# this is how we handle flags that the bot will respond to
|
8
|
+
def self.extended(obj)
|
9
|
+
obj.instance_eval {
|
10
|
+
@flags['foo'] = lambda { |user, host, arguments, source|
|
11
|
+
say('bar')
|
12
|
+
}
|
13
|
+
@flags['bar'] = lambda { |user, host, arguments, source|
|
14
|
+
if source == :hilight
|
15
|
+
notice_user(user, 'baz')
|
16
|
+
end
|
17
|
+
if source == :flag
|
18
|
+
say("Hey everyone, #{user} wants to bar.")
|
19
|
+
end
|
20
|
+
}
|
21
|
+
@flags['baz'] = lambda { |user, host, arguments, source|
|
22
|
+
notice_channel('not baz!')
|
23
|
+
}
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def join
|
28
|
+
@server.say "JOIN ##{@name}"
|
29
|
+
say "#{1.chr}ACTION is here to help#{1.chr}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Github
|
2
|
+
module Issues
|
3
|
+
require 'rubygems'
|
4
|
+
require 'octopi'
|
5
|
+
def self.extended(obj)
|
6
|
+
obj.instance_eval {
|
7
|
+
repo = Octopi::Repository.find("xiongchiamiov", "erasmus")
|
8
|
+
|
9
|
+
@flags['issues'] = lambda { |user, host, arguments, source|
|
10
|
+
if arguments[0] and arguments[0] =~ /^\d+$/
|
11
|
+
begin
|
12
|
+
# this only gives up after receiving 10 403s,
|
13
|
+
# making it very easy to build up a large queue
|
14
|
+
# perhaps we should get all issues, and just index?
|
15
|
+
# http://github.com/fcoury/octopi/issues/#issue/36
|
16
|
+
issue = repo.issue(arguments[0])
|
17
|
+
say "Issue #{issue.number}: #{issue.title}"
|
18
|
+
rescue Octopi::APIError
|
19
|
+
say "No issue with id #{arguments[0]} found."
|
20
|
+
end
|
21
|
+
else
|
22
|
+
begin
|
23
|
+
repo.issues.each do |issue|
|
24
|
+
say "Issue #{issue.number}: #{issue.title}"
|
25
|
+
end
|
26
|
+
rescue Octopi::APIError
|
27
|
+
say "I'm having a problem connecting to GitHub. Try again in a bit."
|
28
|
+
end
|
29
|
+
end
|
30
|
+
}
|
31
|
+
@flags['issue-detail'] = lambda { |user, host, arguments, source|
|
32
|
+
if arguments[0] and arguments[0] =~ /^\d+$/
|
33
|
+
begin
|
34
|
+
issue = repo.issue(arguments[0])
|
35
|
+
say "Issue #{issue.number}: #{issue.title} (reported by #{issue.user})"
|
36
|
+
say "#{issue.body}"
|
37
|
+
say 'http://github.com/xiongchiamiov/erasmus/issues/#issue/' + issue.number.to_s
|
38
|
+
rescue Octopi::APIError
|
39
|
+
say "No issue with id #{arguments[0]} found."
|
40
|
+
end
|
41
|
+
end
|
42
|
+
}
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -1,33 +1,8 @@
|
|
1
1
|
module Utils
|
2
|
-
module Foo
|
3
|
-
def handle_hilight(user, host, message)
|
4
|
-
hilight_user(user, 'whatcha want?')
|
5
|
-
end
|
6
|
-
|
7
|
-
def self.extended(obj)
|
8
|
-
obj.instance_eval {
|
9
|
-
@flags['foo'] = lambda { |user, host, arguments|
|
10
|
-
say('bar')
|
11
|
-
}
|
12
|
-
@flags['bar'] = lambda { |user, host, arguments|
|
13
|
-
notice_user(user, 'baz')
|
14
|
-
}
|
15
|
-
@flags['baz'] = lambda { |user, host, arguments|
|
16
|
-
notice_channel('not baz!')
|
17
|
-
}
|
18
|
-
}
|
19
|
-
end
|
20
|
-
|
21
|
-
def join
|
22
|
-
@server.say "JOIN ##{@name}"
|
23
|
-
say "#{1.chr}ACTION is here to help#{1.chr}"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
2
|
module Changelog
|
28
3
|
def self.extended(obj)
|
29
4
|
obj.instance_eval {
|
30
|
-
@flags['changelog'] = lambda { |user, host, arguments|
|
5
|
+
@flags['changelog'] = lambda { |user, host, arguments, source|
|
31
6
|
if arguments[0] and arguments[0] =~ /^[\w\d "]+$/
|
32
7
|
output = `git --no-pager log --pretty=format:%s --since=#{arguments[0]}`
|
33
8
|
else
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: erasmus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- xiongchiamiov
|
@@ -11,37 +11,33 @@ cert_chain: []
|
|
11
11
|
|
12
12
|
date: 2009-10-15 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
16
|
-
|
17
|
-
type: :development
|
18
|
-
version_requirement:
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: "0"
|
24
|
-
version:
|
25
|
-
description: "TODO: longer description of your gem"
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: A simple, modular irc bot/framework
|
26
17
|
email: xiong.chiamiov@gmail.com
|
27
18
|
executables: []
|
28
19
|
|
29
20
|
extensions: []
|
30
21
|
|
31
|
-
extra_rdoc_files:
|
32
|
-
|
33
|
-
- README.rdoc
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
34
24
|
files:
|
35
|
-
-
|
36
|
-
-
|
37
|
-
- lib/utils.rb
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
38
27
|
- LICENSE
|
39
|
-
-
|
28
|
+
- lib/erasmus.rb
|
29
|
+
- lib/erasmus/examples.rb
|
30
|
+
- lib/erasmus/utils.rb
|
31
|
+
- lib/erasmus/github.rb
|
32
|
+
- lib/erasmus/admin.rb
|
33
|
+
- lib/bots.rb
|
40
34
|
has_rdoc: true
|
41
35
|
homepage: http://github.com/xiongchiamiov/erasmus
|
36
|
+
licenses: []
|
37
|
+
|
42
38
|
post_install_message:
|
43
|
-
rdoc_options:
|
44
|
-
|
39
|
+
rdoc_options: []
|
40
|
+
|
45
41
|
require_paths:
|
46
42
|
- lib
|
47
43
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -59,10 +55,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
55
|
requirements: []
|
60
56
|
|
61
57
|
rubyforge_project:
|
62
|
-
rubygems_version: 1.3.
|
58
|
+
rubygems_version: 1.3.5
|
63
59
|
signing_key:
|
64
|
-
specification_version:
|
60
|
+
specification_version: 3
|
65
61
|
summary: A simple, modular irc bot/framework
|
66
|
-
test_files:
|
67
|
-
|
68
|
-
- test/test_helper.rb
|
62
|
+
test_files: []
|
63
|
+
|
data/README.rdoc
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
= erasmus
|
2
|
-
|
3
|
-
A simple, modular irc bot/framework.
|
4
|
-
|
5
|
-
== Note on Patches/Pull Requests
|
6
|
-
|
7
|
-
* Fork the project.
|
8
|
-
* Make your feature addition or bug fix.
|
9
|
-
* Add tests for it. This is important so I don't break it in a
|
10
|
-
future version unintentionally.
|
11
|
-
* Commit, do not mess with rakefile, version, or history.
|
12
|
-
(if you want to have your own version, that is fine but
|
13
|
-
bump version in a commit by itself I can ignore when I pull)
|
14
|
-
* Send me a pull request. Bonus points for topic branches.
|
15
|
-
|
16
|
-
== Copyright
|
17
|
-
|
18
|
-
Copyright (c) 2009 xiongchiamiov. See LICENSE for details.
|
data/test/erasmus_test.rb
DELETED
data/test/test_helper.rb
DELETED