Created
January 21, 2012 16:28
-
-
Save regedarek/1653215 to your computer and use it in GitHub Desktop.
Prosty bot do wysylania wiadomości regularnie na jakiś kanał.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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