meimei 0.1.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +20 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +40 -9
- data/VERSION +1 -0
- data/cron.sh +8 -0
- data/lib/meimei/client.rb +18 -8
- data/lib/meimei.rb +0 -25
- data/plugins/an2.rb +5 -0
- data/plugins/ann.rb +47 -0
- data/plugins/autoping.rb +5 -0
- data/plugins/cco.rb +4 -0
- data/plugins/choose.rb +13 -0
- data/plugins/courage.rb +7 -0
- data/plugins/dan.rb +13 -0
- data/plugins/dg.rb +25 -0
- data/plugins/dwiki.rb +6 -0
- data/plugins/eta.rb +43 -0
- data/plugins/g.rb +30 -0
- data/plugins/gc.rb +34 -0
- data/plugins/godfinger.rb +9 -0
- data/plugins/hammerhell.rb +7 -0
- data/plugins/hanase.rb +14 -0
- data/plugins/hellheaven.rb +6 -0
- data/plugins/help.rb +7 -0
- data/plugins/jtime.rb +9 -0
- data/plugins/nai_ja_nai.rb +4 -0
- data/plugins/note.rb +10 -0
- data/plugins/ranking.rb +422 -0
- data/plugins/reload.rb +3 -0
- data/plugins/retard.rb +4 -0
- data/plugins/rs.rb +8 -0
- data/plugins/shiningfinger.rb +9 -0
- data/plugins/shuffle.rb +3 -0
- data/plugins/sugei_inaka.rb +4 -0
- data/plugins/suki_dakara.rb +4 -0
- data/plugins/ts.rb +25 -0
- data/plugins/tsundere.rb +5 -0
- data/plugins/tt.rb +50 -0
- data/plugins/ttt.rb +5 -0
- data/plugins/uptime.rb +20 -0
- data/plugins/wawawa.rb +5 -0
- data/plugins/weather.rb +39 -0
- data/test/helper.rb +18 -0
- data/test/test_meimei.rb +7 -0
- metadata +139 -56
- data/CHANGES +0 -10
- data/LICENSE +0 -31
- data/README +0 -30
- data/lib/meimei/gemspec.rb +0 -45
- data/lib/meimei/specification.rb +0 -128
- data/lib/meimei/version.rb +0 -18
data/.document
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 albert
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= meimei
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to meimei
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 albert. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
CHANGED
@@ -1,14 +1,45 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require 'bundler'
|
2
|
+
require 'jeweler'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
begin
|
5
|
+
Bundler.setup(:default, :development)
|
6
|
+
rescue Bundler::BundlerError => e
|
7
|
+
$stderr.puts e.message
|
8
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
9
|
+
exit e.status_code
|
10
|
+
end
|
9
11
|
|
10
|
-
|
12
|
+
Jeweler::Tasks.new do |gem|
|
13
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
14
|
+
gem.name = "meimei"
|
15
|
+
gem.homepage = "http://github.com/r888888888/meimei"
|
16
|
+
gem.license = "MIT"
|
17
|
+
gem.summary = %Q{Minimalistic IRC bot framework}
|
18
|
+
gem.description = %Q{If all you need is a simple infobot and don't need a full RFC1459 implementation.}
|
19
|
+
gem.email = "r888888888@gmail.com"
|
20
|
+
gem.authors = ["r888888888"]
|
21
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
22
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
23
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
24
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
11
27
|
|
12
|
-
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
13
34
|
|
35
|
+
task :default => :test
|
14
36
|
|
37
|
+
require 'rdoc/task'
|
38
|
+
Rake::RDocTask.new do |rdoc|
|
39
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
40
|
+
|
41
|
+
rdoc.rdoc_dir = 'rdoc'
|
42
|
+
rdoc.title = "meimei #{version}"
|
43
|
+
rdoc.rdoc_files.include('README*')
|
44
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.3.0
|
data/cron.sh
ADDED
data/lib/meimei/client.rb
CHANGED
@@ -118,7 +118,7 @@ module Meimei
|
|
118
118
|
def check_command_plugins(msg)
|
119
119
|
@command_plugins.each do |name, block, options|
|
120
120
|
begin
|
121
|
-
if name
|
121
|
+
if name =~ /^!/
|
122
122
|
if msg =~ /^#{name}\b/
|
123
123
|
msg = msg.gsub(/!\S+\s*/, "")
|
124
124
|
block.call(msg)
|
@@ -154,18 +154,15 @@ module Meimei
|
|
154
154
|
while @running
|
155
155
|
@servers.each do |server|
|
156
156
|
unless server.is_connected
|
157
|
-
if server.reconnect_delay_passed? && server.connect
|
157
|
+
if server.reconnect_delay_passed? && server.connect
|
158
158
|
server.write("PASS #{@password}") if @password
|
159
159
|
server.write("NICK #{@nick}")
|
160
160
|
server.write("USER #{@username} hostname servername :#{@username}")
|
161
|
-
server.autojoin.each do |channel|
|
162
|
-
server.write("JOIN #{channel}")
|
163
|
-
end
|
164
161
|
end
|
165
162
|
end
|
166
163
|
|
167
|
-
|
168
|
-
|
164
|
+
autoping()
|
165
|
+
check_timer_plugins()
|
169
166
|
|
170
167
|
@current_server = self.select()
|
171
168
|
|
@@ -173,7 +170,8 @@ module Meimei
|
|
173
170
|
msg = @current_server.read
|
174
171
|
|
175
172
|
if msg != nil
|
176
|
-
|
173
|
+
autojoin_on_recognize(server, msg)
|
174
|
+
process_message(msg)
|
177
175
|
end
|
178
176
|
end
|
179
177
|
end
|
@@ -211,6 +209,18 @@ module Meimei
|
|
211
209
|
server.write("PRIVMSG #{to} :#{msg}")
|
212
210
|
end
|
213
211
|
|
212
|
+
def autojoin_on_recognize(server, msg)
|
213
|
+
if msg =~ /^:\S+ MODE #{@nick} :\+r/
|
214
|
+
autojoin(server)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
def autojoin(server)
|
219
|
+
server.autojoin.each do |channel|
|
220
|
+
server.write("JOIN #{channel}")
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
214
224
|
# Parses a messages and dispatches as necessary.
|
215
225
|
def process_message(msg)
|
216
226
|
@current_from = nil
|
data/lib/meimei.rb
CHANGED
@@ -1,25 +0,0 @@
|
|
1
|
-
module Meimei
|
2
|
-
|
3
|
-
ROOT_DIR = File.expand_path(File.join(File.dirname(__FILE__),".."))
|
4
|
-
LIB_DIR = File.join(ROOT_DIR,"lib").freeze
|
5
|
-
RESOURCE_DIR = File.join(ROOT_DIR,"resources").freeze
|
6
|
-
|
7
|
-
#
|
8
|
-
# Utility method to require all files ending in .rb in the directory
|
9
|
-
# with the same name as this file minus .rb
|
10
|
-
#
|
11
|
-
def require_all_libs_relative_to(fname)
|
12
|
-
prepend = File.basename(fname,".rb")
|
13
|
-
search_me = File.join(File.dirname(fname),prepend)
|
14
|
-
|
15
|
-
Dir.entries(search_me).each do |rb|
|
16
|
-
if File.extname(rb) == ".rb" then
|
17
|
-
require "#{prepend}/#{File.basename(rb,".rb")}"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
module_function :require_all_libs_relative_to
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
Meimei.require_all_libs_relative_to(__FILE__)
|
data/plugins/an2.rb
ADDED
data/plugins/ann.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'cgi'
|
3
|
+
require 'uri'
|
4
|
+
require 'timeout'
|
5
|
+
|
6
|
+
define_plugin("!ann") do |msg|
|
7
|
+
@ann_cache ||= {}
|
8
|
+
|
9
|
+
name = msg
|
10
|
+
|
11
|
+
if @ann_cache[name]
|
12
|
+
reply @ann_cache[name]
|
13
|
+
next
|
14
|
+
end
|
15
|
+
|
16
|
+
if name =~ /^(anime|manga|people|company) /
|
17
|
+
type = $1
|
18
|
+
name = name.gsub(/^(?:anime|manga|people|company) /, "")
|
19
|
+
else
|
20
|
+
type = "anime|manga|people|company"
|
21
|
+
end
|
22
|
+
|
23
|
+
uri = URI.parse("http://www.animenewsnetwork.com/encyclopedia/search.php?searchbox=#{CGI.escape(name)}")
|
24
|
+
|
25
|
+
begin
|
26
|
+
Net::HTTP.start("www.animenewsnetwork.com", 80) do |http|
|
27
|
+
resp = http.get("/encyclopedia/search/name?q=" + CGI.escape(name))
|
28
|
+
links = resp.body.scan(/<a href="\/encyclopedia\/(#{type})\.php\?id=(\d+)">(.+?)<\/a>/)
|
29
|
+
matches = []
|
30
|
+
links[0, 3].each do |l|
|
31
|
+
matches << "#{l[0]}.php?id=#{l[1]}"
|
32
|
+
end
|
33
|
+
|
34
|
+
if matches.any?
|
35
|
+
link = "http://www.animenewsnetwork.com/encyclopedia/#{matches[0]}"
|
36
|
+
@ann_cache[name] = link
|
37
|
+
reply link
|
38
|
+
else
|
39
|
+
reply "no matches found"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
rescue Timeout
|
43
|
+
reply "timeout"
|
44
|
+
rescue Exception => e
|
45
|
+
reply e.to_s
|
46
|
+
end
|
47
|
+
end
|
data/plugins/autoping.rb
ADDED
data/plugins/cco.rb
ADDED
data/plugins/choose.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
define_plugin("!choose") do |msg|
|
2
|
+
if rand(100) <= 2
|
3
|
+
reply "You decide."
|
4
|
+
else
|
5
|
+
choices = msg.split(/,\s*/)
|
6
|
+
special = choices.grep(/only everyone is/)
|
7
|
+
if special.any?
|
8
|
+
reply special.pick_random
|
9
|
+
else
|
10
|
+
reply choices.pick_random
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/plugins/courage.rb
ADDED
data/plugins/dan.rb
ADDED
data/plugins/dg.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'json'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'cgi'
|
5
|
+
require 'pp'
|
6
|
+
|
7
|
+
define_plugin("!dg") do |msg|
|
8
|
+
api_key = CGI.escape("AIzaSyBbqMEONSx_cqrBhk0GXNbzZw_E3bNgNwQ")
|
9
|
+
cx = CGI.escape("003806434433967703265:4z2lw9zljym")
|
10
|
+
query = CGI.escape(msg)
|
11
|
+
url = "https://www.googleapis.com/customsearch/v1?key=#{api_key}&q=#{query}&cx=#{cx}"
|
12
|
+
text = open(url).read
|
13
|
+
json = JSON.parse(text)
|
14
|
+
urls = []
|
15
|
+
|
16
|
+
if json["items"]
|
17
|
+
urls = json["items"].select {|x| x["link"] =~ /us\/post/}.map {|x| x["link"]}
|
18
|
+
end
|
19
|
+
|
20
|
+
if urls.any?
|
21
|
+
reply urls.slice(0, 5).join(" | ")
|
22
|
+
else
|
23
|
+
reply "No matches"
|
24
|
+
end
|
25
|
+
end
|
data/plugins/dwiki.rb
ADDED
data/plugins/eta.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'net/http'
|
3
|
+
require 'nokogiri'
|
4
|
+
|
5
|
+
define_plugin("!eta") do |msg|
|
6
|
+
query = msg
|
7
|
+
|
8
|
+
if query.strip == ""
|
9
|
+
reply "http://www.mahou.org/Showtime"
|
10
|
+
else
|
11
|
+
Net::HTTP.start("www.mahou.org", 80) do |http|
|
12
|
+
resp = http.get("/Showtime")
|
13
|
+
if resp.code !~ /200/
|
14
|
+
reply "Could not fetch web page, try again later"
|
15
|
+
break
|
16
|
+
end
|
17
|
+
|
18
|
+
answer = "Show not found"
|
19
|
+
doc = Nokogiri::HTML(resp.body)
|
20
|
+
doc.xpath('//table[@summary="Currently Airing"]/tr/td/table/tr').each do |element|
|
21
|
+
name = element.children[2].text
|
22
|
+
eta = element.children[12].text
|
23
|
+
if name =~ /#{query}/i
|
24
|
+
answer = "ETA for #{name}: #{eta}"
|
25
|
+
break
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
if answer == "Show not found"
|
30
|
+
doc.xpath('//table[@summary="Starting Soon"]/tr/td/table/tr').each do |element|
|
31
|
+
name = element.children[2].text
|
32
|
+
eta = element.children[16].text
|
33
|
+
if name =~ /#{query}/i
|
34
|
+
answer = "ETA for #{name}: #{eta}"
|
35
|
+
break
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
reply answer
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/plugins/g.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "net/http"
|
5
|
+
require "uri"
|
6
|
+
require "json"
|
7
|
+
require "timeout"
|
8
|
+
require "cgi"
|
9
|
+
|
10
|
+
define_plugin("!g") do |msg|
|
11
|
+
query = msg
|
12
|
+
|
13
|
+
if query.any?
|
14
|
+
begin
|
15
|
+
Net::HTTP.start("ajax.googleapis.com", 80) do |http|
|
16
|
+
resp = http.get("/ajax/services/search/web?v=1.0&q=" + URI.escape(query, /./))
|
17
|
+
json = JSON.parse(resp.body)
|
18
|
+
answers = json["responseData"]["results"].map {|x| "\00311" + CGI.unescapeHTML(x["titleNoFormatting"]) + " \00307" + URI.unescape(x["url"])}
|
19
|
+
answers.each do |answer|
|
20
|
+
reply answer
|
21
|
+
end
|
22
|
+
end
|
23
|
+
rescue Timeout
|
24
|
+
reply "timeout"
|
25
|
+
rescue Exception => e
|
26
|
+
reply e.to_s
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
data/plugins/gc.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "net/http"
|
5
|
+
require "uri"
|
6
|
+
require "json"
|
7
|
+
require "timeout"
|
8
|
+
require "cgi"
|
9
|
+
|
10
|
+
define_plugin("!gc") do |msg|
|
11
|
+
app = "meimei"
|
12
|
+
app_id = "WQJUTR-EXQT7VL45T"
|
13
|
+
url = URI.parse("http://api.wolframalpha.com/v2/query?input=#{CGI.escape(msg)}&appid=#{app_id}&format=plaintext&includepodid=Result")
|
14
|
+
|
15
|
+
begin
|
16
|
+
Net::HTTP.start(url.host, url.port) do |http|
|
17
|
+
resp = http.get(url.request_uri).body
|
18
|
+
|
19
|
+
if resp =~ /queryresult success='false'/
|
20
|
+
reply "Wolfram Alpha errored out"
|
21
|
+
elsif resp =~ /<plaintext>(.+?)<\/plaintext>/m
|
22
|
+
answer = $1.strip
|
23
|
+
answer = answer[0, 200]
|
24
|
+
reply "#{msg} -> #{answer}"
|
25
|
+
else
|
26
|
+
reply "Wolfram Alpha doesn't seem to know"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
rescue Timeout
|
30
|
+
reply "timeout"
|
31
|
+
rescue Exception => e
|
32
|
+
reply e.to_s
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
define_plugin("god finger") do |msg|
|
2
|
+
next unless msg =~ /ore no kono te ga makka ni moeru/i
|
3
|
+
|
4
|
+
reply "Shouri o tsukameto todoroki sakebu!", false
|
5
|
+
sleep 1
|
6
|
+
reply "BAKUNETSU", false
|
7
|
+
sleep 1
|
8
|
+
reply "GOOOOOOOOOOOOOOOD FIIIIIIINGAAAAAAAAAAAAAA!!!!!!", false
|
9
|
+
end
|
data/plugins/hanase.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
define_plugin("hanase") do |msg|
|
2
|
+
@hanase ||= []
|
3
|
+
@hanase << msg
|
4
|
+
|
5
|
+
if @hanase.size > 3
|
6
|
+
@hanase.shift
|
7
|
+
end
|
8
|
+
|
9
|
+
if @hanase == %w(HA NA SE)
|
10
|
+
reply "nani kanchigai shiterunda."
|
11
|
+
sleep 2
|
12
|
+
reply "MADA ORE NO BATTLE PHASE WA SHUURYOU SHITENAIZE", false
|
13
|
+
end
|
14
|
+
end
|
data/plugins/help.rb
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
define_plugin("!help") do
|
2
|
+
a = "\00311"
|
3
|
+
b = "\00307"
|
4
|
+
c = "\00316"
|
5
|
+
reply "#{a}!ann !an2 #{b}Anime News Network Search #{c}| #{a}!g #{b}Google Search #{c}| #{a}!dan #{b}Danbooru Search #{c}| #{a}!tt !ttt #{b}Tokyo Toshokan Search #{c}| #{a}!choose #{b}Random Selection #{c}| #{a}!shuffle #{b}Random Order #{c}| #{a}!jtime #{b}Japanese Time #{c}| #{a}!gc #{b}Google Calculator #{c}| #{a}!ranking #{b}Rankings"
|
6
|
+
reply "#{a}!rs #{b}RapidSearch #{c}| #{a}!ts #{b}Twitter Search #{c}| #{a}!weather #{b}Weather #{c}| #{a}!eta #{b}Anime air dates #{c}| #{a}!dwiki #{b}Danbooru Wiki Search#{c}| #{a}!pixiv #{b}Pixiv English Search #{c}| #{a}!dg #{b}Danbooru Google Search#{c}"
|
7
|
+
end
|
data/plugins/jtime.rb
ADDED
data/plugins/note.rb
ADDED