From 34789c960f3122e8d5dee62b2fe3f6be3a268211 Mon Sep 17 00:00:00 2001 From: SirSkidmore Date: Sun, 6 Jan 2013 14:27:17 -0600 Subject: [PATCH 1/4] Moving bot out of Rakefile/rm Gemfile --- Gemfile | 7 ------- Rakefile | 45 --------------------------------------------- lib/percival.rb | 1 + percival.gemspec | 20 -------------------- 4 files changed, 1 insertion(+), 72 deletions(-) delete mode 100644 Gemfile delete mode 100644 Rakefile delete mode 100644 percival.gemspec diff --git a/Gemfile b/Gemfile deleted file mode 100644 index 30369fe..0000000 --- a/Gemfile +++ /dev/null @@ -1,7 +0,0 @@ -source 'http://rubygems.org' - -gem 'rspec' -gem 'pry' - -# Specify your gem's dependencies in percival.gemspec -gemspec diff --git a/Rakefile b/Rakefile deleted file mode 100644 index ef10124..0000000 --- a/Rakefile +++ /dev/null @@ -1,45 +0,0 @@ -require 'rubygems' -require 'bundler/setup' -require 'bundler/gem_tasks' -require 'rspec/core/rake_task' - -task :default => :spec - -desc "Run specs" -RSpec::Core::RakeTask.new do |task| - task.rspec_opts = ["-c", "-f progress"] -end - - -task :c => :console -desc "start up a irb console" -task :console do - system 'bundle exec pry' -end - - -desc "start percival, connect to all channels in the CHANNELS env var" -task :start do - system 'mkdir -p data/timesheets/' - system 'mkdir -p data/quotelists/' - channels = ENV["CHANNELS"] && ENV["CHANNELS"].split(/,\s*/) || ["#lpmc-bot"] - nick = ENV["NICK"] || "percival" - server = 'irc.freenode.com' - - require 'percival' - - bot = Cinch::Bot.new do - configure do |c| - c.server = server - c.channels = channels - c.nick = nick - c.plugins.plugins = [ClockPlugin, - LoggerPlugin, - ChannelChangerPlugin, - NameChangerPlugin, - QuotePlugin] - end - end - - bot.start -end diff --git a/lib/percival.rb b/lib/percival.rb index 91b7bad..740a5d8 100644 --- a/lib/percival.rb +++ b/lib/percival.rb @@ -6,6 +6,7 @@ require 'percival/channel_changer' require 'percival/name_changer' require 'percival/quote' +require 'percival/guessing_game' PERCIVAL_ROOT = File.dirname(File.dirname(__FILE__)) diff --git a/percival.gemspec b/percival.gemspec deleted file mode 100644 index 1832be5..0000000 --- a/percival.gemspec +++ /dev/null @@ -1,20 +0,0 @@ -# -*- encoding: utf-8 -*- -require File.expand_path('../lib/percival/version', __FILE__) - -Gem::Specification.new do |gem| - gem.authors = ["Joe Fredette"] - gem.email = ["jfredett@gmail.com"] - gem.description = %q{A IRC bot for the vermonster team.} - gem.summary = %q{A IRC bot for the vermonster team.} - gem.homepage = "" - - gem.add_dependency "cinch" - gem.add_dependency "rake" - - gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } - gem.files = `git ls-files`.split("\n") - gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") - gem.name = "percival" - gem.require_paths = ["lib"] - gem.version = Percival::VERSION -end From edcb0b85c0d79e03a633dc104d480b5686fa0f9c Mon Sep 17 00:00:00 2001 From: SirSkidmore Date: Sun, 6 Jan 2013 14:29:00 -0600 Subject: [PATCH 2/4] Created bot.rb --- bot.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100755 bot.rb diff --git a/bot.rb b/bot.rb new file mode 100755 index 0000000..c430e3e --- /dev/null +++ b/bot.rb @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby + +require 'rubygems' +require 'cinch' + +bot = Cinch::Bot.new do + configure do |c| + c.server = 'irc.freenode.net' + c.channels = ['#lpmc-bot'] + c.nick = 'percival' + c.plugins.plugins = [] + end +end + +bot.start From fc1f6ebed86ac0331d46ce3132148ee076f1b3bb Mon Sep 17 00:00:00 2001 From: SirSkidmore Date: Sun, 6 Jan 2013 14:36:13 -0600 Subject: [PATCH 3/4] Cleaned up plugins (starting over) --- lib/percival.rb | 9 --- lib/percival/channel_changer.rb | 2 - lib/percival/channel_changer/plugin.rb | 27 ------- lib/percival/channel_changer/user_role.rb | 13 --- lib/percival/clock.rb | 5 -- lib/percival/clock/clock.rb | 21 ----- lib/percival/clock/plugin.rb | 21 ----- lib/percival/clock/tick.rb | 39 --------- lib/percival/clock/timesheet.rb | 68 ---------------- lib/percival/logger.rb | 2 - lib/percival/logger/logger.rb | 27 ------- lib/percival/logger/plugin.rb | 29 ------- lib/percival/name_changer.rb | 1 - lib/percival/name_changer/plugin.rb | 11 --- lib/percival/quote.rb | 2 - lib/percival/quote/plugin.rb | 25 ------ lib/percival/quote/quotelist.rb | 40 --------- lib/percival/version.rb | 3 - spec/clock_plugin_spec.rb | 98 ----------------------- spec/clock_spec.rb | 71 ---------------- spec/logger_spec.rb | 6 -- spec/spec_helper.rb | 5 -- spec/support/irc_faker.rb | 33 -------- spec/tick_spec.rb | 56 ------------- spec/timesheet_spec.rb | 50 ------------ 25 files changed, 664 deletions(-) delete mode 100644 lib/percival/channel_changer.rb delete mode 100644 lib/percival/channel_changer/plugin.rb delete mode 100644 lib/percival/channel_changer/user_role.rb delete mode 100644 lib/percival/clock.rb delete mode 100644 lib/percival/clock/clock.rb delete mode 100644 lib/percival/clock/plugin.rb delete mode 100644 lib/percival/clock/tick.rb delete mode 100644 lib/percival/clock/timesheet.rb delete mode 100644 lib/percival/logger.rb delete mode 100644 lib/percival/logger/logger.rb delete mode 100644 lib/percival/logger/plugin.rb delete mode 100644 lib/percival/name_changer.rb delete mode 100644 lib/percival/name_changer/plugin.rb delete mode 100644 lib/percival/quote.rb delete mode 100644 lib/percival/quote/plugin.rb delete mode 100644 lib/percival/quote/quotelist.rb delete mode 100644 lib/percival/version.rb delete mode 100644 spec/clock_plugin_spec.rb delete mode 100644 spec/clock_spec.rb delete mode 100644 spec/logger_spec.rb delete mode 100644 spec/spec_helper.rb delete mode 100644 spec/support/irc_faker.rb delete mode 100644 spec/tick_spec.rb delete mode 100644 spec/timesheet_spec.rb diff --git a/lib/percival.rb b/lib/percival.rb index 740a5d8..ccac833 100644 --- a/lib/percival.rb +++ b/lib/percival.rb @@ -1,12 +1,3 @@ require 'cinch' -require 'percival/version' -require 'percival/clock' -require 'percival/logger' -require 'percival/channel_changer' -require 'percival/name_changer' -require 'percival/quote' -require 'percival/guessing_game' - PERCIVAL_ROOT = File.dirname(File.dirname(__FILE__)) - diff --git a/lib/percival/channel_changer.rb b/lib/percival/channel_changer.rb deleted file mode 100644 index a18b165..0000000 --- a/lib/percival/channel_changer.rb +++ /dev/null @@ -1,2 +0,0 @@ -require 'percival/channel_changer/plugin' -require 'percival/channel_changer/user_role' diff --git a/lib/percival/channel_changer/plugin.rb b/lib/percival/channel_changer/plugin.rb deleted file mode 100644 index 0ab4dca..0000000 --- a/lib/percival/channel_changer/plugin.rb +++ /dev/null @@ -1,27 +0,0 @@ - -class ChannelChangerPlugin - include Cinch::Plugin - - match /join-channel\s+(\S+)/, :method => :join - match /leave-channel(?:\s+(\S+))?/, :method => :leave - - listen_to :error, method: :error - - def error irc - debug( irc.to_s ) - end - - def leave( irc, channel ) - if UserRole.approved? irc.user, :channel_changer - channel ||= irc.channel - Channel(channel).part - end - end - - def join( irc, channel ) - Channel(channel).join() if UserRole.approved? irc.user, :channel_changer - end -end - - - diff --git a/lib/percival/channel_changer/user_role.rb b/lib/percival/channel_changer/user_role.rb deleted file mode 100644 index 3073b0c..0000000 --- a/lib/percival/channel_changer/user_role.rb +++ /dev/null @@ -1,13 +0,0 @@ -class UserRole - @test_users = ["colwem", "jfredett"] - @roles = { - super_user: @test_users, - channel_changer: @test_users, - name_changer: @test_users} - - def self.approved?(user, role) - user = user.name if user.is_a? Cinch::User - raise "user not in String, Cinch::User" unless user.is_a? String - @roles[role].include? user - end -end diff --git a/lib/percival/clock.rb b/lib/percival/clock.rb deleted file mode 100644 index ca2bdcc..0000000 --- a/lib/percival/clock.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'percival/clock/tick' -require 'percival/clock/timesheet' -require 'percival/clock/clock' -require 'percival/clock/plugin' - diff --git a/lib/percival/clock/clock.rb b/lib/percival/clock/clock.rb deleted file mode 100644 index bc17070..0000000 --- a/lib/percival/clock/clock.rb +++ /dev/null @@ -1,21 +0,0 @@ -class Clock - def for(username) - (timesheet_manager.for(username) || []).sort - end - - def clock_in(username) - timesheet_manager.entry(username, :in) - end - - def clock_out(username) - timesheet_manager.entry(username, :out) - end - - def initialize(timesheet_manager = Timesheet) - @timesheet_manager = timesheet_manager - end - - private - - attr_reader :timesheet_manager -end diff --git a/lib/percival/clock/plugin.rb b/lib/percival/clock/plugin.rb deleted file mode 100644 index d01fee9..0000000 --- a/lib/percival/clock/plugin.rb +++ /dev/null @@ -1,21 +0,0 @@ -class ClockPlugin - include Cinch::Plugin - - match /clock (.+)/ - - def execute(irc, status) - begin - case status - when "in" - Clock.new.clock_in(irc.user) - when "out" - Clock.new.clock_out(irc.user) - else - irc.reply "USAGE: !clock " - end - rescue InvalidTimesheetSequence - irc.reply "You are already clocked #{status}." - end - end - -end diff --git a/lib/percival/clock/tick.rb b/lib/percival/clock/tick.rb deleted file mode 100644 index 9e14377..0000000 --- a/lib/percival/clock/tick.rb +++ /dev/null @@ -1,39 +0,0 @@ -require 'yaml' -class Tick - include Comparable - - def self.in - new(Time.now, :in) - end - - def self.out - new(Time.now, :out) - end - - def self.parse(s) - YAML::load(s) - end - alias_method :dump, :to_yaml - - def to_s - "#{time} #{type}" - end - alias_method :inspect, :to_s - - def ==(other) - self.dump == other.dump - end - - def <=>(other) - time <=> other.send(:time) #a little bit cheaty - end - - def initialize(time, type) - @time = time - @type = type - end - - private - - attr_accessor :time, :type -end diff --git a/lib/percival/clock/timesheet.rb b/lib/percival/clock/timesheet.rb deleted file mode 100644 index 0e57f61..0000000 --- a/lib/percival/clock/timesheet.rb +++ /dev/null @@ -1,68 +0,0 @@ -class Timesheet - def self.entry(user, type, reader=File) - raise "Reader dependency must respond to #open" unless reader.respond_to? :open - raise "Reader dependency must respond to #read" unless reader.respond_to? :read - raise "Reader dependency must respond to #exists?" unless reader.respond_to? :exists? - - new(user, reader).clock(type) - end - - def clock(type) - raise InvalidTimesheetSequence if type == previous_type - write_to_timesheet(Tick.send(type).dump) - end - - - - private - - attr_accessor :user, :reader - - def initialize(user, reader) - @user = user - @reader = reader - end - - def write_to_timesheet(string) - reader.open(timesheet_path, 'a') do |f| - f << string - f << "\n" - end - self - end - - def timesheet_data - raw_data = reader.read(timesheet_path) if reader.exists?(timesheet_path) - return [] unless raw_data - - entries = [] - entry = "" - raw_data.each_line do |line| - if line =~ /^\s*$/ - entries << YAML.load(entry) - entry = "" - else - entry << line - end - end - - entries - end - - def previous_type - last_entry = (timesheet_data || []).sort.last - #another minor hack -- I want a "only other instances of myself need to - #access this for comparison purposes" protection level. - last_entry.send(:type) if last_entry - end - - def timesheet_path - PERCIVAL_ROOT + path_to_timesheets + user.to_s - end - - def path_to_timesheets - "/data/timesheets/" - end -end - -class InvalidTimesheetSequence < Exception ; end diff --git a/lib/percival/logger.rb b/lib/percival/logger.rb deleted file mode 100644 index 7280171..0000000 --- a/lib/percival/logger.rb +++ /dev/null @@ -1,2 +0,0 @@ -require 'percival/logger/logger' -require 'percival/logger/plugin' diff --git a/lib/percival/logger/logger.rb b/lib/percival/logger/logger.rb deleted file mode 100644 index bf14262..0000000 --- a/lib/percival/logger/logger.rb +++ /dev/null @@ -1,27 +0,0 @@ -require 'singleton' -require 'forwardable' -class Logger - extend Forwardable - - def initialize - #since we're keeping a persistent connection, we need - #to remember to close the file when the object dies. - ObjectSpace.define_finalizer(self, proc { flush ; close }) - end - - delegate [:flush, :close] => :file - - def log(user, message, event) - file << "%s | %8s | %s: %s\n" % [iso_standard_time, event, user, message] - end - - private - - def file - @file ||= File.open(PERCIVAL_ROOT + '/data/log', 'a') - end - - def iso_standard_time - Time.now.strftime("%F %T") - end -end diff --git a/lib/percival/logger/plugin.rb b/lib/percival/logger/plugin.rb deleted file mode 100644 index 9d18f9c..0000000 --- a/lib/percival/logger/plugin.rb +++ /dev/null @@ -1,29 +0,0 @@ -require 'forwardable' -class LoggerPlugin - include Cinch::Plugin - extend Forwardable - - listen_to( - :join, :leaving, - :message, - :op, :deop, :halfop, :dehalfop, :owner, :deowner, - :ban, :unban, - :kick, - :away, :unaway, - :voice, :devoice - ) - - timer 15, method: :flush - - def listen(irc, *_) - log(irc.user, irc.message, irc.command) - end - - private - - delegate [:flush, :log] => :logger - - def logger - @logger ||= Logger.new - end -end diff --git a/lib/percival/name_changer.rb b/lib/percival/name_changer.rb deleted file mode 100644 index 14e339f..0000000 --- a/lib/percival/name_changer.rb +++ /dev/null @@ -1 +0,0 @@ -require 'percival/name_changer/plugin' diff --git a/lib/percival/name_changer/plugin.rb b/lib/percival/name_changer/plugin.rb deleted file mode 100644 index c70c956..0000000 --- a/lib/percival/name_changer/plugin.rb +++ /dev/null @@ -1,11 +0,0 @@ -class NameChangerPlugin - include Cinch::Plugin - - match /change-name\s+(\S+)/, :method => :change_name - - def change_name( irc, name ) - if UserRole.approved? irc.user, :name_changer - bot.nick = name - end - end -end diff --git a/lib/percival/quote.rb b/lib/percival/quote.rb deleted file mode 100644 index aff2a81..0000000 --- a/lib/percival/quote.rb +++ /dev/null @@ -1,2 +0,0 @@ -require 'percival/quote/quotelist' -require 'percival/quote/plugin' diff --git a/lib/percival/quote/plugin.rb b/lib/percival/quote/plugin.rb deleted file mode 100644 index 227d7fa..0000000 --- a/lib/percival/quote/plugin.rb +++ /dev/null @@ -1,25 +0,0 @@ -class QuotePlugin - include Cinch::Plugin - - match /quote (\w+) (.+)/, { :method => :record } - match /quote\s*$/, { :method => :random } - match /quote-by (\w+)/, { :method => :quote_by } - - def record(irc, user, quote) - Quotelist.record(user, quote) - irc.reply "Quote recorded for user " + user - end - - def random(irc) - irc.reply Quotelist.get_random_quote - end - - def quote_by(irc, user) - begin - irc.reply(Quotelist.get_quote_by user) - rescue Errno::ENOENT - irc.reply "No quotes from that user yet" - end - end - -end diff --git a/lib/percival/quote/quotelist.rb b/lib/percival/quote/quotelist.rb deleted file mode 100644 index bef2efb..0000000 --- a/lib/percival/quote/quotelist.rb +++ /dev/null @@ -1,40 +0,0 @@ -class Quotelist - def self.record(user, quote, reader=File) - self.check_reader_validity(reader) - reader.open(quotelist_path(user), 'a') do |f| - f << quote + "\n" - end - end - - def self.random_quote - file = Dir.glob(PERCIVAL_ROOT + path_to_quotelists + '*').sample - raise "No QuoteFiles found" if file.nil? - random_line file - end - - def self.quote_by(user) - random_line(quotelist_path user) - end - - private - - def self.random_line(file) - File.readlines(file).sample - end - - def self.quotelist_path(user) - PERCIVAL_ROOT + path_to_quotelists + user.to_s - end - - def self.path_to_quotelists - "/data/quotelists/" - end - - def self.check_reader_validity(reader) - raise "Reader dependency must respond to #open" unless reader.respond_to? :open - raise "Reader dependency must respond to #read" unless reader.respond_to? :read - raise "Reader dependency must respond to #exists?" unless reader.respond_to? :exists? - end - -end - diff --git a/lib/percival/version.rb b/lib/percival/version.rb deleted file mode 100644 index f0e658b..0000000 --- a/lib/percival/version.rb +++ /dev/null @@ -1,3 +0,0 @@ -module Percival - VERSION = "0.0.1" -end diff --git a/spec/clock_plugin_spec.rb b/spec/clock_plugin_spec.rb deleted file mode 100644 index 5e1cbe7..0000000 --- a/spec/clock_plugin_spec.rb +++ /dev/null @@ -1,98 +0,0 @@ -require 'spec_helper' - - -describe "The Clock plugin" do - let(:channel) do - IrcFaker.new(cinch_mock) - end - - let(:cinch_mock) do - mock(:cinch).tap do |m| - m.stub!(:reply) - m.stub!(:user).and_return('test_user') - end - end - - let(:plugin_instance) do - #This is f'd because Cinch is stupid, it requires some sort of phantom argument - #to the initializer, which is braindead. - ClockPlugin.new(mock('cinch_pleaser').as_null_object) - end - - context "Using the !clock command to clock in and out" do - subject { Clock.any_instance } - - it "allows me to clock in by sending the message `!clock in` to the channel" do - subject.should_receive(:clock_in).with('test_user') - channel. - plugins(plugin_instance). - send_message("!clock in"). - as("test_user"). - run! - end - - it "allows me to clock out by sending the message `!clock out` to the channel" do - subject.should_receive(:clock_out).with('test_user') - - channel. - plugins(plugin_instance). - send_message("!clock out"). - as("test_user"). - run! - end - - it "tells me the command usage information if I pass an incorrect subcommand" do - cinch_mock.should_receive(:reply).with("USAGE: !clock ") - - channel. - plugins(plugin_instance). - send_message("!clock WRONG"). - as("test_user"). - run! - end - end - - context "The class itself" do - describe "instance methods" do - - subject { plugin_instance } - - pending ":: waiting for design" do - it "allows for review and editing of times for a given day" - - it "messages you if your time is out of the ordinary via email" - end - - - it { should respond_to :execute } - describe "#execute(m, type)" do - it "takes at least two arguments for execute" do - expect { subject.execute(cinch_mock, "subcommand") }.to_not raise_error - end - - it "should clock you in when you pass it the type 'in'" do - Clock.any_instance.should_receive(:clock_in).with('test_user') - subject.execute(cinch_mock, 'in') - end - - it "should clock you out when you pass it the type 'out'" do - Clock.any_instance.should_receive(:clock_out).with('test_user') - subject.execute(cinch_mock, 'out') - end - - it "should respond with a usage message if you try to use an invalid type" do - cinch_mock.should_receive(:reply).with("USAGE: !clock ") - subject.execute(cinch_mock, 'flurble') - end - end - end - - describe "class level constraints" do - subject { ClockPlugin } - - #Cinch doesn't open up much in the way of "respond to !clock command", but it - #should be tested - its(:included_modules) { should include(Cinch::Plugin) } - end - end -end diff --git a/spec/clock_spec.rb b/spec/clock_spec.rb deleted file mode 100644 index 6aaf188..0000000 --- a/spec/clock_spec.rb +++ /dev/null @@ -1,71 +0,0 @@ -require 'spec_helper' - -describe Clock do - let(:cinch_mock) { - mock(:cinch).tap do |m| - m.stub!(:reply) - end - } - - let(:timesheet) { - mock("timesheet class").tap { |t| - t.as_null_object - t.stub!(:entry) - t.stub!(:for) - } - } - - subject { Clock.new(timesheet) } - - it { should respond_to :clock_in } - describe "#clock_in" do - it "takes a username as an argument" do - expect { subject.clock_in("test_username") }.to_not raise_error - end - - it "should create a tick on the user's timesheet" do - timesheet. - should_receive(:entry). - with('test_user', :in) - - subject.clock_in('test_user') - end - end - - it { should respond_to :clock_out } - describe "#clock_out" do - it "takes a username as an argument" do - expect { subject.clock_out("test_username") }.to_not raise_error - end - - it "should create a tick on the user's timesheet" do - timesheet. - should_receive(:entry). - with('test_user', :out) - subject.clock_out('test_user') - end - end - - - describe "#for(user)" do - it "takes a single user as an argument" do - expect { subject.for("foo") }.to_not raise_error - end - - it "should return an empty list if no ticks are present" do - timesheet.should_receive(:for).with('foo').and_return([]) - subject.for("foo").should == [] - end - - it "returns all the clock-tick objects for a given user" do - timesheet.should_receive(:for).with('test_user') - subject.for('test_user') - end - - it "returns the tick object in chronological order" do - fake_times = [Tick.new(Time.now + 60, :out), Tick.new(Time.now - 60, :in)] - timesheet.should_receive(:for).with('test_user').and_return(fake_times) - subject.for('test_user').should == fake_times.reverse #the above times are in reverse order - end - end -end diff --git a/spec/logger_spec.rb b/spec/logger_spec.rb deleted file mode 100644 index 1ebdc96..0000000 --- a/spec/logger_spec.rb +++ /dev/null @@ -1,6 +0,0 @@ -require 'spec_helper' - -describe Logger do - -end - diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb deleted file mode 100644 index 185e05e..0000000 --- a/spec/spec_helper.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rspec' - -require './lib/percival' - -require './spec/support/irc_faker' diff --git a/spec/support/irc_faker.rb b/spec/support/irc_faker.rb deleted file mode 100644 index f72a491..0000000 --- a/spec/support/irc_faker.rb +++ /dev/null @@ -1,33 +0,0 @@ -class IrcFaker - def initialize(irc_mock) - @irc_mock = irc_mock - @expectation = {} - end - - def plugins(*plugins) - @plugins = plugins - self - end - - def send_message(msg) - msg_params = msg.gsub(/^!/,'').split(' ') - @command = msg_params.first.capitalize #this could be turned into the class... - msg_params.shift - @message_args = msg_params - self - end - - def as(sender) - @sender = sender - self - end - - def run! - @irc_mock.stub!(:user).and_return(@sender) #a sort of lo-fi mock of the Cinch "user" object - @irc_mock.stub!(:reply) # ignore outgoing replies - @plugins.each do |plugin| - plugin.execute(@irc_mock, *@message_args) - end - nil - end -end diff --git a/spec/tick_spec.rb b/spec/tick_spec.rb deleted file mode 100644 index 8323e84..0000000 --- a/spec/tick_spec.rb +++ /dev/null @@ -1,56 +0,0 @@ -require 'spec_helper' - -describe Tick do - subject { Tick.in } - - describe "==" do - it { should == subject } - - it "should equal an equivalent tick" do - time = Time.now - Tick.new(time, :in).should == Tick.new(time, :in) - end - - it "should not be equal to a tick of a different type" do - Tick.in.should_not == Tick.out - end - - it "should not be equal to a tick of the same type with a different time" do - tick1 = Tick.in - tick2 = Tick.new(Time.now + 1, :in) - tick1.should_not == tick2 - end - end - - describe "<=>" do - it "determines inequality by timestamp" do - Tick.new(Time.now + 50, :in).should be > Tick.new(Time.now - 50, :out) - end - end -end - -describe Tick do #class methods - subject { Tick } - - describe ".parse" do - it "is the inverse of #dump" do - tick = Tick.in - Tick.parse(tick.dump).should == tick - - tick = Tick.out - Tick.parse(tick.dump).should == tick - end - end - - describe ".in" do - it "takes no arguments" do - expect { subject.in }.to_not raise_error - end - end - - describe ".out" do - it "takes no arguments" do - expect { subject.out }.to_not raise_error - end - end -end diff --git a/spec/timesheet_spec.rb b/spec/timesheet_spec.rb deleted file mode 100644 index f891d3b..0000000 --- a/spec/timesheet_spec.rb +++ /dev/null @@ -1,50 +0,0 @@ -require 'spec_helper' - -describe Timesheet do #class methods - subject { Timesheet } - - let(:reader) { mock("reader").tap { |r| r.stub!(:open) ; r.stub!(:read) ; r.stub!(:exists?).and_return(true) } } - let(:invalid_reader) { mock("invalid reader") } - - it { should respond_to :entry } - describe "#entry" do - it "should take a username and a tick-type as an argument to .entry" do - expect { subject.entry('test_user', :in, reader) }.to_not raise_error - expect { subject.entry('test_user', :out, reader) }.to_not raise_error - end - - it "optionally expects a dependency which responds to #open and #read" do - expect { subject.entry('test', :in, reader) }.to_not raise_error - expect { subject.entry('test', :in, invalid_reader) }.to raise_error - end - - it "should throw an error if you try to make the same entry type twice in a row" do - fake_data_after_clockin =<<-HERE ---- !ruby/object:Tick -time: 2011-12-06 08:19:22.174495000 -05:00 -type: :out - ---- !ruby/object:Tick -time: 2011-12-06 08:23:00.546090000 -05:00 -type: :in - - HERE - - expect do - reader.should_receive(:read).with(anything).and_return(fake_data_after_clockin) - reader.stub(:read).and_return(fake_data_after_clockin) - - subject.entry('test', :in, reader) - end.to raise_error InvalidTimesheetSequence - end - end - - describe "#clock" do - it "should write the tick to the user's timesheet" do - reader.should_receive(:open).with(PERCIVAL_ROOT + '/data/timesheets/test', 'a') - - subject.entry('test', :in, reader) # this feels a little wrong, it calls clock internally - end - end -end - From 99121dbbde8a53c62f6312ac6ae4085b9ccea13f Mon Sep 17 00:00:00 2001 From: SirSkidmore Date: Sun, 6 Jan 2013 15:15:18 -0600 Subject: [PATCH 4/4] adding sample hello command --- bot.rb | 4 ++-- lib/percival.rb | 2 ++ lib/percival/commands.rb | 1 + lib/percival/commands/hello.rb | 9 +++++++++ 4 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 lib/percival/commands.rb create mode 100644 lib/percival/commands/hello.rb diff --git a/bot.rb b/bot.rb index c430e3e..28ec7df 100755 --- a/bot.rb +++ b/bot.rb @@ -1,14 +1,14 @@ #!/usr/bin/env ruby require 'rubygems' -require 'cinch' +require File.expand_path('../lib/percival', __FILE__) bot = Cinch::Bot.new do configure do |c| c.server = 'irc.freenode.net' c.channels = ['#lpmc-bot'] c.nick = 'percival' - c.plugins.plugins = [] + c.plugins.plugins = [Hello] end end diff --git a/lib/percival.rb b/lib/percival.rb index ccac833..6d7f9f6 100644 --- a/lib/percival.rb +++ b/lib/percival.rb @@ -1,3 +1,5 @@ require 'cinch' +require File.expand_path('../percival/commands/hello.rb', __FILE__) + PERCIVAL_ROOT = File.dirname(File.dirname(__FILE__)) diff --git a/lib/percival/commands.rb b/lib/percival/commands.rb new file mode 100644 index 0000000..6b0eba6 --- /dev/null +++ b/lib/percival/commands.rb @@ -0,0 +1 @@ +require 'percival/commands/hello' diff --git a/lib/percival/commands/hello.rb b/lib/percival/commands/hello.rb new file mode 100644 index 0000000..c659069 --- /dev/null +++ b/lib/percival/commands/hello.rb @@ -0,0 +1,9 @@ +class Hello + include Cinch::Plugin + + match "hello" + + def execute(m) + m.reply "Hello, #{m.user.nick}" + end +end