2007年 04月 17日

tig.rb athack

http://lab.lowreal.net/trac/changeset/668

http://unknownplace.org/memo/2007/04/15#e001 の @ をつけるというのが便利そうなので実装してみた。

realname のメールアドレスのあとにスペースをいれて athack を書くと有効になる

twitter {
    host: localhost
    port: 19876
    name: cho45@lowreal.net athack
    password: ***
}

この @つき nick は JOIN でおくらないと irssi たんはうまく補完してくれないみたいだ (353 だと op の @ としてパースされるみたい。@@ とかやってもだめ)


ゲートウェイ側で「先頭が nick なら twitter.com への送信時 @ をつける」としてもいいかもしれない……

FreeBSD rc.d

http://www.freebsd.org/doc/en_US.ISO8859-1/articles/rc-scripting/rcng-hookup.html とかあるけどよくわかんない……
どう書くのか見ようと思って /etc/rc.d 以下の cron とか読んでも実際そこでは起動してないみたいだし

/etc/rc.d/bridge は参考になるっぽい。

hoge_start () {
    _cmd="--start
}

みたいにすると「何かが」変えられるのかな

postfix の rc.d を参考にすることにした

2007年 04月 15日

irssi

-!- Irssi: critical nicklist_set_host: assertion `host != NULL' failed

がでまくる。
なにがわるいんだろ。書いたゲートウェイがわるいのはかくじつだけど、再現できなくてこまる。

JOIN, PART のメッセージがまちがっていたからみたいだ。たぶん

tig.rb (twitter irc gareway)

このエントリはやばい激烈古くてマジうけるーwww なので、github の net-irc の tig.rb をつかいましょう

git clone git://github.com/cho45/net-irc.git
cd net-irc
ruby examples/tig.rb --debug

このエントリは激烈古くてマジうけるーwww なので、net-irc の tig.rb をつかいましょう

svn co http://svn.coderepos.org/share/lang/ruby/net-irc/trunk net-irc
cd net-irc
ruby examples/tig.rb --debug

だいたい安定したっぽいのでログをまともにした。

リポジトリの位置がきもいので移動させようかとおもったけどめんどい。

導入ほう:

  1. mkdir tig
  2. cd tig
  3. svn co http://svn.lab.lowreal.net/lowreal/chokan/trunk/rice/
  4. wget http://svn.lab.lowreal.net/lowreal/chokan/trunk/tig.rb
  5. ruby tig.rb

スクリプトの設定はなし。接続方法は http://subtech.g.hatena.ne.jp/mayuki/20070408/1175994705 と同じ

常時起動の Windows がない人はいいかもよ! (っておもったけど、もう typester さんの ( http://unknownplace.org/memo/2007/04/15#e001 ) でもいいよね。アカウント設定するのがプチめんどいくらいだよね)

問題点:

  • とりこぼし? あるかもしれない。どういうことかよくわかってない。
  • 500 がでたときは冷たく失敗したよってことだけ伝える (再送しない)
  • 設定ができない (ソースが設定だよ! 書きかえればできるよ!)
  • 自分の発言がでてくる (自分はこのほうがいいんだけど)

xmllint catalog

http://www.akatsukinishisu.net/wiki.cgi?XSLT%A4%C7catalog_file%A4%F2%BB%C8%A4%A6
おお
xmllint では (Mac ではデフォルトではいっているはず。たぶん)

       --catalogs
              Use the SGML catalog(s) from SGML_CATALOG_FILES. Otherwise XML
              catalogs starting from /etc/xml/catalog are used by default.

で、--catalogs つけないときは /etc/xml/catalog をよむみたいだ

$ cd /etc
$ sudo mkdir xml
$ cd xml
$ sudo vim catalog
$ cat catalog
<?xml version="1.0"?>
<!DOCTYPE catalog
 PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN"
 "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd">
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
  <public publicId="-//W3C//DTD XHTML 1.1//EN"
    uri="xhtml11-flat.dtd"/>
  <public publicId="-//W3C//DTD XHTML 1.0 Strict//EN"
    uri="xhtml1-strict.dtd"/>
  <public publicId="-//W3C//DTD XHTML 1.0 Transitional//EN"
    uri="xhtml1-transitional.dtd"/>
  <public publicId="-//W3C//DTD XHTML 1.0 Frameset//EN"
    uri="xhtml1-frameset.dtd"/>
  <public publicId="-//W3C//DTD XHTML Basic 1.0//EN"
    uri="xhtml-basic10-f.dtd"/>
</catalog>
$ sudo wget http://www.w3.org/TR/xhtml11/DTD/xhtml11-flat.dtd
$ sudo wget http://www.w3.org/TR/xhtml-basic/xhtml-basic10-f.dtd
$ sudo wget http://www.w3.org/TR/2002/REC-xhtml1-20020801/DTD/xhtml1-strict.dtd
$ sudo wget http://www.w3.org/TR/2002/REC-xhtml1-20020801/DTD/xhtml1-transitional.dtd
$ sudo wget http://www.w3.org/TR/2002/REC-xhtml1-20020801/DTD/xhtml1-frameset.dtd
$ sudo wget http://www.w3.org/TR/2002/REC-xhtml1-20020801/DTD/xhtml-lat1.ent
$ sudo wget http://www.w3.org/TR/2002/REC-xhtml1-20020801/DTD/xhtml-special.ent
$ sudo wget http://www.w3.org/TR/2002/REC-xhtml1-20020801/DTD/xhtml-symbol.ent

これやらないと激おそい。

hcard microformats

ちょっと同時多発的に使う機会があるので調べてる。
こういうのは書いてみないとわからないものだ。

例えば wiki の例で

<span class="tel">
 <span class="type">home</span>:
 <span class="value">+1.415.555.1212</span>
</span>

みたいな例があるけれど、"home" なんて日本語の文書ではつかわない。

でもこれにはちゃんと回避策があるようで

<span class="tel">
 <abbr class="type" title="home">自宅</span>:
 <span class="value">+81-901*111*11</span>
</span>

のように書けるようだ。

<abbr title>: use the value of the 'title' attribute. If there is no 'title' attribute then use the contents of the element.

Example Web Page

あと、基本的には純粋にクラス名だけを見るため、要素には何を使ってもいい (上の abbr のように特別な要素はいくつかある。a, img, object)

2007年 04月 14日

mono TwitterIrcGateway.exe on ubuntu

$ sudo apt-get install mono

$ mono TwitterIrcGateway.exe
The assembly mscorlib.dll was not found or could not be loaded.
It should have been installed in the `/usr/lib/mono/2.0/mscorlib.dll' directory.

