Skip to content

Commit

Permalink
Fix admin only commands, add a configuration system, and fix some oth…
Browse files Browse the repository at this point in the history
…er random things
  • Loading branch information
cmelbye committed Dec 24, 2008
1 parent d6829de commit 6d0c43e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
config.yaml
db/*
4 changes: 3 additions & 1 deletion bot.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
$LOAD_PATH << './lib'
puts "Loading IRC..."
require 'irc'
puts "Loading Configuration Class..."
require 'configuration'
puts "Loading the IRC Parser..."
require 'parser'
puts "Loading RubyGems..."
Expand Down Expand Up @@ -168,7 +170,7 @@
end
end

if e.message =~ /^complete (\d+)$/
if e.message =~ /^complete task (\d+)$/
task = Task.find( $1 )
if task.nil?
irc.msg(e.sender.nick, 'That task does not exist, sorry!')
Expand Down
14 changes: 14 additions & 0 deletions lib/configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Configuration
def initialize( file = 'config.yaml' )
@config = YAML.load_file( file )
end

def is_admin?(nick, host)
for person in @config
if person['nick'] == nick && person['host'] == host
return true
end
end
return false
end
end
17 changes: 5 additions & 12 deletions lib/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,17 @@ def command(e, name, admin_only = false)
@event = e
if e.message =~ /^`#{name}(?: (.*))?/
c = Parser::Command.new($1)
if admin_only && is_admin?
true
elsif admin_only && !is_admin?
false
else
true
if admin_only && !is_admin?
return false
end
yield c, params
else
false
return false
end
end

def is_admin?
if @event.sender.nick == "chuck"
true
else
false
end
config = Configuration.new
return config.is_admin?( @event.sender.nick, @event.sender.host )
end
end

0 comments on commit 6d0c43e

Please sign in to comment.