Permalink
Browse files

added quit bugfix. fixed news bug

  • Loading branch information...
1 parent 77b9fba commit d77beb96d038e997dc6f5c4e614646d285772a5a root committed Apr 10, 2008
Showing with 292 additions and 93 deletions.
  1. +1 −0 .gitignore
  2. +1 −1 config/seasons/testing/stems.yml
  3. +7 −4 leaves/rigel.rb
  4. +2 −1 libs/coder.rb
  5. +1 −1 libs/ctcp.rb
  6. +49 −11 libs/daemon.rb
  7. +13 −5 libs/formatting.rb
  8. +12 −2 libs/generator.rb
  9. +10 −10 libs/leaf.rb
  10. +174 −52 libs/stem.rb
  11. +5 −3 libs/stem_facade.rb
  12. +17 −3 support/rigel/noobkit.rb
View
@@ -1 +1,2 @@
+*.*~
log/*
@@ -5,5 +5,5 @@ Example:
- Rigel
- Scorekeeper
rejoin: true
- channel: "#rigels-home"
+ channel: "#ruby"
server: irc.freenode.com
View
@@ -23,10 +23,13 @@ def suck_command(stem, sender, reply_to, msg)
when /penis|cock|dick/i
"No way, dude!"
when /lolipop/i
- "Yea, i like sweets!"
+ "Yea, i like that!"
+ else
+ "No, I don't want that, thanks"
end
end
-
+ alias eat_command suck_command
+
def yoMamma_command(stem, sender, reply_to, msg)
"Yo dude! What's crackin?"
end
@@ -52,8 +55,8 @@ def whats_command(stem, sender, reply_to, msg)
end
def news_command(stem, sender, reply_to, msg)
- news = news(msg.strip)
- "#{color :blue}" + news[:title] + "#{uncolor}\n" + news[:link]
+ news = news(msg)
+ news.is_a?(String) ? news : ("#{color :blue}" + news[:title] + "#{uncolor}\n" + news[:link])
end
def pastie_command(stem, sender, reply_to, msg)
View
@@ -151,7 +151,8 @@ def leaf(name)
leaf << "private"
leaf.newline!
leaf.method('authenticate_filter', 'stem', 'channel', 'sender', 'command', 'msg', 'opts') do |auth|
- auth << '[ :operator, :admin, :founder, :channel_owner ].include? stem.privilege(channel, sender)'
+ auth << "# Returns true if the sender has any of the privileges listed below"
+ auth << 'not ([ :operator, :admin, :founder, :channel_owner ] & [ stem.privilege(channel, sender) ].flatten).empty?'
end
end
end
View
@@ -136,7 +136,7 @@ def irc_notice_event(stem, sender, arguments) # :nodoc:
def ctcp_version_request(handler, stem, sender, arguments)
return unless handler == self
- send_ctcp_reply stem, sender[:nick], 'VERSION', "Autumn 2.0.2, a Ruby IRC framework", `uname -sr`, "http://autumn-leaves.googlecode.com/"
+ send_ctcp_reply stem, sender[:nick], 'VERSION', "Autumn 2.0.3, a Ruby IRC framework", `uname -sr`, "http://autumn-leaves.googlecode.com/"
end
# Replies to a CTCP PING request by sending back the same arguments as a
View
@@ -1,4 +1,5 @@
require 'facets/string/partitions'
+require 'facets/string/indexable'
require 'facets/array/only'
module Autumn
@@ -34,7 +35,7 @@ class Daemon
def initialize(name, info)
if name.nil? and info.nil? then # it's the default hash
- raise "Already created a default Daemon" if self.class.class_variables.include? :@@default
+ raise "Already created a default Daemon" if self.class.class_variable_defined? :@@default
@usermode = Hash.parroting
@privilege = Hash.parroting
@user_prefix = Hash.parroting
@@ -54,16 +55,16 @@ def initialize(name, info)
@@instances[name] = self
# Build up our default so it contains all keys with no conflicting
- # values across different server specs. Delete keys from the default
- # hash for which we found duplicates.
- info.each do |hname, hsh|
- next unless @@default.respond_to? hname.to_sym
- default_hash = @@default.send(hname.to_sym)
-
- (hsh.keys & default_hash.keys).each { |k| default_hash.delete k }
- uniques = hsh.reject { |k, v| default_hash.include? k }
- default_hash.update uniques
- end
+ # values across different server specs. Delete keys from the default
+ # hash for which we found duplicates.
+ info.each do |hname, hsh|
+ next unless @@default.respond_to? hname.to_sym
+ default_hash = @@default.send(hname.to_sym)
+
+ (hsh.keys & default_hash.keys).each { |k| default_hash.delete k }
+ uniques = hsh.reject { |k, v| default_hash.include? k }
+ default_hash.update uniques
+ end
end
end
@@ -141,6 +142,43 @@ def privilege_mode?(mode)
raise ArgumentError, "Invalid mode string '#{mode}'" unless mode =~ /^[\+\-]\S+$/
mode.except_first.chars.all? { |c| privilege? c }
end
+
+ # Returns true if the first character(s) of a nick are valid privilege
+ # prefixes.
+
+ def nick_prefixed?(nick)
+ user_prefix? nick.first
+ end
+
+ # Given a nick, returns that nick stripped of any privilege characters on
+ # the left side.
+
+ def just_nick(name)
+ nick = name.dup
+ while nick_prefixed?(nick)
+ nick.slice! 0, 1
+ end
+ return nick
+ end
+
+ # Given a nick, returns the privileges granted to this nick, as indicated by
+ # the prefix characters. Returns :unvoiced if no prefix characters are
+ # present. Returns an array of privileges if multiple prefix characters are
+ # present.
+
+ def nick_privilege(name)
+ privs = Array.new
+ nick = name.dup
+ while user_prefix? nick.first
+ privs << user_prefix[nick.first]
+ nick.slice! 0, 1
+ end
+ case privs.size
+ when 0 then :unvoiced
+ when 1 then privs.only
+ else privs
+ end
+ end
def method_missing(meth, *args) # :nodoc:
if meth.to_s =~ /^([a-z_]+)\?$/ then
View
@@ -50,7 +50,10 @@ module Mirc
# The mIRC color code sentinel.
COLOR_CODE = 3.chr
# Insert this character to stop colorizing text.
- UNCOLOR = COLOR_CODE
+ UNCOLOR = COLOR_CODE + " "
+ # Same as UNCOLOR, but suppresses the trailing space for situations where
+ # no conflict is assured.
+ UNCOLOR_NO_SPACE = COLOR_CODE
# Valid IRC colors, in the mIRC style, to be used with the color method.
COLORS = {
:white => '00',
@@ -98,7 +101,7 @@ module Mirc
def color(fgcolor, bgcolor=nil, options={})
fgcolor = :black unless COLORS.include? fgcolor
- bgcolor = :white unless (bgcolor.nil? or COLORS.include? bgcolor)
+ bgcolor = :white unless (bgcolor.nil? or COLORS.include? bgcolor)
"#{COLOR_CODE}#{COLORS[fgcolor]}#{bgcolor ? (',' + COLORS[bgcolor]) : ''}#{options[:suppress_space] ? '' : ' '}"
end
@@ -114,8 +117,14 @@ def italic; ITALIC; end
# Sets all following text underline.
def underline; UNDERLINE; end
- # Removes coloring from all following text.
- def uncolor; UNCOLOR; end
+ # Removes coloring from all following text. Options:
+ #
+ # +suppress_space+:: By default, this method places a space after the
+ # uncolor token to prevent "color bleed." If you would
+ # like to suppress this behavior, set this to true.
+ def uncolor(options={})
+ options[:suppress_space] ? UNCOLOR_NO_SPACE : UNCOLOR
+ end
end
# The default formatter for leaves that do not specify otherwise.
@@ -219,7 +228,6 @@ def italic; ITALIC; end
# Sets all following text underline.
def underline; UNDERLINE; end
-
end
end
end
View
@@ -94,6 +94,8 @@ def unleaf(name, options={})
if File.exist? sname then
FileUtils.rm sname
deleted sname, options
+ else
+ notfound sname, options
end
dname = "support/#{name.pathize}"
if File.directory? dname then
@@ -152,8 +154,12 @@ def unseason(name, options={})
dname = "config/seasons/#{name.pathize}"
SEASON_FILES.each do |fname, content|
fpath = File.join(dname, fname)
- FileUtils.rm fpath
- deleted fpath, options
+ if File.exist? fpath then
+ FileUtils.rm fpath
+ deleted fpath, options
+ else
+ notfound fpath, options
+ end
end
Dir.rmdir dname
deleted dname, options
@@ -182,5 +188,9 @@ def deleted(path, options)
def notempty(path, options)
puts "-- notempty #{path}" if options[:verbose]
end
+
+ def notfound(path, options)
+ puts "-- notfound #{path}" if options[:verbose]
+ end
end
end
View
@@ -511,7 +511,7 @@ def quit_command(stem, sender, reply_to, msg)
# that is running this leaf.
def autumn_command(stem, sender, reply_to, msg)
- "Autumn version 2.0.2 (3-18-08), an IRC bot framework for Ruby (http://autumn-leaves.googlecode.com)."
+ "Autumn version 2.0.3 (3-22-08), an IRC bot framework for Ruby (http://autumn-leaves.googlecode.com)."
end
private
@@ -538,7 +538,7 @@ def parse_for_command(stem, sender, arguments)
stem.message response, reply_to
end
end
- end
+ end
end
end
@@ -548,17 +548,17 @@ def reload
exceptions = 0
Dir.glob("#{options[:root]}/leaves/*.rb").each do |file|
begin
- load file
- rescue Exception
- exceptions += 1
- end
+ load file
+ rescue Exception
+ exceptions += 1
+ end
end
Dir.glob("#{options[:root]}/support/**/*.rb").each do |file|
begin
- load file
- rescue Exception
- exceptions += 1
- end
+ load file
+ rescue Exception
+ exceptions += 1
+ end
end
#TODO it's slow to reload everything in leaves/ and support/ for every leaf, but there's not really a better way for now
logger.info "Reloading"
Oops, something went wrong.

0 comments on commit d77beb9

Please sign in to comment.