wtth 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2009 Matthew Donoughe
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,18 @@
1
+ # Welcome to the Horde
2
+
3
+ This is a program that watches [HVZ Source](http://humansvszombies.org/) and posts messages to [Twitter](http://twitter.com/) when people are zombified. See [@wtthumd](http://twitter.com/wtthumd) for an example(game starts 2009-09-27 at about 22:00).
4
+
5
+ Please only run one WTTH or similar per game. Check to see if your game already has one before starting your own. Nothing is gained by running duplicates, and it wastes the resources of Twitter and HVZ Source.
6
+
7
+ ## Installation
8
+ WTTH is written in [Ruby](http://www.ruby-lang.org/) and requires the [nokogiri](http://nokogiri.rubyforge.org/) and [twitter](http://twitter.rubyforge.org/) [gems](http://docs.rubygems.org/).
9
+
10
+ WTTH now has a gem in the [GitHub gem source](http://gems.github.com/) and can be installed as `mdonoughe-wtth`. This should install all the dependencies and put `wtth` into your path like magic.
11
+
12
+ After you've gotten everything installed, run `wtth init` to give the program access to a Twitter account. I'd suggest not using your usual Twitter account for this.
13
+
14
+ Running `wtth init` will create a file called `.wtth.yml` in your home directory. You'll want to open that and change `player_list_uri` to point at the correct HVZ Source page for your game.
15
+
16
+ You'll probably want to make some sort of cron job to run `wtth`. It makes at most one request to HVZ Source and posts at most one message to Twitter per run. Set this to a responsible interval. You can probably get away with as low as once a minute, but that's completely unnecessary in my opinion.
17
+
18
+ Please remember not to have the cron job running when the game is not in session.
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'net/http'
5
+ require 'nokogiri'
6
+ require 'twitter'
7
+ require 'yaml'
8
+
9
+ wtth_path = File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'wtth')
10
+ require File.join(wtth_path, 'config')
11
+ require File.join(wtth_path, 'hvzsource')
12
+ require File.join(wtth_path, 'twitter')
13
+
14
+ module WTTH
15
+ VERSION = '1.2.1'
16
+ load_config
17
+
18
+ if ARGV.length > 0 and ARGV[0] == 'init'
19
+ twitter_init
20
+ exit 0
21
+ end
22
+
23
+ unless twitter_is_authorized?
24
+ puts 'You have not yet authorized WTTH to access Twitter.'
25
+ puts 'Please run `wtth init` first'
26
+ exit 1
27
+ end
28
+
29
+ # get new zombies and zombies that weren't reported last time
30
+ to_welcome = CONFIG[:backlog]
31
+ if to_welcome == nil
32
+ to_welcome = get_new_zombies
33
+ elsif to_welcome.join(', ').length < 140
34
+ to_welcome = get_new_zombies + to_welcome
35
+ end
36
+
37
+ if to_welcome != []
38
+ this_batch = []
39
+ recovery = []
40
+ size = 0
41
+
42
+ # get the least recent kills, no more than 140 characters worth
43
+ until size > 140 or to_welcome.empty?
44
+ zombie = to_welcome.last
45
+ size += zombie.length
46
+ size += 2 if this_batch.length > 0
47
+ if size <= 140
48
+ this_batch << zombie
49
+ recovery << to_welcome.pop
50
+ end
51
+ end
52
+
53
+ # remember who we haven't reported
54
+ CONFIG[:backlog] = to_welcome
55
+
56
+ # welcome with the most recent first so things are in order on twitter
57
+ this_batch.reverse!
58
+
59
+ begin
60
+ tweet(this_batch.join(', '))
61
+ rescue Twitter::TwitterError
62
+ puts "TwitterError #{$!}"
63
+ # throw the message onto the backlog so we can try again next time
64
+ CONFIG[:backlog] = to_welcome + recovery.reverse
65
+ end
66
+ end
67
+
68
+ save_config
69
+ end
@@ -0,0 +1,20 @@
1
+ module WTTH
2
+ private
3
+ CONFIG_PATH = File::expand_path('~/.wtth.yml')
4
+ # set the defaults
5
+ CONFIG = {:player_list_uri => 'http://20cent.hvzsource.com/players.php'}
6
+
7
+ def self.load_config
8
+ if File.exists?(CONFIG_PATH)
9
+ File.open(CONFIG_PATH) do |file|
10
+ CONFIG.merge!(YAML::load(file.read))
11
+ end
12
+ end
13
+ end
14
+
15
+ def self.save_config
16
+ File.open(CONFIG_PATH, 'w') do |file|
17
+ file.write(YAML::dump(CONFIG))
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,31 @@
1
+ module WTTH
2
+ private
3
+ def self.get_new_zombies
4
+ to_welcome = []
5
+ zombies = []
6
+
7
+ puts "fetching from hvzsource"
8
+
9
+ uri = URI.parse(CONFIG[:player_list_uri])
10
+ preq = Net::HTTP::Post.new(uri.path)
11
+ preq['user-agent'] = "welcome to the horde #{VERSION}"
12
+ preq.set_form_data({'faction' => 'h', 'sort_by' => 'kd', 'order' => 'd', 'show_killed' => '1', 'submit' => 'Refresh'}, '&')
13
+
14
+ req = Net::HTTP.new(uri.host, uri.port)
15
+ req.start do |http|
16
+ http.request(preq) do |resp|
17
+ doc = Nokogiri::HTML(resp.read_body)
18
+ # hvzsource produces some malformed html, so we can't use rows
19
+ # the table is <name> | horde | <tod>
20
+ cells = doc.xpath('//form/table//td')
21
+ ((cells.length - 3) / 3).times do |i|
22
+ name = cells[i * 3 + 3].content
23
+ zombies << name
24
+ to_welcome << name unless CONFIG[:zombies] != nil and CONFIG[:zombies].include?(name)
25
+ end
26
+ end
27
+ end
28
+ CONFIG[:zombies] = zombies
29
+ return to_welcome
30
+ end
31
+ end
@@ -0,0 +1,28 @@
1
+ module WTTH
2
+ private
3
+ APP_TOKEN = 'HgPXVDITRITul4peTLkyg'
4
+ APP_SECRET = 'iLoBnhZF3YDki5k4l09hptgg9SaRJkOYEyzsk1n0'
5
+
6
+ def self.tweet( message )
7
+ oauth = Twitter::OAuth.new(APP_TOKEN, APP_SECRET)
8
+ oauth.authorize_from_access(CONFIG[:access_token], CONFIG[:access_secret])
9
+ twitter = Twitter::Base.new(oauth)
10
+ p message
11
+ return
12
+ twitter.update(message)
13
+ end
14
+
15
+ def self.twitter_is_authorized?
16
+ return (CONFIG[:access_token] != nil and CONFIG[:access_secret] != nil)
17
+ end
18
+
19
+ def self.twitter_init
20
+ oauth = Twitter::OAuth.new(APP_TOKEN, APP_SECRET)
21
+ puts "Please go to #{oauth.request_token.authorize_url} and enter the PIN number here:"
22
+ oauth.authorize_from_request(oauth.request_token.token, oauth.request_token.secret, STDIN.gets.to_i)
23
+ CONFIG[:access_token] = oauth.access_token.token
24
+ CONFIG[:access_secret] = oauth.access_token.secret
25
+
26
+ save_config
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wtth
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Matthew Donoughe
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-27 00:00:00 +00:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: nokogiri
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.0.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: twitter
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.5.0
34
+ version:
35
+ description: Welcome to the Horde is a program that tweets when people join the zombie horde(in humans vs. zombies).
36
+ email: mdonoughe@gmail.com
37
+ executables:
38
+ - wtth
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.markdown
44
+ files:
45
+ - README.markdown
46
+ - bin/wtth
47
+ - lib/wtth/config.rb
48
+ - lib/wtth/hvzsource.rb
49
+ - lib/wtth/twitter.rb
50
+ - LICENSE
51
+ has_rdoc: true
52
+ homepage: http://github.com/mdonoughe/wtth
53
+ licenses: []
54
+
55
+ post_install_message:
56
+ rdoc_options:
57
+ - --main
58
+ - README.markdown
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ version:
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ version:
73
+ requirements: []
74
+
75
+ rubyforge_project:
76
+ rubygems_version: 1.3.5
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: Welcome to the Horde is a program that tweets when people join the zombie horde(in humans vs. zombies).
80
+ test_files: []
81
+