Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Checking in initial work on the refactorization
- Loading branch information
Showing
16 changed files
with
398 additions
and
77 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,41 @@ | |||
class GlobalChannel | |||
include NetUtils | |||
|
|||
def privatemsg(msg, client) | |||
# Broadcast to all users | |||
carp "#{msg} from #{client}" | |||
$user_store.each_user do |user| | |||
user.reply :privmsg, client.userprefix, "#all", msg | |||
end | |||
end | |||
|
|||
def notice(msg, client) | |||
$user_store.each_user {|user| | |||
user.reply :notice, client.userprefix, @name, msg | |||
} | |||
end | |||
|
|||
def each_user(&blk) | |||
$user_store.each_user(&blk) | |||
end | |||
|
|||
def name; "#all"; end | |||
|
|||
def nicks; $user_store.nicks + ["Steve"]; end | |||
|
|||
def topic | |||
"All that is posted on Kookaburra" | |||
end | |||
|
|||
def join(client); true; end | |||
|
|||
def part(client, msg); true; end | |||
|
|||
def is_member?(user); true; end | |||
alias has_nick? is_member? | |||
|
|||
def mode(u) | |||
u == "Steve" ? "@" : " " | |||
end | |||
|
|||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,63 @@ | |||
# Logger partially based on Merb logger | |||
class IRCLogger | |||
|
|||
LEVELS = { | |||
:fatal => 7, | |||
:error => 6, | |||
:warn => 4, | |||
:info => 3, | |||
:debug => 0 | |||
} | |||
|
|||
COLOURS = { | |||
:fatal => 31, # red | |||
:error => 33, # yellow | |||
:warn => 35, # magenta | |||
:info => 32, # green | |||
:debug => 34 # white | |||
} | |||
|
|||
attr_accessor :level, :file, :verbose | |||
|
|||
def initialize(level = :info, verbose = false) | |||
self.level = level.to_sym | |||
self.verbose = verbose | |||
self.file = File.open(File.join(Kookaburra.root, "log/ircd.log"), "a+") | |||
end | |||
|
|||
def close! | |||
self.file.close | |||
end | |||
|
|||
LEVELS.each do |name, value| | |||
|
|||
define_method(name) do |message| | |||
write "[#{name.to_s.upcase}] #{message}", name if LEVELS[self.level] <= value | |||
end | |||
|
|||
define_method(:"#{name}?") do | |||
LEVELS[self.level] <= value | |||
end | |||
end | |||
|
|||
def debug_exception(exception) | |||
|
|||
debug "Exception: #{exception}" | |||
exception.backtrace.each do |l| | |||
debug ">> #{l}" | |||
end | |||
|
|||
end | |||
|
|||
private | |||
|
|||
def write(message, level = self.level) | |||
self.file.puts message | |||
STDOUT.puts colourize(message, level) if self.verbose | |||
end | |||
|
|||
def colourize(message, level) | |||
"\033[1;#{COLOURS[level]}m#{message}\033[0m" | |||
end | |||
|
|||
end |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,17 @@ | |||
#!/usr/bin/env ruby | |||
require 'rubygems' | |||
require 'eventmachine' | |||
require 'thread' | |||
|
|||
DIR = File.dirname(__FILE__) | |||
%w(irc_replies net_utils message_server synchronized_store default_stores | |||
irc_channel irc_client irc_server global_channel irc_logger kookaburra).each do |f| | |||
require File.join(DIR, f) | |||
end | |||
|
|||
$channel_store["#all"] = GlobalChannel.new | |||
|
|||
include IRCReplies | |||
|
|||
CHANNEL = /^[#\$&]+/ | |||
PREFIX = /^:[^ ]+ +(.+)$/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,69 @@ | |||
class Kookaburra | |||
class << self | |||
|
|||
def version; "0.1"; end | |||
|
|||
def logger | |||
@@logger ||= setup_logger! | |||
end | |||
|
|||
def verbose? | |||
@@verbose ||= false | |||
end | |||
|
|||
def verbose=(value) | |||
@@verbose = !!value | |||
end | |||
|
|||
def root | |||
@@root || File.expand_path(File.join(File.dirname(__FILE__), "..")) | |||
end | |||
|
|||
def root=(path) | |||
@@root = path | |||
end | |||
|
|||
def host_name | |||
@@host_name ||= Socket.gethostname.split(/\./).shift | |||
end | |||
|
|||
def started_at; @@started_at ||= Time.now.to_s; end | |||
|
|||
def max_nick_tries; 5; end | |||
|
|||
# Initialization | |||
|
|||
def setup_logger! | |||
log_level = :debug | |||
if ARGV.detect { |c| c.to_s =~ /^(\-\-log\-level(.*))/i } | |||
cmd = $1 | |||
if cmd.include?("=") | |||
log_level = cmd.split("=", 2)[1].to_sym | |||
else | |||
log_level = ARGV[ARGV.index(cmd) + 1].to_sym | |||
end | |||
end | |||
@@logger ||= IRCLogger.new((log_level || :debug).to_sym, self.verbose?) | |||
end | |||
|
|||
def setup_traps! | |||
trap("INT") do | |||
$message_server.dump | |||
system("kill -9 #{$$}") | |||
end | |||
end | |||
|
|||
def setup_verbosity! | |||
self.verbose = !ARGV.detect { |c| c =~ /-v/ }.nil? || false | |||
end | |||
|
|||
def setup! | |||
@@started_at = Time.now.to_s | |||
setup_verbosity! | |||
setup_logger! | |||
setup_traps! | |||
end | |||
|
|||
|
|||
end | |||
end |
Oops, something went wrong.