<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>sixserv blog &#187; drb</title>
	<atom:link href="http://sixserv.org/tag/drb/feed/" rel="self" type="application/rss+xml" />
	<link>http://sixserv.org</link>
	<description>A Blog about Linux, Networking, Development and Security.</description>
	<lastBuildDate>Tue, 27 Jul 2010 16:45:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Rbot Remote</title>
		<link>http://sixserv.org/2008/09/15/rbot-remote/</link>
		<comments>http://sixserv.org/2008/09/15/rbot-remote/#comments</comments>
		<pubDate>Mon, 15 Sep 2008 21:14:48 +0000</pubDate>
		<dc:creator>apoc</dc:creator>
				<category><![CDATA[RBot]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[bot]]></category>
		<category><![CDATA[drb]]></category>
		<category><![CDATA[irc]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://sixserv.org/?p=90</guid>
		<description><![CDATA[<img src="/wp-content/themes/6stheme/icons/icon_ruby.png" width="50" height="51" alt="" title="Ruby" /><br/>Ich setze schon lange den grandiosen IRC-Bot &#8220;rbot&#8221; ein. Ein überaus vielseitiger und einfach zu erweiternder Bot, der dazu auch noch in meiner Lieblings Script-Sprache Ruby geschrieben ist. Vielleicht komme ich dazu einige meiner Plugins, die ich für ihn geschrieben habe, hier zu Veröffentlichen. Eines der Features von rbot welches ich erst kürzlich entdeckt habe [...]]]></description>
			<content:encoded><![CDATA[<img src="/wp-content/themes/6stheme/icons/icon_ruby.png" width="50" height="51" alt="" title="Ruby" /><br/><p>Ich setze schon lange den grandiosen IRC-Bot &#8220;<a href="http://ruby-rbot.org/">rbot</a>&#8221; ein. Ein überaus vielseitiger und einfach zu erweiternder Bot, der dazu auch noch in meiner Lieblings Script-Sprache <a href="http://www.ruby-lang.org/">Ruby</a> geschrieben ist. Vielleicht komme ich dazu einige meiner Plugins, die ich für ihn geschrieben habe, hier zu Veröffentlichen.</p>
<p>Eines der Features von rbot welches ich erst kürzlich entdeckt habe und was absolut genial ist, ist das <a href="http://ruby-rbot.org/rbot-trac/wiki/RbotRemote">Rbot Remote Interface</a>. Per Default hört der Bot nämlich auf Port 7268(127.0.0.1) und stellt dort ein <a href="http://segment7.net/projects/ruby/drb/">DRb(Distributed Ruby)</a> Interface zur Verfügung. Dieses erlaubt es von Außen den Bot zu steuern und beispielsweise Funktionen eines Plugins auszuführen. RbotRemote kann z.B. dazu genutzt werden bei neuen SVN-Commits im RSS Plugin das Updaten eines Commit-Feeds zu starten. Denkbar ist dies natürlich auch für neue Blog-Posts innerhalb von WordPress etc.</p>
<p>Da DRb logischerweise nur für Ruby zur Verfügung steht muss bspw. eine PHP-Webapplikation ein Ruby-Skript starten welches die gewünschte Aktionen am rbot auslöst. Hier als Beispiel-Skript wird eine Nachricht an #sixserv(btw: im Freenode) gesendet:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#!/usr/bin/ruby</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'drb'</span>
&nbsp;
rbot = DRbObject.<span style="color:#9900CC;">new_with_uri</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;druby://localhost:7268&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
id = rbot.<span style="color:#9900CC;">delegate</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">nil</span>, <span style="color:#996600;">&quot;remote login owner [Owner/Auth Passwort]&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:return</span><span style="color:#006600; font-weight:bold;">&#93;</span>
rbot.<span style="color:#9900CC;">delegate</span><span style="color:#006600; font-weight:bold;">&#40;</span>id, <span style="color:#996600;">&quot;dispatch say #sixserv Hallo Welt!&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>In <a href="http://ruby-rbot.org/rbot-trac/browser/bin/rbot-remote">/bin/rbot-remote</a> gibt es ein ähnliches, etwas komplexeres Beispiel welches die Eingaben von stdin erwartet.</p>
<p>Eine weitere Möglichkeit ist wie schon erwähnt eine Methode eines Plugins zu starten. Hier ein ganz einfaches rbot-(Remote)Plugin:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> SimplePlugin <span style="color:#006600; font-weight:bold;">&lt;</span> Plugin
  <span style="color:#9966CC; font-weight:bold;">include</span> RemotePlugin
  <span style="color:#9966CC; font-weight:bold;">def</span> sayfoo<span style="color:#006600; font-weight:bold;">&#40;</span>m, params<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@bot</span>.<span style="color:#9900CC;">say</span> <span style="color:#996600;">'#sixserv'</span>, <span style="color:#996600;">'foo'</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> params.<span style="color:#9900CC;">has_key</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:bar</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">then</span>
      <span style="color:#0066ff; font-weight:bold;">@bot</span>.<span style="color:#9900CC;">say</span> <span style="color:#996600;">'#sixserv'</span>, params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:bar</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
plugin = SimplePlugin.<span style="color:#9900CC;">new</span>
plugin.<span style="color:#9900CC;">remote_map</span> <span style="color:#996600;">'sayfoo'</span>
plugin.<span style="color:#9900CC;">remote_map</span> <span style="color:#996600;">'sayfoo :bar'</span></pre></div></div>

<p>Wird die Methode extern aufgerufen kann man natürlich kein m.reply verwenden, wenn die Nachricht im Channel landen soll, ich habe das hier ganz einfach gelöst indem ich den Channel fest eingebunden habe. Hier noch das Skript welches sayfoo mit Parameter aufruft:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#!/usr/bin/ruby</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'drb'</span>
&nbsp;
rbot = DRbObject.<span style="color:#9900CC;">new_with_uri</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;druby://localhost:7268&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
id = rbot.<span style="color:#9900CC;">delegate</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">nil</span>, <span style="color:#996600;">&quot;remote login owner [Owner/Auth Passwort]&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:return</span><span style="color:#006600; font-weight:bold;">&#93;</span>
rbot.<span style="color:#9900CC;">delegate</span><span style="color:#006600; font-weight:bold;">&#40;</span>id, <span style="color:#996600;">&quot;sayfoo bar&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Update: Das Plugin auf remote_map geändert, thanks for the hint tango!</p>
]]></content:encoded>
			<wfw:commentRss>http://sixserv.org/2008/09/15/rbot-remote/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
