Metafridge Jabber Support: Unterschied zwischen den Versionen

aus Metalab Wiki, dem offenen Zentrum für meta-disziplinäre Magier und technisch-kreative Enthusiasten.
Zur Navigation springenZur Suche springen
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 5: Zeile 5:


  #!/usr/bin/env ruby
  #!/usr/bin/env ruby
   
  # Metafridge Jabber/Twitter Bot - Version 0.2
# SAT July 26 2008
# Consti AT Consti PUNKT de
  require 'xmpp4r'
  require 'xmpp4r'
  require 'net/http'
  require 'net/http'
Zeile 11: Zeile 13:
  require 'iconv'
  require 'iconv'
  require 'uri'
  require 'uri'
  require 'open-uri'  
  require 'open-uri'
 
  client = Jabber::Client.new(Jabber::JID.new('metafridge@jabber.metalab.at/metalab'))
  client = Jabber::Client.new(Jabber::JID.new('metafridge@jabber.metalab.at/metalab'))
  client.connect
  client.connect
  client.auth('PASSWORT')  
  client.auth('metafoo')  
   
   
  client.send(Jabber::Presence.new.set_show(:chat).set_status('Feed me.'))  
  client.send(Jabber::Presence.new.set_show(:chat).set_status('Feed me.'))
   
   
  client.add_message_callback { |msg|
  client.add_message_callback { |msg|
  if msg.type == :chat
  if msg.type == :chat
  puts "\n------INCOMING-------\nFrom: #{msg.from}\nMessage:#{msg.body}\n--------------------\n"
    puts "\n------INCOMING-------\nFrom: #{msg.from}\nMessage:#{msg.body}\n--------------------\n"
  begin
    begin
    incoming = URI.encode(msg.body)
      incoming = URI.encode(msg.body)
    @spl = incoming.split(/:%20/)
      @spl = incoming.split(/:%20/)
    if (@spl.length == 2)
      if (@spl.length == 2)
      puts "\n------SENDING TO FRIDGE-------\nUsername: #{@spl[0]}\nMessage:#{@spl[1]}\n--------------------\n"
        puts "\n------SENDING TO FRIDGE-------\nUsername: #{@spl[0]}\nMessage:#{@spl[1]}\n--------------------\n"
      open("http://fridge.metalab.at:1337/cgi-bin/post_text.cgi?lauftext=#{@spl[1]}&playfunction=1").read
        open("http://fridge.metalab.at:1337/cgi-bin/post_text.cgi?lauftext=#{@spl[1]}&playfunction=1").read
      puts "\n-----SENT-----\n"
        puts "\n-----SENT-----\n"
    else   
      else
      open("http://fridge.metalab.at:1337/cgi-bin/post_text.cgi?lauftext=#{incoming}&playfunction=1").read
        puts "\n------SENDING TO FRIDGE-------\nMessage:#{incoming}\n--------------------\n"    
      puts "\n-----SENT-----\n"
        open("http://fridge.metalab.at:1337/cgi-bin/post_text.cgi?lauftext=#{incoming}&playfunction=1").read
    end
        puts "\n-----SENT-----\n"
  rescue
        puts "\n------SENDING RESPONSE-------\nTo:#{msg.from}\nMessage: Thanks!\n--------------------\n"
    puts "Keine Korrekte Message  "
        m = Jabber::Message.new(msg.from, 'Thanks!').set_type(:normal).set_id('1').set_subject('Thanks!')
        client.send m
      end
    rescue
      puts "Keine Korrekte Message  "
    end
   end
   end
  end
  }
  }
   
   
  Thread.stop
  Thread.stop

Version vom 26. Juli 2008, 16:08 Uhr

Ein Bot in Rails, welcher per Jabber Account neue Messages entgegen nimmt und an den Fridge sendet; Sollte eigentlich primär für den Twitterbot sein, damit man auch 'direct' messages an den Twitter Bot schicken kann, die dann angezeigt werden. Aber nachdem Twitter im Moment kein Jabber anbietet (Performance Probleme) ists nun mehr 'nur' ein Jabber Bot :) Benoetigt 'xmpp4r' gem;

#!/usr/bin/env ruby
# Metafridge Jabber/Twitter Bot - Version 0.2
# SAT July 26 2008
# Consti AT Consti PUNKT de
require 'xmpp4r'
require 'net/http'
require 'cgi'
require 'iconv'
require 'uri'
require 'open-uri'
 
client = Jabber::Client.new(Jabber::JID.new('metafridge@jabber.metalab.at/metalab'))
client.connect
client.auth('metafoo') 

client.send(Jabber::Presence.new.set_show(:chat).set_status('Feed me.'))

client.add_message_callback { |msg|
  if msg.type == :chat
   puts "\n------INCOMING-------\nFrom: #{msg.from}\nMessage:#{msg.body}\n--------------------\n"
   begin
     incoming = URI.encode(msg.body)
     @spl = incoming.split(/:%20/)
     if (@spl.length == 2)
       puts "\n------SENDING TO FRIDGE-------\nUsername: #{@spl[0]}\nMessage:#{@spl[1]}\n--------------------\n"
       open("http://fridge.metalab.at:1337/cgi-bin/post_text.cgi?lauftext=#{@spl[1]}&playfunction=1").read
       puts "\n-----SENT-----\n"
     else
       puts "\n------SENDING TO FRIDGE-------\nMessage:#{incoming}\n--------------------\n"   
       open("http://fridge.metalab.at:1337/cgi-bin/post_text.cgi?lauftext=#{incoming}&playfunction=1").read
       puts "\n-----SENT-----\n"
       puts "\n------SENDING RESPONSE-------\nTo:#{msg.from}\nMessage: Thanks!\n--------------------\n"
       m = Jabber::Message.new(msg.from, 'Thanks!').set_type(:normal).set_id('1').set_subject('Thanks!')
       client.send m
     end
   rescue
     puts "Keine Korrekte Message  "
   end
  end
}

Thread.stop