LINUX.ORG.RU

gtalk jabber bot ruby

 ,


0

1

Есть простейший бот, собственно код:

#!/usr/bin/env ruby

require 'rubygems'
require 'xmpp4r-simple'
require 'session'
# Запускаем сеанс sh, в котором будет происходить выполнение команд
bot.deliver(msg.from, "\n" + stdout.chomp) unless stdout.empty?
@sh = Session::new
# Коннектимся к Jabber-серверу
bot = Jabber::Simple.new('bot-acc@gmail.com', "passw0rd")
while true
# Ожидаем сообщение
bot.received_messages do |msg|
# Проверяем, что сообщение пришло от юзер@gmail.com
if msg && msg.from.to_s.include?('deliver@gmail.com')
# Выполняем команды в сеансе sh
stdout, stderr = @sh.execute(msg.body) if msg.body
# Отправляем в ответном сообщении вывод команды
bot.deliver(msg.from, "\n" + stdout.chomp) unless stdout.empty?
# Отправляем поток ошибок
bot.deliver(msg.from, "\n" + stderr.chomp) unless stderr.empty?
end
end
запускаю, выдает ошибку:
$ ./gmail-bot:23: syntax error, unexpected $end, expecting keyword_end
^C
[1]+  Exit 1                  ./gmail-bot

★★★

Последнее исправление: conformist (всего исправлений: 1)

Мм... А где окончания для условных выражений, fi? И then?

Weres ★★★
()
Ответ на: комментарий от ttyv0_o
#!/usr/bin/env ruby
require 'rubygems'
require 'xmpp4r-simple'
require 'session'
@sh = Session::new
bot = Jabber::Simple.new('bot-acc@gmail.com', "passw0rd")
loop do
bot.received_messages do |msg|
if msg && msg.from.to_s.include?('deliver@gmail.com')
stdout, stderr = @sh.execute(msg.body) if msg.body
bot.deliver(msg.from, "\n" + stdout.chomp) unless stdout.empty?
bot.deliver(msg.from, "\n" + stderr.chomp) unless stderr.empty?
end
end

ошибка та же :(
conformist ★★★
() автор топика
Ответ на: комментарий от conformist

И ещё end в конце добавь. Было бы у тебя форматирование кода нормальное, ты бы и сам заметил где end пропустил. =)

ttyv0_o
()
Ответ на: комментарий от ttyv0_o

Дело в том, что я ruby вообще не знаю, визуально вижу, что есть пара открывающих while true и if, вроде бы всего хватало :) теперь другая проблема:

$ ./gmail-bot &
[1] 16353
test @ test ~/Scripts$ /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:60:in `require': /var/lib/gems/1.9.1/gems/xmpp4r-simple-0.8.8/lib/xmpp4r-simple.rb:441: syntax error, unexpected ':', expecting keyword_then or ',' or ';' or '\n' (SyntaxError)
                   when nil: new_presence.show || :online
                            ^
/var/lib/gems/1.9.1/gems/xmpp4r-simple-0.8.8/lib/xmpp4r-simple.rb:442: syntax error, unexpected keyword_when, expecting keyword_end
                   when :unavailable: :unavailable
                       ^
/var/lib/gems/1.9.1/gems/xmpp4r-simple-0.8.8/lib/xmpp4r-simple.rb:443: syntax error, unexpected keyword_else, expecting keyword_end
/var/lib/gems/1.9.1/gems/xmpp4r-simple-0.8.8/lib/xmpp4r-simple.rb:490: syntax error, unexpected keyword_end, expecting $end
	from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:60:in `rescue in require'
	from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
	from ./gmail-bot:3:in `<main>'
на что-то ругается, а что именно, я не пойму

conformist ★★★
() автор топика
Ответ на: комментарий от conformist
$ gem query -rd xmpp4r-simple

*** REMOTE GEMS ***

xmpp4r-simple (0.8.8)
    Author: Blaine Cook
    Homepage: http://xmpp4r-simple.rubyforge.org/

    A simplified Jabber client library.

xmpp4r-simple-19 (1.0.0)
    Author: Blaine Cook
    Homepage: https://github.com/treeder/xmpp4r-simple

    A simplified Jabber client library.

Я думаю ты поставил старый gem xmpp4r-simple для версии 1.8, а для руби 1.9.* нужен gem xmpp4r-simple-19.

ttyv0_o
()
Ответ на: комментарий от ttyv0_o
# gem install xmpp4r-simple
Fetching: xmpp4r-0.5.6.gem (100%)
Fetching: xmpp4r-simple-0.8.8.gem (100%)
Successfully installed xmpp4r-0.5.6
Successfully installed xmpp4r-simple-0.8.8
2 gems installed
Installing ri documentation for xmpp4r-0.5.6...
file 'index.html' not found
Installing ri documentation for xmpp4r-simple-0.8.8...
Installing RDoc documentation for xmpp4r-0.5.6...
file 'index.html' not found
Installing RDoc documentation for xmpp4r-simple-0.8.8...
$ gem -rd xmpp4r-simple
ERROR:  Invalid option: -rd.  See 'gem --help'.

как теперь поставить другую версию ( и удалить эту, соответственно)

conformist ★★★
() автор топика
Ответ на: комментарий от conformist

спасибо. А если хочешь толкового совета, то добавь тег ruby.

emulek
()
Ответ на: комментарий от conformist

Если кто-нибудь узнает твой jid и jid бота, то может зарегать jid вида abcd(твой-jid) и получить доступ к твоему боту. Лучше перепиши проверку jid'а.

ttyv0_o
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.