Permalink
Browse files

mathnet plugin attached. uses sqlite3.

git-svn-id: https://dev.upnl.org/svn/ircbot2/trunk@50 66f668a4-574d-4515-85ec-6e73d9c367eb
  • Loading branch information...
1 parent 2bc336a commit 16bc1792f70fc343e7ed95418706b7ccfc3c97cc klutzy committed Jan 26, 2010
Showing with 46 additions and 0 deletions.
  1. BIN lib/mathnet.db
  2. +46 −0 plugins/mathnet.py
View
Binary file not shown.
View
@@ -0,0 +1,46 @@
+#-*- encoding: utf-8 -*-
+import re
+import sqlite3 as sqlite
+
+con = sqlite.connect('lib/mathnet.db')
+def search(eng):
+ """mathnet에서 영어 to 한국어 용어를 검색."""
+ global con
+ pq = "select english, korean from mathnet where %s order by length(english) asc limit 3"
+ q = pq % ("english = '%s'"%eng)
+ f = con.execute(q).fetchall()
+ if not f:
+ q = pq % ("english like '%"+eng+"%'")
+ f = con.execute(q).fetchall()
+ return f
+
+
+def on_pubmsg(bot, connection, event):
+ msg = event.arguments()[0]
+ source = str(event.source())
+ source = source.split('!', 1)[1]
+ source = source.split('@')[0]
+ if '=' in source: source = source.split('=',1)[1]
+ if '~' in source: source = source.split('~',1)[1]
+ if source in ['uniko', 'kouni', '|']:
+ msg = re.sub(r'^<.*?> ', '', msg, 1)
+
+ commands = ['mathnet', 'mn']
+ for command in commands:
+ if msg.startswith('!'+command+" "): break
+ else: return
+
+ output = u''
+ try:
+ s = msg.split(' ', 1)[1].strip()
+ f = search(s)
+ if f:
+ output += " / ".join(" = ".join(i) for i in f)
+ else:
+ output += u"'%s': 검색 결과가 없습니다."%s
+ except IndexError:
+ return
+
+ bot.reply(event, output)
+
+on_privmsg = on_pubmsg

0 comments on commit 16bc179

Please sign in to comment.