Created
June 1, 2011 21:41
-
-
Save thorncp/1003398 to your computer and use it in GitHub Desktop.
See about getting this (or similar) into rubot
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
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 |
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
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