$ lm /usr/lib/mono/2.0
ls: /usr/lib/mono/2.0: No such file or directory

$ sudo apt-get install mono-classlib-2.0
$ mono TwitterIrcGateway.exe
** (TwitterIrcGateway.exe:4924): WARNING **: exception inside UnhandledException handler: An exception was thrown by the type initializer for System.Windows.Forms.Form

ねむい!

RICE

いろいろバグあるみたいだなぁ。つかってるひといないのかな
Replay.rpl_welcome 系は使えない。数値コマンドなのに文字列でおくってしまう。とか
あとどこだかわすれたけどチャンネル名プリフィックスの正規表現がまちがってたきがする。

とちゅうでやめた

#!/usr/bin/ruby -d


require 'rubygems'
require 'twitter'

require 'socket'
require 'rice/irc'
require 'nkf'


class IrcTwitterGateway

	def initialize(host, port)
		@clients = []

		s = TCPServer.new(host, port)
		Thread.start(s) do |s|
			loop do
				@clients << Session.new(s.accept)
			end
		end

		# @pass, @nick, @login, @user

	end


	class Session
		include RICE

		NAME = "twittergw"
		VERSION = -1
		CHANNEL = "#twitter"

		def initialize(socket)
			@s = socket
			begin
				while l = @s.gets
					$stderr.puts 's <- c: ' + l.inspect if $DEBUG
					begin
						m = Message.parse(l)
						p m
						case m
						when Command::PASS
							@pass = m.params[0]

						when Command::NICK
							@nick = m.params[0]

						when Command::USER
							@login, @real = m.params[0], m.params[3]
							@host = @s.peeraddr[2]
							@mask = "#{@nick}!#{@login}@#{@host}"
							p [@nick, @login, @real, @pass]

							on_user(m)

						when Command::PRIVMSG
							on_privmsg(m)

						end
					rescue InvalidMessage, UnknownCommand
						$stderr.puts '- -: ' + l.inspect if $DEBUG
					end
					break if m.kind_of?(Command::QUIT)
				end
			#rescue IOError
			ensure
				@s.close
			end
		end

		def on_user(m)
			@s << Message.new(NAME, "001", [@nick, "Welcome to the Internet Relay Network #{@mask}"])
			@s << Message.new(NAME, "002", [@nick, "Your host is #{NAME}, running version #{VERSION}"])
			@s << Message.new(NAME, "003", [@nick, "This server was created #{Time.now}"])
			@s << Message.new(NAME, "004", [@nick, "#{NAME} `Tynoq` v#{VERSION}"])
			@s << Message.new(@mask, "JOIN", [CHANNEL, ""])
			log "Hello this is Twitter Gateway."


			@twitter = ::Twitter::Base.new(@real, @pass)
			@friends = @twitter.friends
			@s << Message.new(NAME, "353", [@nick, "=", CHANNEL, @friends.map{|i| i.screen_name }.join(" ")])
			@s << Message.new(NAME, "366", [@nick, CHANNEL, "End of NAMES list"])

			@timeline = []
			Thread.start do
				loop do
					check_timeline
					check_friends
					sleep 60
				end
			end
		end

		def on_privmsg(m)
		end

		private
		def check_timeline
			@twitter.timeline.each do |s|
				message(s.user.screen_name, CHANNEL, s.created_at.to_s + s.text)
			end
		end

		def message(sender, target, str)
			str.gsub!(/&#(x)?([0-9a-f]+);/i) do |m|
				[$1 ? $2.hex : $2.to_i].pack("U")
			end
			@s << Message.new(sender, "PRIVMSG", [target, NKF.nkf("-j", str)])
		end

		def log(str)
			@s << Message.new(NAME, "NOTICE", [CHANNEL, str])
		end
	end
end

host, port = nil, 19876
IrcTwitterGateway.new(host, port)
sleep

rubyforge の twitter gem package は依存が微妙にやっかい (外部サイトへの依存がある) なのと、since 指定でとってこれないので、自分でかいたほうがいい。

やっぱつづきかいた

http://lab.lowreal.net/trac/browser/chokan/trunk/tig.rb
update.json からの書きこみがうまくいかない……

LimeChat の IRC ログをそのまま表示機能をつかってデバッグしてる。べんりべんり

あーPOST にするんだ。
てかあたりまえだ

chokan のディレクトリ下に入っているのは修正済み RICE がそこにあってそれを使っているってだけなので、べつに chokan つかっているわけじゃないです。

direct messages もいけるようにした。あんまてすとしてないけど……