Skip to content
This repository has been archived by the owner on Apr 13, 2019. It is now read-only.

Helper methods not available from plugins? #53

Closed
stith opened this issue Nov 2, 2011 · 4 comments
Closed

Helper methods not available from plugins? #53

stith opened this issue Nov 2, 2011 · 4 comments

Comments

@stith
Copy link

stith commented Nov 2, 2011

In my bot:

helpers do
  def shutup?
    @shutup = false if @shutup_expire <= @shutup
    !!@shutup
  end 
end

And in a plugin:

m.reply @factoids[matches[2].downcase] unless @bot.shutup?

But when running I get:

factoids.rb:31:in `listen': undefined method `shutup?' for #<Cinch::Bot:0x000000028ee098> (NoMethodError)

Am I misunderstanding how helpers work or is this a bug? I thought it would define the methods in the context of the bot object?

@dominikh
Copy link
Member

dominikh commented Nov 2, 2011

helpers is only used in combination with the on syntax. Since plugins are ordinary classes, they should just include/extend modules as needed.

@stith
Copy link
Author

stith commented Nov 3, 2011

So my plugin should extend my bot? Guess it's just my lack of Ruby knowledge at this point :P

How should I be doing this if this is working as intended? There's a central value that all plugins need to be able to check, and the configuration object doesn't seem like the right place.

@dominikh
Copy link
Member

dominikh commented Nov 3, 2011

The configuration object is the right place when that "central value" is a setting that won't change during runtime. Otherwise use something like this:https://gist.github.com/88eee25a620a8bb18408

@stith
Copy link
Author

stith commented Nov 3, 2011

The value will be changing, it's a plugin to let people request that the bot shuts up for an amount of time :P The idea is we only store the value (and set it) in the Shutup plugin, but it'd be available in all of the other plugins for seeing if they should output. Shutup and shutup_expire are both values that get set to Time objects when someone says "Bot, shut up."

I'll give that module method a shot, thanks.

@dominikh dominikh closed this as completed Nov 4, 2011
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants