Skip to content

Instantly share code, notes, and snippets.

@regedarek
Created January 21, 2012 16:28
Show Gist options
  • Save regedarek/1653215 to your computer and use it in GitHub Desktop.
Save regedarek/1653215 to your computer and use it in GitHub Desktop.
Prosty bot do wysylania wiadomości regularnie na jakiś kanał.
# muzang_instance.rb
require 'muzang'
require 'muzang-plugins'
class SendMessageToChannel
include Muzang::Plugins::Helpers
def initialize(bot)
@bot = bot
end
def call(connection, message)
on_join(connection, message) do
EM.add_timer(120) {
connection.msg(message.channel, 'Hello World!')
EM.add_timer(200) { connection.part(message.channel) }
EM.add_timer(15) { EM.stop }
}
end
end
end
class SendMessage
def self.send_message
EM.run do
@bot = Muzang::Bot.new(irc_host: 'irc.freenode.net',
irc_port: 6667,
nick: 'PipiLandsztrum',
channels: ['#channel'])
@bot.register_plugin(SendMessageToChannel)
@bot.start # start after register plugins
end
end
end
#Rakefile
require_relative 'muzang_instance'
desc "This task is called by the Heroku cron add-on"
task :cron do
puts 'sending message...'
SendMessage.send_message
puts 'done'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment