kastner-twitter-bot 0.1

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.
@@ -0,0 +1 @@
1
+ v0.1 Initial release
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Erik Kastner
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.
@@ -0,0 +1,8 @@
1
+ CHANGELOG
2
+ examples/my_bot.rb
3
+ lib/twitter_bot.rb
4
+ LICENSE
5
+ Manifest
6
+ README
7
+ README.markdown
8
+ site/index.html
data/README ADDED
@@ -0,0 +1,30 @@
1
+ Realtime Twitter Bot
2
+ ====================
3
+
4
+ A realtime bot for [twitter](http://twitter.com/)
5
+
6
+ Gem dependencies:
7
+ * [xmpp4r/simple](http://code.google.com/p/xmpp4r-simple/)
8
+ * [twitter](http://twitter.rubyforge.org/)
9
+ * [simple-daemon](http://simple-daemon.rubyforge.org/)
10
+
11
+
12
+ Using the bot
13
+ -------------
14
+
15
+ Place a file in your $HOME: **bot.yml** with the format:
16
+ `
17
+ twitter_user: "account"
18
+ twitter_pass: "password"
19
+ jabber_acct: "jabber user (user@gmail.com works fine)"
20
+ jabber_pass: "jabber/gmail password"
21
+ `
22
+
23
+ Registering the jabber account with twitter
24
+ -------------------------------------------
25
+
26
+ **DO NOT SKIP THIS**
27
+
28
+ * visit http://twitter.com/devices
29
+ * add your jabber account
30
+ * use a jabber client (iChat, adium, etc), sign in to the account and verify the code twitter gives you
@@ -0,0 +1,37 @@
1
+ Realtime Twitter Bot
2
+ ====================
3
+
4
+ A realtime bot for [twitter](http://twitter.com/)
5
+
6
+ Gem dependencies:
7
+ * [xmpp4r/simple](http://code.google.com/p/xmpp4r-simple/)
8
+ * [twitter](http://twitter.rubyforge.org/)
9
+ * [simple-daemon](http://simple-daemon.rubyforge.org/)
10
+
11
+
12
+ Using the bot
13
+ -------------
14
+
15
+ Place a file in your $HOME: **bot.yml** with the format:
16
+
17
+ twitter_user: "account"
18
+ twitter_pass: "password"
19
+ jabber_acct: "jabber user (user@gmail.com works fine)"
20
+ jabber_pass: "jabber/gmail password"
21
+
22
+
23
+ Registering the jabber account with twitter
24
+ -------------------------------------------
25
+
26
+ **DO NOT SKIP THIS**
27
+
28
+ * visit http://twitter.com/devices
29
+ * add your jabber account
30
+ * use a jabber client (iChat, adium, etc), sign in to the account and verify the code twitter gives you
31
+ * if you'd like to handle direct messages, ask [al3x](http://twitter.com/al3x) to turn on *autofollow*
32
+
33
+
34
+ Contributors
35
+ ------------
36
+
37
+ * Erik [Kastner](http://metaatem.net) <kastner@gmail.com>
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift("../")
4
+ require 'rubygems'
5
+ require 'simple-daemon'
6
+ require 'twitter_bot'
7
+ require 'YAML'
8
+
9
+ # require 'ruby-debug'
10
+
11
+ WORKING_DIR = "/tmp/bingo-bot/"
12
+ DEBUG = true
13
+
14
+ class MyBot < TwitterBot
15
+ def initialize(twitter_username, twitter_password, jabber_account, jabber_password)
16
+ super
17
+ @bot_name = twitter_username
18
+ end
19
+
20
+ def go
21
+ received_messages { |message| deal_with(message.body) }
22
+ end
23
+
24
+ def deal_with(message)
25
+ log(message) if DEBUG
26
+ case message
27
+ when /^(.*):\s*@#{@bot_name}:?\s*(.*)\s*$/i # @ reply
28
+ user, command = $1, $2
29
+ log("@reply from #{user} / #{command}") if DEBUG
30
+ handle_reply(user, command)
31
+ when /Direct from (.*):\n([^\n]+)\n/
32
+ user, command = $1, $2
33
+ log("#{user} / #{command}") if DEBUG
34
+ handle_dm(user, command)
35
+ end
36
+ end
37
+
38
+ def end
39
+ disconnect
40
+ end
41
+ end
42
+
43
+ class BotRunner < SimpleDaemon::Base
44
+ `mkdir -p #{WORKING_DIR}` # just make sure the working dir exists
45
+ SimpleDaemon::WORKING_DIRECTORY = WORKING_DIR
46
+
47
+ def self.start
48
+ TwitterBot.log("start up") if DEBUG
49
+ initialize_envrionment
50
+
51
+ @bot = MyBot.new(@bot_settings["twitter_user"], @bot_settings["twitter_pass"], @bot_settings["jabber_acct"], @bot_settings["jabber_pass"])
52
+ loop do
53
+ begin
54
+ @bot.go
55
+ rescue => e
56
+ TwitterBot.log(e.inspect) if DEBUG
57
+ end
58
+ sleep(2)
59
+ end
60
+ end
61
+
62
+ def self.stop
63
+ @bingo.end
64
+ end
65
+ end
66
+
67
+ def initialize_envrionment
68
+ raise "Missing file #{ENV["HOME"]}/bot.yml" unless File.exists?("#{ENV["HOME"]}/bot.yml")
69
+
70
+ @bot_settings = YAML::load_file("#{ENV["HOME"]}/bot.yml")
71
+ end
72
+
73
+ BotRunner.daemonize
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'xmpp4r-simple'
5
+ require 'twitter'
6
+ require 'syslog'
7
+
8
+ class TwitterBot < Jabber::Simple
9
+
10
+ TWITTER_JABBER = "twitter@twitter.com"
11
+
12
+ def self.log(message)
13
+ Syslog.open($0, Syslog::LOG_PID | Syslog::LOG_CONS) { |s| s.warning message }
14
+ end
15
+
16
+ def initialize(twitter_username, twitter_password, jabber_account, jabber_password)
17
+ @twitter = Twitter::Base.new(twitter_username, twitter_password)
18
+ super(jabber_account, jabber_password)
19
+ end
20
+
21
+ def log(message)
22
+ TwitterBot.log(message)
23
+ end
24
+
25
+ def say(message)
26
+ deliver(TWITTER_JABBER, message)
27
+ end
28
+
29
+ def direct_message(to, message)
30
+ deliver(TWITTER_JABBER, "d #{to} #{message}")
31
+ end
32
+
33
+ def user(id_or_screen_name)
34
+ @twitter.user(id_or_screen_name)
35
+ end
36
+ end
File without changes
@@ -0,0 +1,31 @@
1
+
2
+ # Gem::Specification for Twitter-bot-0.1
3
+ # Originally generated by Echoe
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = %q{twitter-bot}
7
+ s.version = "0.1"
8
+
9
+ s.specification_version = 2 if s.respond_to? :specification_version=
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.authors = ["Erik Kastner"]
13
+ s.date = %q{2008-04-29}
14
+ s.description = %q{A real-time twitter bot that uses Jabber (XMPP)}
15
+ s.email = %q{}
16
+ s.extra_rdoc_files = ["CHANGELOG", "lib/twitter_bot.rb", "LICENSE", "README", "README.markdown"]
17
+ s.files = ["CHANGELOG", "examples/my_bot.rb", "lib/twitter_bot.rb", "LICENSE", "Manifest", "README", "README.markdown", "site/index.html", "twitter-bot.gemspec"]
18
+ s.has_rdoc = true
19
+ s.homepage = %q{http://github.com/kastner/twitter-bot/}
20
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Twitter-bot", "--main", "README"]
21
+ s.require_paths = ["lib"]
22
+ s.rubyforge_project = %q{twitter-bot}
23
+ s.rubygems_version = %q{1.0.1}
24
+ s.summary = %q{A real-time twitter bot that uses Jabber (XMPP)}
25
+ end
26
+
27
+
28
+ # # Original Rakefile source (requires the Echoe gem):
29
+ #
30
+ # require 'echoe'
31
+ # Echoe.new('twitter-bot')
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kastner-twitter-bot
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: ruby
6
+ authors:
7
+ - Erik Kastner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-04-29 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: A real-time twitter bot that uses Jabber (XMPP)
17
+ email: ""
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - CHANGELOG
24
+ - lib/twitter_bot.rb
25
+ - LICENSE
26
+ - README
27
+ - README.markdown
28
+ files:
29
+ - CHANGELOG
30
+ - examples/my_bot.rb
31
+ - lib/twitter_bot.rb
32
+ - LICENSE
33
+ - Manifest
34
+ - README
35
+ - README.markdown
36
+ - site/index.html
37
+ - twitter-bot.gemspec
38
+ has_rdoc: true
39
+ homepage: http://github.com/kastner/twitter-bot/
40
+ post_install_message:
41
+ rdoc_options:
42
+ - --line-numbers
43
+ - --inline-source
44
+ - --title
45
+ - Twitter-bot
46
+ - --main
47
+ - README
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ requirements: []
63
+
64
+ rubyforge_project: twitter-bot
65
+ rubygems_version: 1.2.0
66
+ signing_key:
67
+ specification_version: 2
68
+ summary: A real-time twitter bot that uses Jabber (XMPP)
69
+ test_files: []
70
+