Skip to content

Instantly share code, notes, and snippets.

@hellekin
Created August 26, 2013 19:08
Show Gist options
  • Save hellekin/6345303 to your computer and use it in GitHub Desktop.
Save hellekin/6345303 to your computer and use it in GitHub Desktop.
Lorea Assembly bot is a baby Cinch.
$:<< File.expand_path(File.join(File.dirname(__FILE__), 'lib'))
require 'cinch'
class TurnBot
include Cinch::Plugin
def initialize(*args)
super
@turns = []
end
match "queue", method: :queue
def queue(m)
if @turns.empty?
m.reply "Queue is empty. Use '+q' to be added to the speaker's queue."
else
n = @turns.count
s = n>1 ? 'speakers':'speaker'
m.reply "#{n} #{s} on queue: #{@turns.join(', ').sub(', ([^,]+)$', ', and $1')}."
end
end
match "+q", use_prefix: false, method: :enqueue
def enqueue(m)
@turns << m.user.nick unless @turns.include? m.user.nick
end
match "-q", use_prefix: false, method: :dequeue
def dequeue(m)
speaking = (@turns[0] == m.user.nick)
@turns -= [m.user.nick]
if speaking
reply_msg = "#{m.user.nick} finished speaking. "
if @turns.empty?
reply_msg << "No next speaker. Use '+q' to get on the speaker queue."
else
reply_msg << "Next speaker: *#{@turns.first}*. End your turn with '-q'."
end
m.reply reply_msg
end
end
end
bot = Cinch::Bot.new do
configure do |c|
c.nick = 'lorea-bot'
c.user = 'wisteria'
c.realname = 'Cooperative Bit Fiend'
c.sasl.username = 'lorea'
c.sasl.password = 'MySekritIsNotAvailabletoYou'
c.server = "irc.freenode.org"
c.port = 6697
c.ssl.use = true
c.channels = ["#lorea"]
c.plugins.plugins = [TurnBot]
end
# listen_to :connect, ethod: :on_connect
# def on_connect(m)
# User("NickServ").send("identify #{configuration.password}")
# end
on :message, "hello" do |m|
m.reply "Hello, #{m.user.nick}"
end
end
bot.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment