Skip to content

Commit

Permalink
Adding better code layout.
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkie committed Feb 5, 2012
1 parent 8faa4aa commit 2e9a372
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 26 deletions.
26 changes: 0 additions & 26 deletions XOmBot.rb

This file was deleted.

8 changes: 8 additions & 0 deletions bin/XOmBot
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env ruby

$: << File.dirname(__FILE__) + '/../lib'

require 'xombot'
require 'xombot/cli'

XOmBot::CLI.run
26 changes: 26 additions & 0 deletions lib/xombot.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'bundler'
Bundler.require

require 'xombot/plugins/hello'

module XOmBot
class << self
def load_plugins
end

def start
bot = Cinch::Bot.new do
configure do |c|
c.server = "irc.freenode.org"
c.port = 6697
c.ssl.use = true
c.nick = "XOmBot-test"
c.channels = ["#XOmBot"]
c.plugins.plugins = [Hello]
end
end

bot.start
end
end
end
34 changes: 34 additions & 0 deletions lib/xombot/cli.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require 'xombot'
require 'optparse'

module XOmBot
class CLI
BANNER = <<-USAGE
Usage:
Run with the default parameters:
xombot
USAGE

class << self
def parse_options
@opts = OptionParser.new do |opts|
opts.banner = BANNER.gsub(/^\s{4}/, '')

opts.separator ''
opts.separator 'Options:'

opts.on('-h', '--help', 'Display this help') do
puts opts
exit
end
end

@opts.parse!
end

def run
XOmBot.start
end
end
end
end
10 changes: 10 additions & 0 deletions lib/xombot/plugins/hello.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Hello
include Cinch::Plugin

match "hello"
help "This command says hello."

def execute(m)
m.reply "Hello, #{m.user.nick}"
end
end

0 comments on commit 2e9a372

Please sign in to comment.