Skip to content

Instantly share code, notes, and snippets.

@thorncp
Created June 1, 2011 21:41
Show Gist options
  • Save thorncp/1003398 to your computer and use it in GitHub Desktop.
Save thorncp/1003398 to your computer and use it in GitHub Desktop.
See about getting this (or similar) into rubot
class DerpController < VariableController
controller_variable :derp_con
command :con, :protected => true do
if message.text.empty?
reply derp_con
else
self.derp_con = message.text
end
end
channel_variable :derp_chan
command :chan, :protected => true do
if message.text.empty?
reply derp_chan
else
self.derp_chan = message.text
end
end
end
class VariableController < Rubot::Controller
def self.controller_variables(*vars)
vars.each do |var|
define_method(var) { convars[var] }
define_method("#{var}=") { |value| convars[var] = value }
end
end
def self.channel_variables(*vars)
vars.each do |var|
define_method(var) { chavars[message.to][var] }
define_method("#{var}=") { |value| chavars[message.to][var] = value }
end
end
class << self
alias_method :controller_variable, :controller_variables
alias_method :channel_variable, :channel_variables
end
private
def self.convars
@convars ||= {}
end
def convars
self.class.convars
end
def self.chavars
@chavars ||= Hash.new { |h,k| h[k] = {} }
end
def chavars
self.class.chavars
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment