-
Notifications
You must be signed in to change notification settings - Fork 12
Writing Servers
pbrisbin edited this page Jan 23, 2013
·
3 revisions
Create a subclass of Server
which implements main_loop
, accept_message
, and send_message
.
module Basil
class MyServer < Server
# optionally, declare if running more than one
# instance of your server at a time would be
# a Bad Thing
lock_start
def main_loop
# block forever. when an event occurs (like an
# incoming message), yield *something*
end
def accept_message(*args)
# args will be whatever your main_loop yielded,
# this method should use that to construct and
# return a Message
end
def send_message(message)
# whatever machinery is required to send a
# Message out. Typically this will use
# Message#chat and Message#text
end
end
end
Replace DEFAULTS['server_class']
in config.rb
with MyServer
.
This step is only needed because, currently, there is only Cli
and Skype
so they are handled specially. If someone were to actually contribute an additional server, I would refactor these aspects.