Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated autumn to latest version.

Added !github and !githubs command for lookup of github stuffs
  • Loading branch information...
commit 60378e84d5eba240a7390706dd534b3bfb0a21fe 1 parent 76084bc
@radar radar authored
1  autumn
@@ -0,0 +1 @@
+Subproject commit 7c9debd60e1406fd53e7b6a2e394dc22a293292e
View
24 leaves/logga/controller.rb
@@ -197,19 +197,33 @@ def railscast_command(stem, sender, reply_to, msg, opts={})
search("http://railscasts.com/episodes", stem, sender, msg, reply_to, opts, "search")
end
- private
+ def githubs_command(stem, sender, reply_to, msg, opts={})
+ search("http://github.com/search", stem, sender, msg, reply_to, opts)
+ end
+ def github_command(stem, sender, reply_to, msg, opts={})
+ parts = msg.split(" ")
+ message = "http://github.com/#{parts[0]}/#{parts[1]}/tree/#{parts[2].nil? ? 'master' : parts[2]}"
+ message += "/#{parts[3..-1].join("/")}" if !parts[3].nil?
+ direct_at(stem, reply_to, message, opts[:directed_at])
+ end
- def search(host, stem, sender, msg, reply_to, opts, query_parameter="q")
- message = "#{host}?#{query_parameter}=#{msg.split(" ").join("+")}"
- if opts[:directed_at]
- message = opts[:directed_at] + ": #{message}"
+ private
+
+ def direct_at(stem, reply_to, message, who=nil)
+ if who
+ message = who + ": #{message}"
stem.message(message, reply_to)
else
return message
end
end
+ def search(host, stem, sender, msg, reply_to, opts, query_parameter="q")
+ message = "#{host}?#{query_parameter}=#{msg.split(" ").join("+")}"
+ direct_at(stem, reply_to, message, opts[:directed_at])
+ end
+
# I, Robot.
def i_am_a_bot
View
1  libs/authentication.rb
@@ -56,6 +56,7 @@ def authenticate(stem, channel, sender, leaf)
# password").
def unauthorized
+ "You must be an administrator for this bot to do that."
end
end
View
89 libs/datamapper_hacks.rb
@@ -126,44 +126,40 @@ def #{name}_association
opts[:child_model] ||= opts.delete(:class_name) || Extlib::Inflection.classify(name)
opts[:parent_model] = model
opts[:repository_name] = repository_name
- opts[:remote_relationship_name] ||= opts.delete(:remote_name) || name
+ opts[:remote_relationship_name] ||= opts.delete(:remote_name) || Extlib::Inflection.tableize(opts[:child_model])
opts[:parent_key] = opts[:parent_key]
opts[:child_key] = opts[:child_key]
opts[:mutable] = true
names = [ opts[:child_model].demodulize, opts[:parent_model].name.demodulize ].sort
- model_name = names.join
+ model_name = names.join.gsub("::", "")
storage_name = Extlib::Inflection.tableize(Extlib::Inflection.pluralize(names[0]) + names[1])
model_module = model.to_s.split('::')
model_module.pop
model_module = model_module.join('::')
+ model_module = model_module.empty? ? Object : eval("::#{model_module}")
-
opts[:near_relationship_name] = Extlib::Inflection.tableize(model_name).to_sym
-
+
model.has(model.n, opts[:near_relationship_name], :old_behavior => true)
relationship = DataMapper::Associations::RelationshipChain.new(opts)
model.relationships(repository_name)[name] = relationship
- unless Object.const_defined?(model_name)
- bts = names.collect do |name|
- "belongs_to #{Extlib::Inflection.underscore(name).to_sym.inspect}"
- end
-
- Object.const_get(model_module).module_eval <<-EOS, __FILE__, __LINE__
- class #{model_name}
- include DataMapper::Resource
-
- #def self.name; #{model_name.inspect} end
- #def self.default_repository_name; #{repository_name.inspect} end
- def self.many_to_many; true end
-
- storage_names[#{repository_name.inspect}] = #{storage_name.inspect}
-
- #{bts.join("\n")}
- end
+ unless model_module.const_defined?(model_name)
+ model = DataMapper::Model.new(storage_name)
+
+ model.class_eval <<-EOS, __FILE__, __LINE__
+ def self.name; #{model_name.inspect} end
+ def self.default_repository_name; #{repository_name.inspect} end
+ def self.many_to_many; true end
EOS
+
+ names.each do |n|
+ model.belongs_to(Extlib::Inflection.underscore(n).gsub("/", "_").to_sym, :class_name => n)
+ end
+
+ model_module.const_set(model_name, model)
end
relationship
@@ -183,6 +179,7 @@ def near_relationship
end
def remote_relationship
+ return nil unless near_relationship
near_relationship.child_model.relationships(repository.name)[@remote_relationship_name] ||
near_relationship.child_model.relationships(repository.name)[@remote_relationship_name.to_s.singularize.to_sym]
end
@@ -223,29 +220,32 @@ def child_key(repository_name=nil)
repository_name ||= repository.name
@child_key ||= Hash.new
@child_key[repository_name] ||= begin
- model_properties = child_model.properties(repository_name)
+ child_key = nil
+ repository(repository_name).scope do |r|
+ model_properties = child_model.properties(repository_name)
- child_key = parent_key(repository_name).zip(@child_properties || []).map do |parent_property,property_name|
- # TODO: use something similar to DM::NamingConventions to determine the property name
- parent_name = Extlib::Inflection.underscore(Extlib::Inflection.demodulize(parent_model.base_model.name))
- property_name ||= "#{parent_name}_#{parent_property.name}".to_sym
+ child_key = parent_key(repository_name).zip(@child_properties || []).map do |parent_property,property_name|
+ # TODO: use something similar to DM::NamingConventions to determine the property name
+ parent_name = Extlib::Inflection.underscore(Extlib::Inflection.demodulize(parent_model.base_model.name))
+ property_name ||= "#{parent_name}_#{parent_property.name}".to_sym
- if model_properties.has_property?(property_name)
- model_properties[property_name]
- else
- options = {}
+ if model_properties.has_property?(property_name)
+ model_properties[property_name]
+ else
+ options = {}
- [ :length, :precision, :scale ].each do |option|
- options[option] = parent_property.send(option)
- end
+ [ :length, :precision, :scale ].each do |option|
+ options[option] = parent_property.send(option)
+ end
- # NOTE: hack to make each many to many child_key a true key,
- # until I can figure out a better place for this check
- if child_model.respond_to?(:many_to_many)
- options[:key] = true
- end
+ # NOTE: hack to make each many to many child_key a true key,
+ # until I can figure out a better place for this check
+ if child_model.respond_to?(:many_to_many)
+ options[:key] = true
+ end
- child_model.property(property_name, parent_property.primitive, options)
+ child_model.property(property_name, parent_property.primitive, options)
+ end
end
end
DataMapper::PropertySet.new(child_key)
@@ -265,10 +265,13 @@ def parent_key(repository_name=nil)
repository_name ||= repository.name
@parent_key ||= Hash.new
@parent_key[repository_name] ||= begin
- parent_key = if @parent_properties
- parent_model.properties(repository_name).slice(*@parent_properties)
- else
- parent_model.key(repository_name)
+ parent_key = nil
+ repository(repository_name).scope do |r|
+ parent_key = if @parent_properties
+ parent_model.properties(repository_name).slice(*@parent_properties)
+ else
+ parent_model.key(repository_name)
+ end
end
DataMapper::PropertySet.new(parent_key)
end
View
25 libs/foliater.rb
@@ -79,7 +79,7 @@ def each_leaf
def load_configs(stem_config, leaf_config)
leaf_config.each do |name, options|
- global_config_file = "leaves/#{options['class'].snakecase}/config.yml"
+ global_config_file = "#{AL_ROOT}/leaves/#{options['class'].snakecase}/config.yml"
if File.exist? global_config_file then
config.leaf name, YAML.load(File.open(global_config_file))
end
@@ -105,11 +105,11 @@ def load_leaf_classes
end
def load_leaf_controller(type)
- controller_file = "leaves/#{type.snakecase}/controller.rb"
+ controller_file = "#{AL_ROOT}/leaves/#{type.snakecase}/controller.rb"
raise "controller.rb file for leaf #{type} not found" unless File.exist? controller_file
controller_code = nil
begin
- File.open("leaves/#{type.snakecase}/controller.rb", 'r') { |f| controller_code = f.read }
+ File.open("#{AL_ROOT}/leaves/#{type.snakecase}/controller.rb", 'r') { |f| controller_code = f.read }
rescue Errno::ENOENT
raise "controller.rb file for leaf #{type} not found"
end
@@ -119,7 +119,7 @@ def load_leaf_controller(type)
def load_leaf_helpers(type)
mod = config.leaf(type, :module)
helper_code = nil
- Dir.glob("leaves/#{type.snakecase}/helpers/*.rb").each do |helper_file|
+ Dir.glob("#{AL_ROOT}/leaves/#{type.snakecase}/helpers/*.rb").each do |helper_file|
File.open(helper_file, 'r') { |f| helper_code = f.read }
mod.module_eval helper_code
end
@@ -140,7 +140,7 @@ def load_leaf_helpers(type)
def load_leaf_views(type)
views = Hash.new
view_text = nil
- Dir.glob("leaves/#{type.snakecase}/views/*.txt.erb").each do |view_file|
+ Dir.glob("#{AL_ROOT}/leaves/#{type.snakecase}/views/*.txt.erb").each do |view_file|
view_name = File.basename(view_file).match(/^(.+)\.txt\.erb$/)[1]
File.open(view_file, 'r') { |f| view_text = f.read }
views[view_name] = view_text
@@ -171,9 +171,20 @@ def load_all_leaf_models
end
def load_leaf_models(leaf)
- mod = config.leaf(leaf.options[:class], :module)
+ model_code = nil
+ mod = config.leaf(leaf.options[:class], :module) # mod.constants.map { |const_name| mod.const_get(const_name) }.select { |const| const.ancestors.include? ActiveRecord::Base }.each do |model|
+ # # model.storage_names[leaf.database_name] = model.to_s.demodulize.snakecase.pluralize
+ # end
leaf.database do
- Dir.glob("leaves/#{leaf.options[:class].snakecase}/models/*.rb").each { |model_file| require model_file }
+ Dir.glob("#{AL_ROOT}/leaves/#{leaf.options[:class].snakecase}/models/*.rb").each do |model_file|
+ File.open(model_file, 'r') { |f| model_code = f.read }
+ mod.module_eval model_code
+ end
+ # Need to manually set the table names of the models because we loaded
+ # them inside a module
+ unless $NO_DATABASE
+
+ end
end
end
View
28 libs/genesis.rb
@@ -6,12 +6,11 @@
require 'yaml'
require 'logger'
require 'facets'
-require 'facets/annotations'
+require 'facets/random'
+require 'anise'
require 'libs/misc'
require 'libs/speciator'
require 'libs/authentication'
-
-gem 'activerecord', "2.1.2"
require 'activerecord'
AUTUMN_VERSION = "3.0 (7-4-08)"
@@ -53,7 +52,7 @@ def boot!(invoke=true)
def load_global_settings
begin
- config.global YAML.load(File.open('config/global.yml'))
+ config.global YAML.load(File.open("#{AL_ROOT}/config/global.yml"))
rescue SystemCallError
raise "Couldn't find your global.yml file."
end
@@ -66,7 +65,7 @@ def load_global_settings
# PREREQS: load_global_settings
def load_season_settings
- @season_dir = "config/seasons/#{config.global :season}"
+ @season_dir = "#{AL_ROOT}/config/seasons/#{config.global :season}"
raise "The current season doesn't have a directory." unless File.directory? @season_dir
begin
config.season YAML.load(File.open("#{@season_dir}/season.yml"))
@@ -113,7 +112,7 @@ def init_system_logger
# PREREQS: load_libraries
def load_daemon_info
- Dir.glob('resources/daemons/*.yml').each do |yml_file|
+ Dir.glob("#{AL_ROOT}/resources/daemons/*.yml").each do |yml_file|
yml = YAML.load(File.open(yml_file, 'r'))
Daemon.new File.basename(yml_file, '.yml'), yml
end
@@ -122,7 +121,7 @@ def load_daemon_info
# Loads Ruby code in the shared directory.
def load_shared_code
- Dir.glob('shared/**/*.rb').each { |lib| load lib }
+ Dir.glob("#{AL_ROOT}/shared/**/*.rb").each { |lib| load lib }
end
# Creates connections to databases using the DataMapper gem.
@@ -131,13 +130,16 @@ def load_shared_code
def load_databases
db_file = "#{@season_dir}/database.yml"
- if !File.exist?(db_file)
+ if not File.exist? db_file then
$NO_DATABASE = true
- else
- file = YAML::load(File.open(db_file, 'r'))
- ActiveRecord::Base.establish_connection(file[file.keys.first])
+ return
end
-# gem 'extlib', '=0.9.8'
+
+ dbconfig = YAML.load(File.open(db_file, 'r'))
+ ActiveRecord::Base.establish_connection(dbconfig[dbconfig.keys.first])
+ # dbconfig.rekey(&:to_sym).each do |db, config|
+ # # DataMapper.setup(db, config.kind_of?(Hash) ? config.rekey(&:to_sym) : config)
+ # end
end
# Invokes the Foliater.load method. Spawns a new thread to oversee the
@@ -181,7 +183,7 @@ def invoke_foliater(invoke=true)
private
def log_name
- "log/#{config.global(:season)}.log"
+ "#{AL_ROOT}/log/#{config.global(:season)}.log"
end
end
end
View
14 libs/leaf.rb
@@ -148,6 +148,8 @@ module Autumn
# initialization options; see initialize.
class Leaf
+ include Anise::Annotation
+
# Default for the +command_prefix+ init option.
DEFAULT_COMMAND_PREFIX = '!'
@@view_alias = Hash.new { |h,k| k }
@@ -246,8 +248,8 @@ def irc_mode_event(stem, sender, arguments) # :nodoc:
gained_privileges(stem, arguments[:mode]) { |prop| someone_did_gain_privilege stem, arguments[:channel], arguments[:parameter], prop, sender }
lost_privileges(stem, arguments[:mode]) { |prop| someone_did_lose_privilege stem, arguments[:channel], arguments[:parameter], prop, sender }
else
- gained_properties(stem, arguments[:mode]) { |prop| channel_did_gain_property stem, arguments[:channel], prop, arguments, sender }
- lost_properties(stem, arguments[:mode]) { |prop| channel_did_lose_property stem, arguments[:channel], prop, arguments, sender }
+ gained_properties(stem, arguments[:mode]) { |prop| channel_did_gain_property stem, arguments[:channel], prop, arguments[:parameter], sender }
+ lost_properties(stem, arguments[:mode]) { |prop| channel_did_lose_property stem, arguments[:channel], prop, arguments[:parameter], sender }
end
end
end
@@ -400,7 +402,7 @@ def self.before_filter(filter, options={})
options[:only] = [ options[:only] ]
end
if options[:except] and not options[:except].kind_of? Array then
- options[:except] = [ options[:only] ]
+ options[:except] = [ options[:except] ]
end
write_inheritable_array 'before_filters', [ [ filter.to_sym, options ] ]
end
@@ -427,7 +429,7 @@ def self.after_filter(filter, options={})
options[:only] = [ options[:only] ]
end
if options[:except] and not options[:except].kind_of? Array then
- options[:except] = [ options[:only] ]
+ options[:except] = [ options[:except] ]
end
write_inheritable_array 'after_filters', [ [ filter.to_sym, options ] ]
end
@@ -685,9 +687,7 @@ def authenticated?(cmd, stem, channel, sender)
return true if @authenticator.nil?
# Any method annotated as protected is authenticated unconditionally
if not self.class.ann("#{cmd}_command".to_sym, :protected) then
- # Otherwise, we only authenticate if it's listed as protected in the config
- return true if options[:authentication]['only'] and not options[:authentication]['only'].include? cmd
- return true if options[:authentication]['except'] and options[:authentication]['except'].include? cmd
+ return true
end
if @authenticator.authenticate(stem, channel, sender, self) then
return true
View
23 libs/stem.rb
@@ -154,6 +154,7 @@ module Autumn
class Stem
include StemFacade
+ include Anise::Annotation
# Describes all possible channel names. Omits the channel prefix, as that
# can vary from server to server. (See channel?)
@@ -444,6 +445,7 @@ def initialize(server, newnick, opts)
def add_listener(obj)
@listeners << obj
+ obj.class.extend Anise::Annotation # give it the ability to sync
obj.respond :added, self
end
@@ -772,9 +774,12 @@ def receive(comm)
elsif comm =~ /^:(#{NICK_REGEX})\s+([A-Z]+)\s+(.*?)[\r\n]*$/ then
sender = { :nick => $1 }
command, arg_str = $2, $3
+ elsif comm =~ /^:([^\s:]+?)\s+([A-Z]+)\s+(.*?)[\r\n]*$/ then
+ server, command, arg_str = $1, $2, $3
+ arg_array, msg = split_out_message(arg_str)
elsif comm =~ /^(\w+)\s+:(.+?)[\r\n]*$/ then
command, msg = $1, $2
- elsif comm =~ /^:(.+?)\s+(\d+)\s+(.*?)[\r\n]*$/ then
+ elsif comm =~ /^:([^\s:]+?)\s+(\d+)\s+(.*?)[\r\n]*$/ then
server, code, arg_str = $1, $2, $3
arg_array, msg = split_out_message(arg_str)
@@ -786,7 +791,7 @@ def receive(comm)
meths[:irc_response] = [ self, code, server, name, arg_array, msg ]
return meths
else
- logger.error "Couldn't parse IRC message: #{comm}"
+ logger.error "Couldn't parse IRC message: #{comm.inspect}"
return meths
end
@@ -852,11 +857,15 @@ def receive(comm)
return meths
end
- def split_out_message(arg_str='')
- arg_str, *msg = arg_str.split(':')
- msg = msg.join(':')
- arg_array = arg_str.to_s.strip.words
- return arg_array, msg
+ def split_out_message(arg_str)
+ if arg_str.match(/^(.*?):(.*)$/) then
+ arg_array = $1.strip.words
+ msg = $2
+ return arg_array, msg
+ else
+ # no colon in message
+ return arg_str.strip.words, nil
+ end
end
def post_startup
Please sign in to comment.
Something went wrong with that request. Please try again.