dominikh changed the topic of #cinch to: The IRC Framework | Latest version: Cinch 2.0.11
ColdBlooder has joined #cinch
<ColdBlooder> Hi. Anyone here?
<dominikh> Yes
<ColdBlooder> I got a little issue. After god decided to punish me and killed my PC + my backup in one go... I gotta redo my bot >-(
<ColdBlooder> So i basically got twitter to work... I can fetch the new tweets popping up in a timeline... With one tiny issue... I can't, for the love of god, get my bot to put thr tweet into the chat.
<dominikh> why not
<ColdBlooder> I wish i knew
<ColdBlooder> Here is the code http://pastebin.com/Rc23cg7F
<dominikh> that's not a valid plugin
<ColdBlooder> "puts output" does outpu the tweet correctly in the terminal. But how do i convince the bot to put it into the channel?
<dominikh> it got no connection to any bot
<ColdBlooder> huh?
<dominikh> you spawn a thread, on the class level. it will a) start before any bot business is happening b) it will not know of any bot
<dominikh> it exists on its own
<ColdBlooder> So i need to start the thread inside the bot?
<dominikh> you want something like http://sprunge.us/MFaL
<ColdBlooder> Oh so the listen_to line and the def line connect the class to the bot?
<dominikh> it's a method that gets called by the bot's event dispatcher, so yes, in a way
<dominikh> more importantly it's an instance method, and plugin instances have a reference to the bot
<ColdBlooder> Okay. Thatwas my missing piece of the puzzle.
<ColdBlooder> Still not working
<dominikh> you'll need to give me more than "not working"
<ColdBlooder> But it outputs the tweet now twice in the terminal
<ColdBlooder> Looks like its still not connecting to the bot
<dominikh> a) it says "outpout" in your send line, which is a typo b) it should very clearly raise an exception because of that c) thus it should be written very clearly in your terminal
<ColdBlooder> renamed output to thistweet nd now it works. THANKS!
<ColdBlooder> Well sry to ask again... Wanted to sleep before taking care of this but its bugging me too much. I get the tweets to appear in the chat now but they always appear twice.
<ColdBlooder> (corrected code from before -> http://pastebin.com/zcQURfVm )
robonerd is now known as robnerd
<ColdBlooder> Hello, anyone here?
robnerd is now known as robonerd
Azure has quit [Quit: My MBP went to sleep.]
txdv has quit [Quit: No Ping reply in 180 seconds.]
txdv has joined #cinch
* ColdBlooder knocks carefully to check if someones here
<ayonix> ColdBlooder: are you sure on_connect gets called only once?
<ColdBlooder> Im not sure. dominikh suggested calling the plugin this way.
<dominikh> it gets called every time the bot connects
<dominikh> will want to kill the thread on a disconnect I suppose
<ayonix> so if it loses connection and connects again it would start another thread => things get executed twice?
<dominikh> or create the thread in an overridden initialize method
<ayonix> yep, I'd try the initialize method
<ayonix> although you would probably lose some messages then
<ayonix> killing the thread on disconnection would be cleaner
<ColdBlooder> How do i check for disconnection?
<dominikh> how do you check for connect?
<ColdBlooder> listen_to :connect
<dominikh> now make an educated guess how you'd check for disconnect
<ColdBlooder> Does that work for disconnect aswell? Because thats not mentioned in the documentation?
<dominikh> that'd be a documentation bug :)
<ColdBlooder> I had that thought and checked in the docs... Didn't mention disconnection being a method, so i dismissed it...
<ColdBlooder> Thread.kill does kill the thread its called, dosen't it?
<ColdBlooder> *its called in
<ayonix> you probably want to store a reference in a variable, t = Thread.new do ... end and use t.kill when disconnecting
<ayonix> or something like that
<ayonix> @t = Thread.new ... rather
<ColdBlooder> Oh... Now it closes the obsolete thread... AFTER it double posted. I think i can fix that...
<ColdBlooder> Great. Now i either get no post or double post. If i make "y.kill" after checking for disconnect, it somehow kills both threads?
<ColdBlooder> If i kill the thread after it posted i get double post again
<ayonix> code?
<ColdBlooder> This code results in nothing happening. If i post the code for closing on discopnnection after the Channel.send command i get double posts
jmaister has joined #cinch
<jmaister> hi
<ColdBlooder> hi
<ayonix> that looks very strange
<jmaister> what's the best way to add configuration to plugins?
<jmaister> like API keys
<ColdBlooder> Dont mind the code for showing the thread count. I just added that to check of 1 or 2 weree running
<ayonix> you used listen_to :disconnection IN the on_connect method?
<ColdBlooder> Dosent it need to be in the thread to work?
<ayonix> no
<ColdBlooder> Huh? My Qbasic / Visual Basic 6 mind is blown
<ayonix> should do i guess
<ColdBlooder> @ makes a "global variable"?
<ayonix> instance variable
<ColdBlooder> Its still double posting
<ayonix> so it might be on_connect gets called twice without a disconnect in between, so two threads get started and the reference to one of them will be overridden
<ayonix> you could try the initialize version if you don't mind missed tweets
<ColdBlooder> So i can't cancel the obsolete thread?
<ayonix> you could also check if the thread is existing and running so you don't create a second one
<ColdBlooder> Would be better. Missed tweets is not an option
<ayonix> well, that won't help with that I'm afraid
<ayonix> best is to find out why two threads are getting created
<ayonix> like debug when a thread is created and debug when a thread gets killed
<ayonix> s/debug/log/
<jmaister> Hm. So about plugin options. I asked the question here http://pastebin.com/twXV4uwA
<jmaister> do you get what I'm thinking?
<jmaister> would that work?
<jmaister> I'm just not sure how to code it
Azure has joined #cinch
<jmaister> that's what I'm trying to utilize
<jmaister> But I want the options in a file instead of coded into the bot
<ayonix> it's a hash, so you could store it as yaml/json and load that as the config hash for example
<jmaister> hm
<ColdBlooder> OH
<ColdBlooder> I know why i get 2 threads from my plugin
<ColdBlooder> c.plugins.plugins = [TwitterStuff] -> 1 thread
<ColdBlooder> def on_connect(m) -> 2nd thread
<ColdBlooder> So the code you provided is basically always closing and reopening a second thread.
<ColdBlooder> (If i understood it correctly)
UberDragon has joined #cinch
<ayonix> So?
<ayonix> Yes there should be two threads running. one for the connect method and the one you're starting
<jmaister> ayonix: So, I've gotten a bit further, but it doesn't quite work
<jmaister> according to what I've tried in irb this should work http://pastebin.com/BwziLswR
<jmaister> but config is empty in the plugin
<ColdBlooder> ayonix: Both threads react to the twitter stream. Thats the issue with both threads. Thats why i get double posts. I only need 1 thread.
<ayonix> ColdBlooder: that should not be the case
<ColdBlooder> But thats happening. IF i completely disable the "listen_to" and "on connect" lines i can output the tweets vis "puts" command just fine. So theres a thread already active before the bot even connects
rikai has quit [Ping timeout: 264 seconds]
<ayonix> okay
xeviox|afk is now known as xeviox
<ColdBlooder> I FIXED IT!!! Yes!! finally!!!
<Netfeed> yay?
<Netfeed> what was the problem?
<ColdBlooder> I just used the :connect method inside the bot "on :connect" and create tge thread in there.
<ColdBlooder> End result: 1 thread and no double posts
txdv has quit [Ping timeout: 272 seconds]
<ayonix> where's the difference to my proposed solution?
kith has quit [Ping timeout: 252 seconds]
txdv has joined #cinch
<ColdBlooder> Im creating the thread without a class.
<ColdBlooder> wait...
<ColdBlooder> This is working: http://pastebin.com/UKEZ0Y7T
<ColdBlooder> No class, just letrting the bot do the thread when it connects
<ColdBlooder> *letting
<ColdBlooder> Forgot to remove al the stuff i should... Oh well
<ColdBlooder> Its getting deleted tomorrow
<ColdBlooder> Or in one hour
kith has joined #cinch
<ayonix> So if the bot loses its connection it will send stuff twice and you might miss tweets when the bot loses connection
<ColdBlooder> On disconnect i kill the thread
<ColdBlooder> Forgot to copy it
<ColdBlooder> Its basically the same approach just outside of a class
<ayonix> weird
<ColdBlooder> But it works
Azure has quit [Ping timeout: 260 seconds]
postmodern has joined #cinch
ColdBlooder has quit [Remote host closed the connection]
xeviox is now known as xeviox|afk
rikai has joined #cinch