mispy-archive / twitter_ebooks

Better twitterbots for all your friends~
MIT License
972 stars 140 forks source link

I'm too stupid to make my bot tweet #111

Open LoosGuccreen opened 8 years ago

LoosGuccreen commented 8 years ago

(EDIT: I'm also too stupid to write a title correctly, apparently)

Let's get it straight: this is not a bug, I am just stupid.

I managed to setup my bot (great!), launch it (he answers to dm and stuff), make it tweet manually using ebooks tweet <path> <bot_name>, no problem with that.

But, unless I'm impatient, brain damaged or something, I cannot manage to have the bot tweet custom message every defined time. I know how to make him do something regularly as the script shows an example using scheduler.every '30m' do #stuff end, but I just can't find how to make him tweet custom tweets (and not fixed tweets like tweet('fixed text').

So this is my question: What is the method I'm supposed to use to make my bot tweet regular ebooks message ? I'm definitely not a pro Ruby user (although I know object oriented languages paradigm). I've seen on some users something like tweet(model.make_statement) but I have an error when I try to launch the bot with this statement (he tells me model is not defined or something).

I don't really want to understand the whole program (which seems to be really good overall), just having the good keyword would be really appreciable, thanks a lot ! (and of course, sorry for the annoyance)

negatendo commented 8 years ago

The behaviors here might help: https://github.com/BooDoo/ebooks_example

Check out when the model path is set here: https://github.com/BooDoo/ebooks_example/blob/master/bots.rb#L68

... and used to tweet here: https://github.com/BooDoo/ebooks_example/blob/master/bots.rb#L104

My guess is that you did not set "model" to the path to your model, but those behaviors might have other helpful stuff for you too.

LoosGuccreen commented 8 years ago

Ok, so first, thanks for your help. I tried a bit what you suggested and added a line in the def configure part showing more or less @model=Ebooks::Model.load(<path>) and to insert the model.make_statement where I'd like him to be, but I get this error:

bots.rb:33:in 'on_startup': undefined local variable or method 'model' for #<MyBot:0xf53958> (NameError)
         from /var/lib/gems/2.1.0/gems/twitter_ebooks-3.1.6/lib/twitter_ebooks/bot.rb:373:in 'fire'
         from /var/lib/gems/2.1.0/gems/twitter_ebooks-3.1.6/lib/twitter_ebooks/bot.rb:355:in 'prepare'
         from /var/lib/gems/2.1.0/gems/twitter_ebooks-3.1.6/bin/ebooks:337:in `block (2 levels) in start'

however, I can actually get him to tweet by defining model into eatch method (which is obviously a really bad way to do it), example here on the dm part

  def on_message(dm)
     model= Ebooks::Model.load("model/loos_ebooks.model")
     reply(dm,model.make_response(dm.text))
  end

To be honest, an easy solution would be perfect for me. I tried to implement boodoo's ebooks_example, but I get a shit ton of errors (since I don't want to use Heroku)

negatendo commented 8 years ago

Yea you are very close. It seems the scope of the model variable is such that it's not available to your function. Somewhere you need to declare model in such a way that it's made available to your functions. It's hard to say what's going wrong without looking at your code, but read up a little on Ruby variable scope and I think you'll find your answer. You can do it! Also have you checked out this example code? It might be less convoluted than boodoo's. https://github.com/mispy/ebooks_example