RISCfuture / autumn

Easy, fresh, feature-rich IRC bots in Ruby
222 stars 33 forks source link

Sending /MODE and /KICK commands and working with Services #28

Closed alolis closed 13 years ago

alolis commented 13 years ago

Hello,

I have been going through the code and i am trying to find out how to send a /COMMAND to the server.

For example i wanna send /KICK user #channel MESSAGE but I am not sure how. Same goes for /MODE

Also, whats the best way to interact with services? For example i would like to run a /chanserv access #channel list command. Would it be with privmsg or is there a better way?

RISCfuture commented 13 years ago

The high-level way of sending commands is via the StemFacade mixin. This mixin adds high-level commands to your Stem that let you easily work with IRC commands. For example, if you wanted to grant a usermode, you can use the grant_usermode method:


def make_me_invisible_command(stem, sender, reply_to, msg)
  stem.grant_usermode sender, :invisible
end

For directly sending IRC commands, the Stem model uses method_missing to convert methods into IRC commands:


def make_me_invisible_command(stem, sender, reply_to, msg)
  stem.mode sender, '+i'
end
alolis commented 13 years ago

Ah very nice! Thanks :)

And how about that other question regarding the /chanserv access #CHANNEL LIST ?

RISCfuture commented 13 years ago

Yes, just use privmsg.

stem.message "access #channel list", 'ChanServ'

alolis commented 13 years ago

thanks a lot :)

alolis commented 13 years ago

I am trying to use what you said above and i am doing the following:

access_list = stem.privmsg('ChanServ', "access #{channel} list")

But the results aren't returned within access_list but I do see them in the console. Am i forgetting something?

RISCfuture commented 13 years ago

Autumn is event-driven, not procedural, to ensure that bots never lock up waiting for a response. To receive a response from ChanServ you have to override did_receive_private_message and record your response there.

alolis commented 13 years ago

Hm i understand, but this makes interaction with services a bit hard....

For example inside a command i need to get the access list and based on that list to make actions within that command. Jumping around through events will make it very hard to do so.

Any suggestions?

Also, are you sure its did_receive_private_message, cause it's not triggering. Neither does did_receive_notice (ChanServ returns results in notice i think).

RISCfuture commented 13 years ago

You can't, inside a command, send an IRC message and wait for a response. That's not allowed in the event-driven programming paradigm used by Autumn. Your best bet is to do something like this: When receiving a command, push the pending command to some sort of global queue object. In your did_receive_* method, look for a queued command whose parameters match those of the message you just received. Then, finish processing that command.

The list of did_receive_* methods are at https://github.com/RISCfuture/autumn/wiki/Autumn-methods -- if that doesn't fit your needs, you could also override the more low-level (Stem-level) irc_*_event messages (such as irc_notice_event. Do keep in mind that the did_receive_* methods have empty superclass implementations, so overriding them doesn't change any behavior, whereas the Leaf superclass does use the irc_*_event messages, and therefore overriding them without calling super may change core leaf behavior.

alolis commented 13 years ago

I thought you might suggest that. I guess I have to go with this.

Just in case you are wondering what i am trying to do is the following: I am trying to check if a user is in access list even when he is not opped in order to return from the command without executing any further actions within that command or proceed if he aint.

Also, i can't seem to be able to find out which didreceive* method is triggered after the privmsg to chanserv access #channel list

Would you mind giving it a try because did_receive_notice and did_receive_private_message didn't do it for me.

alolis commented 13 years ago

I added a breakpoint in lib/leaf.rb, irc_notice_event method but it's not triggering.

I also tried to /notice BOT message and never got did_receive_notice to trigger as well. I think the event is not capturing the notices coming from users and not server.

A quick run by your side will shed some light to the issue :)

alolis commented 13 years ago

Did u had a chance to look at this?

alolis commented 13 years ago

I am sorry for re-opening but have you had a chance to look at the problem with the even above?

RISCfuture commented 13 years ago

Looking into it ... not working on my end either.

RISCfuture commented 13 years ago

Pull in the latest version: I have changed the way notices are parsed so that irc_notice_event and did_receive_notice should now be called.