sc2cinch 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +129 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +101 -0
- data/Rakefile +37 -0
- data/VERSION +1 -0
- data/bin/sc2cinch +71 -0
- data/lib/cinch/plugins/starcraft/feeds.rb +40 -0
- data/lib/cinch/plugins/starcraft/ranks.rb +126 -0
- data/lib/cinch/plugins/starcraft/user.rb +50 -0
- data/lib/cinch/plugins/starcraft.rb +9 -0
- data/lib/sc2cinch.rb +33 -0
- metadata +241 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem "cinch", "~> 1.1.2"
|
4
|
+
gem "sc2ranks", "~> 0.1.0", :git => "git://github.com/logankoester/sc2ranks.git"
|
5
|
+
gem "nokogiri", "~> 1.4.4"
|
6
|
+
gem "rails", "~> 3.0.3", :require => false # Just uses a couple utils from action_view
|
7
|
+
gem "mongo_mapper", "~> 0.8.6"
|
8
|
+
gem "feedzirra", "~> 0.0.24", :git => "git://github.com/bananastalktome/feedzirra.git"
|
9
|
+
gem "bson_ext", "~> 1.2.4"
|
10
|
+
gem "daemons", "~> 1.1.0"
|
11
|
+
gem "optiflag", "~> 0.7"
|
12
|
+
|
13
|
+
group :development do
|
14
|
+
gem "bundler", "~> 1.0.0"
|
15
|
+
gem "jeweler", "~> 1.5.2"
|
16
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git://github.com/bananastalktome/feedzirra.git
|
3
|
+
revision: e478c1011bd5dc1f57bfa5396398162df48a2dcb
|
4
|
+
specs:
|
5
|
+
feedzirra (0.0.24)
|
6
|
+
activesupport (>= 2.3.8)
|
7
|
+
builder (>= 2.1.2)
|
8
|
+
curb (>= 0.2.3)
|
9
|
+
loofah (>= 0.3.1)
|
10
|
+
nokogiri (> 0.0.0)
|
11
|
+
sax-machine (>= 0.0.12)
|
12
|
+
|
13
|
+
GIT
|
14
|
+
remote: git://github.com/logankoester/sc2ranks.git
|
15
|
+
revision: a1554c218f9ddbff80b5b0b5dbc45cc424ebe853
|
16
|
+
specs:
|
17
|
+
sc2ranks (0.1.0)
|
18
|
+
httparty (>= 0.6.1)
|
19
|
+
|
20
|
+
GEM
|
21
|
+
remote: http://rubygems.org/
|
22
|
+
specs:
|
23
|
+
abstract (1.0.0)
|
24
|
+
actionmailer (3.0.5)
|
25
|
+
actionpack (= 3.0.5)
|
26
|
+
mail (~> 2.2.15)
|
27
|
+
actionpack (3.0.5)
|
28
|
+
activemodel (= 3.0.5)
|
29
|
+
activesupport (= 3.0.5)
|
30
|
+
builder (~> 2.1.2)
|
31
|
+
erubis (~> 2.6.6)
|
32
|
+
i18n (~> 0.4)
|
33
|
+
rack (~> 1.2.1)
|
34
|
+
rack-mount (~> 0.6.13)
|
35
|
+
rack-test (~> 0.5.7)
|
36
|
+
tzinfo (~> 0.3.23)
|
37
|
+
activemodel (3.0.5)
|
38
|
+
activesupport (= 3.0.5)
|
39
|
+
builder (~> 2.1.2)
|
40
|
+
i18n (~> 0.4)
|
41
|
+
activerecord (3.0.5)
|
42
|
+
activemodel (= 3.0.5)
|
43
|
+
activesupport (= 3.0.5)
|
44
|
+
arel (~> 2.0.2)
|
45
|
+
tzinfo (~> 0.3.23)
|
46
|
+
activeresource (3.0.5)
|
47
|
+
activemodel (= 3.0.5)
|
48
|
+
activesupport (= 3.0.5)
|
49
|
+
activesupport (3.0.5)
|
50
|
+
arel (2.0.9)
|
51
|
+
bson (1.2.4)
|
52
|
+
bson_ext (1.2.4)
|
53
|
+
builder (2.1.2)
|
54
|
+
cinch (1.1.2)
|
55
|
+
crack (0.1.8)
|
56
|
+
curb (0.7.12)
|
57
|
+
daemons (1.1.0)
|
58
|
+
erubis (2.6.6)
|
59
|
+
abstract (>= 1.0.0)
|
60
|
+
git (1.2.5)
|
61
|
+
httparty (0.7.4)
|
62
|
+
crack (= 0.1.8)
|
63
|
+
i18n (0.5.0)
|
64
|
+
jeweler (1.5.2)
|
65
|
+
bundler (~> 1.0.0)
|
66
|
+
git (>= 1.2.5)
|
67
|
+
rake
|
68
|
+
jnunemaker-validatable (1.8.4)
|
69
|
+
activesupport (>= 2.3.4)
|
70
|
+
loofah (1.0.0)
|
71
|
+
nokogiri (>= 1.3.3)
|
72
|
+
mail (2.2.15)
|
73
|
+
activesupport (>= 2.3.6)
|
74
|
+
i18n (>= 0.4.0)
|
75
|
+
mime-types (~> 1.16)
|
76
|
+
treetop (~> 1.4.8)
|
77
|
+
mime-types (1.16)
|
78
|
+
mongo (1.2.4)
|
79
|
+
bson (>= 1.2.4)
|
80
|
+
mongo_mapper (0.8.6)
|
81
|
+
activesupport (>= 2.3.4)
|
82
|
+
jnunemaker-validatable (~> 1.8.4)
|
83
|
+
plucky (~> 0.3.6)
|
84
|
+
nokogiri (1.4.4)
|
85
|
+
optiflag (0.7)
|
86
|
+
plucky (0.3.7)
|
87
|
+
mongo (~> 1.1)
|
88
|
+
polyglot (0.3.1)
|
89
|
+
rack (1.2.2)
|
90
|
+
rack-mount (0.6.13)
|
91
|
+
rack (>= 1.0.0)
|
92
|
+
rack-test (0.5.7)
|
93
|
+
rack (>= 1.0)
|
94
|
+
rails (3.0.5)
|
95
|
+
actionmailer (= 3.0.5)
|
96
|
+
actionpack (= 3.0.5)
|
97
|
+
activerecord (= 3.0.5)
|
98
|
+
activeresource (= 3.0.5)
|
99
|
+
activesupport (= 3.0.5)
|
100
|
+
bundler (~> 1.0)
|
101
|
+
railties (= 3.0.5)
|
102
|
+
railties (3.0.5)
|
103
|
+
actionpack (= 3.0.5)
|
104
|
+
activesupport (= 3.0.5)
|
105
|
+
rake (>= 0.8.7)
|
106
|
+
thor (~> 0.14.4)
|
107
|
+
rake (0.8.7)
|
108
|
+
sax-machine (0.0.16)
|
109
|
+
nokogiri (> 0.0.0)
|
110
|
+
thor (0.14.6)
|
111
|
+
treetop (1.4.9)
|
112
|
+
polyglot (>= 0.3.1)
|
113
|
+
tzinfo (0.3.24)
|
114
|
+
|
115
|
+
PLATFORMS
|
116
|
+
ruby
|
117
|
+
|
118
|
+
DEPENDENCIES
|
119
|
+
bson_ext (~> 1.2.4)
|
120
|
+
bundler (~> 1.0.0)
|
121
|
+
cinch (~> 1.1.2)
|
122
|
+
daemons (~> 1.1.0)
|
123
|
+
feedzirra (~> 0.0.24)!
|
124
|
+
jeweler (~> 1.5.2)
|
125
|
+
mongo_mapper (~> 0.8.6)
|
126
|
+
nokogiri (~> 1.4.4)
|
127
|
+
optiflag (~> 0.7)
|
128
|
+
rails (~> 3.0.3)
|
129
|
+
sc2ranks (~> 0.1.0)!
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Logan Koester
|
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,101 @@
|
|
1
|
+
= sc2cinch
|
2
|
+
|
3
|
+
sc2cinch is an IRC bot for Starcraft II players.
|
4
|
+
|
5
|
+
Features:
|
6
|
+
* Display the current rank for a Starcraft II player
|
7
|
+
* Queue a refresh on your SC2Ranks profile
|
8
|
+
* Report the games you've played in-channel (using RSS)
|
9
|
+
|
10
|
+
It is distributed as a Ruby gem and based on Cinch and MongoDB.
|
11
|
+
|
12
|
+
== Installation & Setup
|
13
|
+
|
14
|
+
1. Install Ruby 1.9 and rubygems if you don't already have it.
|
15
|
+
|
16
|
+
2. Install sc2cinch
|
17
|
+
|
18
|
+
$ gem install sc2cinch
|
19
|
+
Successfully installed sc2cinch-0.1.0
|
20
|
+
1 gem installed
|
21
|
+
|
22
|
+
3. Set up a MongoDB database to store users information in. I recommend creating a free account at https://mongohq.com
|
23
|
+
|
24
|
+
4. Create a configuration file
|
25
|
+
|
26
|
+
$ sc2cinch --setup ~/.sc2cinch
|
27
|
+
sc2cinch v0.1.0 - IRC bot for Starcraft II players
|
28
|
+
|
29
|
+
IRC Configuration
|
30
|
+
-----------------
|
31
|
+
IRC Nick: SC2Cinch
|
32
|
+
IRC Server: irc.myserver.net
|
33
|
+
For password protected channels, type "#channel PASSWORD"
|
34
|
+
Channel: #mychannel
|
35
|
+
Database Configuration
|
36
|
+
----------------------
|
37
|
+
You can get free MongoDB hosting from http://mongohq.com
|
38
|
+
MongoDB Host: dbhost
|
39
|
+
MongoDB Port: 6000
|
40
|
+
MongoDB Database: sc2cinch
|
41
|
+
MongoDB Username: sc2cinch
|
42
|
+
MongoDB Password: sc2cinch
|
43
|
+
|
44
|
+
File written.
|
45
|
+
Use sc2cinch -f ~/.sc2cinch to launch your bot.
|
46
|
+
|
47
|
+
5. Launch your new IRC bot!
|
48
|
+
|
49
|
+
$ sc2cinch -f ~/.sc2cinch
|
50
|
+
|
51
|
+
Use --daemonize if you want to run it in the background.
|
52
|
+
|
53
|
+
== Usage
|
54
|
+
|
55
|
+
When your IRC bot has joined a channel, you can start mapping its occupants to
|
56
|
+
their Starcraft II accounts. Visit http://sc2ranks.com to find your profile URL.
|
57
|
+
|
58
|
+
[20:39] < logankoester> !sc2set http://sc2ranks.com/us/1485031/logankoester
|
59
|
+
[20:39] < SC2Cinch> logankoester's battle.net user set to logankoester, Battle.net ID 1485031
|
60
|
+
|
61
|
+
Every user you map will have their wins and losses reported in the channel (after a delay,
|
62
|
+
as it is only RSS).
|
63
|
+
|
64
|
+
You can also find your current rank information.
|
65
|
+
|
66
|
+
[20:43] < SC2Cinch> logankoester is rank #1 in Division Routhe Whiskey (silver) with 300 wins and 271
|
67
|
+
losses (0.53 win ratio) (last updated about 7 hours ago)
|
68
|
+
|
69
|
+
Explore the other options and features available with !sc2help
|
70
|
+
|
71
|
+
[20:44] < logankoester> !sc2help
|
72
|
+
[20:44] < SC2Cinch> Display current rank for a Starcraft II player
|
73
|
+
[20:44] < SC2Cinch> !sc2rank - Display your current rank
|
74
|
+
[20:44] < SC2Cinch> !sc2rank <nick> - Display <nick>'s current rank
|
75
|
+
[20:44] < SC2Cinch> !sc2set <url> - Set your profile URL
|
76
|
+
[20:44] < SC2Cinch> !sc2set <nick> <url> - Set <nick>'s profile URL
|
77
|
+
[20:44] < SC2Cinch> !sc2refresh - Queue a refresh for yourself
|
78
|
+
[20:44] < SC2Cinch> !sc2refresh <nick> - Queue a refresh for your <nick>
|
79
|
+
[20:44] < SC2Cinch> To get your SC2ranks URL, visit http://sc2ranks.com
|
80
|
+
[20:44] < SC2Cinch> Author: Logan Koester <logan@logankoester.com>
|
81
|
+
|
82
|
+
|
83
|
+
== Getting Help
|
84
|
+
|
85
|
+
When all else fails, read the code!
|
86
|
+
|
87
|
+
== Contributing to sc2cinch
|
88
|
+
|
89
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
90
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
91
|
+
* Fork the project
|
92
|
+
* Start a feature/bugfix branch
|
93
|
+
* Commit and push until you are happy with your contribution
|
94
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
95
|
+
* 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.
|
96
|
+
|
97
|
+
== Copyright
|
98
|
+
|
99
|
+
Copyright (c) 2011 Logan Koester. See LICENSE.txt for
|
100
|
+
further details.
|
101
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "sc2cinch"
|
16
|
+
gem.homepage = "http://github.com/logankoester/sc2cinch"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{Ruby-based IRC bot for Starcraft II players}
|
19
|
+
gem.description = %Q{Display your current ladder rank, report the outcome of games, and more}
|
20
|
+
gem.email = "logan@logankoester.com"
|
21
|
+
gem.authors = ["Logan Koester"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rake/rdoctask'
|
30
|
+
Rake::RDocTask.new do |rdoc|
|
31
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
32
|
+
|
33
|
+
rdoc.rdoc_dir = 'rdoc'
|
34
|
+
rdoc.title = "sc2cinch #{version}"
|
35
|
+
rdoc.rdoc_files.include('README*')
|
36
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
37
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/sc2cinch
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'daemons'
|
5
|
+
require 'optiflag'
|
6
|
+
require 'yaml'
|
7
|
+
|
8
|
+
APP_VERSION = File.read("#{File.dirname(__FILE__)}/../VERSION")
|
9
|
+
|
10
|
+
def ask(q)
|
11
|
+
print q
|
12
|
+
a = STDIN.gets.chomp
|
13
|
+
return a
|
14
|
+
end
|
15
|
+
|
16
|
+
module App extend OptiFlagSet
|
17
|
+
optional_flag "file" do
|
18
|
+
alternate_forms "f"
|
19
|
+
description "Path to a configuration file"
|
20
|
+
end
|
21
|
+
|
22
|
+
optional_flag "setup" do
|
23
|
+
description "Generate a configuration file"
|
24
|
+
end
|
25
|
+
|
26
|
+
optional_switch_flag "daemonize" do
|
27
|
+
alternate_forms "d"
|
28
|
+
description "Run this process in the background"
|
29
|
+
end
|
30
|
+
|
31
|
+
and_process!
|
32
|
+
end
|
33
|
+
|
34
|
+
puts "sc2cinch v#{APP_VERSION} - IRC bot for Starcraft II players"
|
35
|
+
|
36
|
+
flag = App.flags
|
37
|
+
|
38
|
+
if flag.file
|
39
|
+
Daemons.daemonize if flag.daemonize?
|
40
|
+
puts "Using configuration at #{flag.file}"
|
41
|
+
$config = YAML.load_file(flag.file)
|
42
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../lib/sc2cinch.rb")
|
43
|
+
elsif flag.setup
|
44
|
+
$config = {'rss' => {}, 'mongodb' => {}}
|
45
|
+
$config['rss']['interval'] = 20 * 60
|
46
|
+
$config['rss']['floodlines'] = 5
|
47
|
+
|
48
|
+
puts
|
49
|
+
puts "IRC Configuration"
|
50
|
+
puts "-----------------"
|
51
|
+
$config['nick'] = ask "IRC Nick: "
|
52
|
+
$config['server'] = ask "IRC Server: "
|
53
|
+
puts "For password protected channels, type \"#channel PASSWORD\""
|
54
|
+
$config['channels'] = [ask("Channel: ")]
|
55
|
+
|
56
|
+
puts "Database Configuration"
|
57
|
+
puts "----------------------"
|
58
|
+
puts "You can get free MongoDB hosting from http://mongohq.com"
|
59
|
+
$config['mongodb']['host'] = ask "MongoDB Host: "
|
60
|
+
$config['mongodb']['port'] = ask "MongoDB Port: "
|
61
|
+
$config['mongodb']['database'] = ask "MongoDB Database: "
|
62
|
+
$config['mongodb']['username'] = ask "MongoDB Username: "
|
63
|
+
$config['mongodb']['password'] = ask "MongoDB Password: "
|
64
|
+
|
65
|
+
File.open(flag.setup, 'w+') { |f| f << $config.to_yaml }
|
66
|
+
puts
|
67
|
+
puts "File written."
|
68
|
+
puts "Use sc2cinch -f #{flag.setup} to launch your bot."
|
69
|
+
else
|
70
|
+
puts "Use sc2cinch --help for usage"
|
71
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Cinch
|
2
|
+
module Plugins
|
3
|
+
module Starcraft
|
4
|
+
class FeedsReader
|
5
|
+
def initialize(bot, channels)
|
6
|
+
@bot, @channels = bot, channels
|
7
|
+
@feeds = Feedzirra::Feed.fetch_and_parse( User.all.map { |u| u.feed } )
|
8
|
+
end
|
9
|
+
|
10
|
+
def start
|
11
|
+
loop do
|
12
|
+
sleep $config['rss']['interval']
|
13
|
+
@feeds = Feedzirra::Feed.update(@feeds.values)
|
14
|
+
@feeds.each do |feed|
|
15
|
+
feed = feed[1]
|
16
|
+
nick = User.find_by_username( feed.title.split(" ").last ).nick
|
17
|
+
entries = feed.new_entries[0..($config['rss']['floodlines']-1)]
|
18
|
+
entries.each do |entry|
|
19
|
+
msg = "#{nick} just played #{entry.title}"
|
20
|
+
@bot.dispatch(:rss_update, nil, {:channels => @channels, :message => msg })
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class Feeds
|
28
|
+
include Cinch::Plugin
|
29
|
+
|
30
|
+
listen_to :rss_update
|
31
|
+
|
32
|
+
def listen(m, event)
|
33
|
+
event[:channels].each do |channel|
|
34
|
+
Channel(channel).send event[:message]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
module Cinch
|
2
|
+
module Plugins
|
3
|
+
module Starcraft
|
4
|
+
class Ranks
|
5
|
+
include Cinch::Plugin
|
6
|
+
|
7
|
+
match /set (.+)/, :method => :set
|
8
|
+
match /help/, :method => :help
|
9
|
+
match /refresh (.+)/, :method => :refresh_nick
|
10
|
+
match /refresh$/, :method => :refresh
|
11
|
+
match /rank (.+)/, :method => :rank_nick
|
12
|
+
match /rank$/, :method => :rank
|
13
|
+
|
14
|
+
listen_to :channel
|
15
|
+
prefix /^!sc2/
|
16
|
+
|
17
|
+
def initialize(*args)
|
18
|
+
super
|
19
|
+
start_rss_thread
|
20
|
+
end
|
21
|
+
|
22
|
+
# Usage:
|
23
|
+
# To set your own Starcraft II user
|
24
|
+
# !sc2set http://sc2ranks.com/#{region}/#{bnetid}/#{username}
|
25
|
+
# To set another Starcraft II user
|
26
|
+
# !sc2set <nick> http://sc2ranks.com/#{region}/#{bnetid}/#{username}
|
27
|
+
def set(m, args)
|
28
|
+
args = args.split(" ")
|
29
|
+
|
30
|
+
# Optional nickname parameter
|
31
|
+
if args.size > 1
|
32
|
+
nick = args[0].downcase
|
33
|
+
url = args[1]
|
34
|
+
else
|
35
|
+
nick = m.user.nick.downcase
|
36
|
+
url = args[0]
|
37
|
+
end
|
38
|
+
|
39
|
+
user = User.find_by_nick(nick)
|
40
|
+
user = User.create(:nick => nick) unless user
|
41
|
+
user.update_from_url(url)
|
42
|
+
user.save
|
43
|
+
restart_rss_thread
|
44
|
+
m.reply "#{user.nick}'s battle.net user set to #{user.username}, Battle.net ID #{user.bnetid}"
|
45
|
+
end
|
46
|
+
|
47
|
+
def help(m)
|
48
|
+
m.reply "Display current rank for a Starcraft II player"
|
49
|
+
m.reply "!sc2rank - Display your current rank"
|
50
|
+
m.reply "!sc2rank <nick> - Display <nick>'s current rank"
|
51
|
+
m.reply "!sc2set <url> - Set your profile URL"
|
52
|
+
m.reply "!sc2set <nick> <url> - Set <nick>'s profile URL"
|
53
|
+
m.reply "!sc2refresh - Queue a refresh for yourself"
|
54
|
+
m.reply "!sc2refresh <nick> - Queue a refresh for your <nick>"
|
55
|
+
m.reply "To get your SC2ranks URL, visit http://sc2ranks.com"
|
56
|
+
m.reply "Author: Logan Koester <logan@logankoester.com>"
|
57
|
+
end
|
58
|
+
|
59
|
+
# Queue refresh for yourself
|
60
|
+
def refresh(m)
|
61
|
+
user = User.find_by_nick(m.user.nick.downcase)
|
62
|
+
if user
|
63
|
+
m.reply "#{user.nick}: #{user.queue_refresh!}"
|
64
|
+
else
|
65
|
+
m.reply "That nick is not registered, use !sc2set (!sc2help for more info)"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# Queue refresh for <nick>
|
70
|
+
def refresh_nick(m, nick)
|
71
|
+
user = User.find_by_nick(nick.downcase)
|
72
|
+
if user
|
73
|
+
m.reply "#{user.nick}: #{user.queue_refresh!}"
|
74
|
+
else
|
75
|
+
m.reply "That nick is not registered, use !sc2set (!sc2help for more info)"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# Display current rank for yourself
|
80
|
+
def rank(m)
|
81
|
+
user = User.find_by_nick(m.user.nick.downcase)
|
82
|
+
if user
|
83
|
+
display_rank(m, user)
|
84
|
+
else
|
85
|
+
m.reply "Your nick is not registered, use !sc2set (!sc2help for more info)"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# Display <nick>'s current rank
|
90
|
+
def rank_nick(m, nick)
|
91
|
+
user = User.find_by_nick(nick.downcase)
|
92
|
+
if user
|
93
|
+
display_rank(m, user)
|
94
|
+
else
|
95
|
+
m.reply "That nick is not registered, use !sc2set (!sc2help for more info)"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
private
|
100
|
+
def display_rank(m, user)
|
101
|
+
begin
|
102
|
+
character = user.get_character
|
103
|
+
team = character.teams.select { |v| v['bracket'] == 1 }.first
|
104
|
+
m.reply "#{character.name} is rank ##{team['division_rank']} in #{team['division']} (#{team['league']}) with #{team['wins']} wins and #{team['losses']} losses (#{team['ratio']} win ratio) (last updated #{time_ago_in_words(team['updated_at'])} ago)"
|
105
|
+
rescue Exception => e
|
106
|
+
m.reply "Sorry, an error occurred: #{e}"
|
107
|
+
m.reply "Try setting your username with !sc2set (!sc2help for more info)"
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def start_rss_thread
|
112
|
+
@rss_thread = Thread.new { FeedsReader.new($bot, $config['channels']).start }
|
113
|
+
end
|
114
|
+
|
115
|
+
def stop_rss_thread
|
116
|
+
@rss_thread.kill if @rss_thread
|
117
|
+
end
|
118
|
+
|
119
|
+
def restart_rss_thread
|
120
|
+
stop_rss_thread
|
121
|
+
start_rss_thread
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Cinch
|
2
|
+
module Plugins
|
3
|
+
module Starcraft
|
4
|
+
|
5
|
+
class User
|
6
|
+
include MongoMapper::Document
|
7
|
+
key :nick, String
|
8
|
+
key :username, String
|
9
|
+
key :region, String
|
10
|
+
key :bnetid, String
|
11
|
+
key :url, String
|
12
|
+
key :feed, String
|
13
|
+
|
14
|
+
def get_character
|
15
|
+
begin
|
16
|
+
sc2ranks = SC2Ranks::API.new('logankoester.com')
|
17
|
+
sc2ranks.get_team_info(self.username, self.bnetid)
|
18
|
+
rescue SC2Ranks::API::NoCharacterError => e
|
19
|
+
m.reply "Character not found: #{e}"
|
20
|
+
rescue Exception => e
|
21
|
+
m.reply "Failed to fetch SC2Ranks data: #{e}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def update_from_url(url)
|
26
|
+
split = url.split(/.*sc2ranks.com\/(.+)\/(.+)\/(.+)/)
|
27
|
+
self.url = url
|
28
|
+
self.region = split[1]
|
29
|
+
self.bnetid = split[2]
|
30
|
+
self.username = split[3]
|
31
|
+
|
32
|
+
doc = Nokogiri::HTML(open(url))
|
33
|
+
self.feed = doc.xpath("//link/@href")[3].value
|
34
|
+
end
|
35
|
+
|
36
|
+
def queue_refresh!
|
37
|
+
url = "http://sc2ranks.com/char/refresh/#{self.region}/#{self.bnetid}/#{self.username}"
|
38
|
+
doc = Nokogiri::HTML(open(url))
|
39
|
+
resp = doc.css("html body div.charprofile div.w960 div.profile div.updated-container div.lastupdated div.refresh span.green").first.content
|
40
|
+
if ( resp.is_a?(String) and resp.size < 140 )
|
41
|
+
resp
|
42
|
+
else
|
43
|
+
"Unexpected response, try clicking #{url}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module Cinch
|
2
|
+
module Plugins
|
3
|
+
module Starcraft
|
4
|
+
autoload :Ranks, File.expand_path('../starcraft/ranks', __FILE__)
|
5
|
+
autoload :Feeds, File.expand_path('../starcraft/feeds', __FILE__)
|
6
|
+
autoload :User, File.expand_path('../starcraft/user', __FILE__)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
data/lib/sc2cinch.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
%w{rubygems cinch sc2ranks nokogiri open-uri
|
2
|
+
action_view mongo_mapper feedzirra}.each { |d| require d }
|
3
|
+
|
4
|
+
require "#{File.dirname(__FILE__)}/cinch/plugins/starcraft"
|
5
|
+
|
6
|
+
include ActionView::Helpers::DateHelper
|
7
|
+
|
8
|
+
begin
|
9
|
+
MongoMapper.connection = Mongo::Connection.new($config['mongodb']['host'], $config['mongodb']['port'])
|
10
|
+
MongoMapper.database = $config['mongodb']['database']
|
11
|
+
MongoMapper.database.authenticate($config['mongodb']['username'], $config['mongodb']['password'])
|
12
|
+
rescue Mongo::AuthenticationError => e
|
13
|
+
puts e
|
14
|
+
puts "Host: " + $config['mongodb']['host']
|
15
|
+
puts "Port: " + $config['mongodb']['port']
|
16
|
+
puts "Database: " + $config['mongodb']['database']
|
17
|
+
puts "Username: " + $config['mongodb']['username']
|
18
|
+
puts "Password: " + $config['mongodb']['password']
|
19
|
+
exit
|
20
|
+
rescue Exception => e
|
21
|
+
"Failed to connect to database: #{e}"
|
22
|
+
end
|
23
|
+
|
24
|
+
$bot = Cinch::Bot.new do
|
25
|
+
configure do |c|
|
26
|
+
c.server = $config['server']
|
27
|
+
c.nick = $config['nick']
|
28
|
+
c.channels = $config['channels']
|
29
|
+
c.plugins.plugins = [Cinch::Plugins::Starcraft::Ranks, Cinch::Plugins::Starcraft::Feeds]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
$bot.start
|
metadata
ADDED
@@ -0,0 +1,241 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sc2cinch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Logan Koester
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-03-14 00:00:00 -04:00
|
18
|
+
default_executable: sc2cinch
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: cinch
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 1
|
30
|
+
- 2
|
31
|
+
version: 1.1.2
|
32
|
+
type: :runtime
|
33
|
+
prerelease: false
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: sc2ranks
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 0
|
44
|
+
- 1
|
45
|
+
- 0
|
46
|
+
version: 0.1.0
|
47
|
+
type: :runtime
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: nokogiri
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 1
|
59
|
+
- 4
|
60
|
+
- 4
|
61
|
+
version: 1.4.4
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: *id003
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: rails
|
67
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ~>
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
segments:
|
73
|
+
- 3
|
74
|
+
- 0
|
75
|
+
- 3
|
76
|
+
version: 3.0.3
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *id004
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: mongo_mapper
|
82
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ~>
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
- 8
|
90
|
+
- 6
|
91
|
+
version: 0.8.6
|
92
|
+
type: :runtime
|
93
|
+
prerelease: false
|
94
|
+
version_requirements: *id005
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: feedzirra
|
97
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ~>
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
- 0
|
105
|
+
- 24
|
106
|
+
version: 0.0.24
|
107
|
+
type: :runtime
|
108
|
+
prerelease: false
|
109
|
+
version_requirements: *id006
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: bson_ext
|
112
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
segments:
|
118
|
+
- 1
|
119
|
+
- 2
|
120
|
+
- 4
|
121
|
+
version: 1.2.4
|
122
|
+
type: :runtime
|
123
|
+
prerelease: false
|
124
|
+
version_requirements: *id007
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: daemons
|
127
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
129
|
+
requirements:
|
130
|
+
- - ~>
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
segments:
|
133
|
+
- 1
|
134
|
+
- 1
|
135
|
+
- 0
|
136
|
+
version: 1.1.0
|
137
|
+
type: :runtime
|
138
|
+
prerelease: false
|
139
|
+
version_requirements: *id008
|
140
|
+
- !ruby/object:Gem::Dependency
|
141
|
+
name: optiflag
|
142
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
143
|
+
none: false
|
144
|
+
requirements:
|
145
|
+
- - ~>
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
segments:
|
148
|
+
- 0
|
149
|
+
- 7
|
150
|
+
version: "0.7"
|
151
|
+
type: :runtime
|
152
|
+
prerelease: false
|
153
|
+
version_requirements: *id009
|
154
|
+
- !ruby/object:Gem::Dependency
|
155
|
+
name: bundler
|
156
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
157
|
+
none: false
|
158
|
+
requirements:
|
159
|
+
- - ~>
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
segments:
|
162
|
+
- 1
|
163
|
+
- 0
|
164
|
+
- 0
|
165
|
+
version: 1.0.0
|
166
|
+
type: :development
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: *id010
|
169
|
+
- !ruby/object:Gem::Dependency
|
170
|
+
name: jeweler
|
171
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
172
|
+
none: false
|
173
|
+
requirements:
|
174
|
+
- - ~>
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
segments:
|
177
|
+
- 1
|
178
|
+
- 5
|
179
|
+
- 2
|
180
|
+
version: 1.5.2
|
181
|
+
type: :development
|
182
|
+
prerelease: false
|
183
|
+
version_requirements: *id011
|
184
|
+
description: Display your current ladder rank, report the outcome of games, and more
|
185
|
+
email: logan@logankoester.com
|
186
|
+
executables:
|
187
|
+
- sc2cinch
|
188
|
+
extensions: []
|
189
|
+
|
190
|
+
extra_rdoc_files:
|
191
|
+
- LICENSE.txt
|
192
|
+
- README.rdoc
|
193
|
+
files:
|
194
|
+
- .document
|
195
|
+
- Gemfile
|
196
|
+
- Gemfile.lock
|
197
|
+
- LICENSE.txt
|
198
|
+
- README.rdoc
|
199
|
+
- Rakefile
|
200
|
+
- VERSION
|
201
|
+
- bin/sc2cinch
|
202
|
+
- lib/cinch/plugins/starcraft.rb
|
203
|
+
- lib/cinch/plugins/starcraft/feeds.rb
|
204
|
+
- lib/cinch/plugins/starcraft/ranks.rb
|
205
|
+
- lib/cinch/plugins/starcraft/user.rb
|
206
|
+
- lib/sc2cinch.rb
|
207
|
+
has_rdoc: true
|
208
|
+
homepage: http://github.com/logankoester/sc2cinch
|
209
|
+
licenses:
|
210
|
+
- MIT
|
211
|
+
post_install_message:
|
212
|
+
rdoc_options: []
|
213
|
+
|
214
|
+
require_paths:
|
215
|
+
- lib
|
216
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
217
|
+
none: false
|
218
|
+
requirements:
|
219
|
+
- - ">="
|
220
|
+
- !ruby/object:Gem::Version
|
221
|
+
hash: -590535288697464928
|
222
|
+
segments:
|
223
|
+
- 0
|
224
|
+
version: "0"
|
225
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
226
|
+
none: false
|
227
|
+
requirements:
|
228
|
+
- - ">="
|
229
|
+
- !ruby/object:Gem::Version
|
230
|
+
segments:
|
231
|
+
- 0
|
232
|
+
version: "0"
|
233
|
+
requirements: []
|
234
|
+
|
235
|
+
rubyforge_project:
|
236
|
+
rubygems_version: 1.3.7
|
237
|
+
signing_key:
|
238
|
+
specification_version: 3
|
239
|
+
summary: Ruby-based IRC bot for Starcraft II players
|
240
|
+
test_files: []
|
241
|
+
|