Skip to content
This repository has been archived by the owner on Mar 6, 2023. It is now read-only.

Commit

Permalink
move skeleton output into its own class. add the auth info to the output
Browse files Browse the repository at this point in the history
  • Loading branch information
muffinista committed Oct 18, 2013
1 parent eb38edf commit cb3a28e
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 35 deletions.
37 changes: 3 additions & 34 deletions bin/chatterbot-register
Expand Up @@ -2,6 +2,7 @@
#$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')

require 'chatterbot'
require 'chatterbot/skeleton'
require 'optparse'

include Chatterbot::Helpers
Expand Down Expand Up @@ -39,39 +40,6 @@ opts.on_tail("-h", "--help", "Show this message") do
exit
end

#
# skeleton code for a bot -- pretty basic but covers the bases
#
skeleton = <<'EOF'
#!/usr/bin/env ruby
require 'rubygems'
require 'chatterbot/dsl'
# remove this to send out tweets
debug_mode
# remove this to update the db
no_update
# remove this to get less output when running
verbose
# here's a list of users to ignore
blacklist "abc", "def"
# here's a list of things to exclude from searches
exclude "hi", "spammer", "junk"
search "keyword" do |tweet|
reply "Hey #USER# nice to meet you!", tweet
end
replies do |tweet|
reply "Yes #USER#, you are very kind to say that!", tweet
end
EOF

extra = opts.parse!(ARGV)


Expand Down Expand Up @@ -106,7 +74,8 @@ unless @bot.screen_name.nil?
puts "writing skeleton to #{skel_dest}"

f = File.new(skel_dest, "w")
f.write(skeleton)
script = Chatterbot::Skeleton.generate(@bot)
f.write(script)
f.close

File.chmod(0740, skel_dest)
Expand Down
11 changes: 10 additions & 1 deletion lib/chatterbot.rb
Expand Up @@ -28,7 +28,6 @@ def symbolize_keys!
#
# the big kahuna!
module Chatterbot

#
# load in our assorted modules
def self.load
Expand All @@ -46,6 +45,16 @@ def self.load

require "chatterbot/bot"
end

require 'chatterbot/version'

# Return a directory with the project libraries.
def self.libdir
t = [File.expand_path(File.dirname(__FILE__)), "#{Gem.dir}/gems/chatterbot-#{Chatterbot::VERSION}"]

t.each {|i| return i if File.readable?(i) }
raise "both paths are invalid: #{t}"
end
end


Expand Down
19 changes: 19 additions & 0 deletions lib/chatterbot/skeleton.rb
@@ -0,0 +1,19 @@
module Chatterbot

#
# bot template generator
class Skeleton
class << self
def generate(bot)
path = File.join(Chatterbot.libdir, "..", "templates", "skeleton.txt")
src = File.read(path)
opts = bot.config.merge({
:name => bot.botname,
:timestamp => Time.now
})

src % opts
end
end
end
end
37 changes: 37 additions & 0 deletions templates/skeleton.txt
@@ -0,0 +1,37 @@
#!/usr/bin/env ruby

require 'rubygems'
require 'chatterbot/dsl'

#
# this is the script for the twitter bot %{name}
# generated on %{timestamp}
#

consumer_key '%{consumer_key}'
consumer_secret '%{consumer_secret}'

secret '%{secret}'
token '%{token}'

# remove this to send out tweets
debug_mode

# remove this to update the db
no_update
# remove this to get less output when running
verbose

# here's a list of users to ignore
blacklist "abc", "def"

# here's a list of things to exclude from searches
exclude "hi", "spammer", "junk"

search "keyword" do |tweet|
reply "Hey #USER# nice to meet you!", tweet
end

replies do |tweet|
reply "Yes #USER#, you are very kind to say that!", tweet
end

0 comments on commit cb3a28e

Please sign in to comment.