Google Wave Workshop - Day 1
ในที่สุด bot ก็คุยกับผมได้แล้ว ใส่คำสั่งภาษา python ลงไปให้มันทำงานได้ด้วย

code ที่ใช้
# -*- encoding: utf-8 -*-
from waveapi import events
from waveapi import model
from waveapi import robot
from waveapi import document
import logging
def OnParticipantsChanged(properties, context):
"""Invoked when any participants have been added/removed."""
added = properties['participantsAdded']
for p in added:
Notify(properties, context)
def OnRobotAdded(properties, context):
"""Invoked when the robot has been added."""
root_wavelet = context.GetRootWavelet()
root_wavelet.CreateBlip().GetDocument().SetText("Wazzup!")
def Notify(properties, context):
root_wavelet = context.GetRootWavelet()
root_wavelet.CreateBlip().GetDocument().SetText("Yo Man!")
def on_blip_submitted(properties, context):
blip = context.GetBlipById(properties['blipId'])
contents = blip.GetDocument().GetText()
if 'mr.fusion' in contents.lower():
man_img = document.Image('http://www.pantip.com/cafe/toy/image/man.gif')
new_blip = blip.CreateChild()
new_blip.GetDocument().AppendElement(man_img)
new_blip.GetDocument().AppendText(u'...เข้ามาดู')
else:
try:
pyobj = eval(contents)
except Exception, e:
pyobj = u'%s' % contents
new_blip = blip.CreateChild()
new_blip.GetDocument().SetText(unicode(pyobj))
if __name__ == '__main__':
myRobot = robot.Robot('chaiwat-suttipongsakul',
image_url='http://cwt.bashell.com/files/img/cwt.png',
version='9',
profile_url='http://cwt.bashell.com/')
myRobot.RegisterHandler(events.WAVELET_PARTICIPANTS_CHANGED, OnParticipantsChanged)
myRobot.RegisterHandler(events.WAVELET_SELF_ADDED, OnRobotAdded)
myRobot.RegisterHandler(events.BLIP_SUBMITTED, on_blip_submitted)
myRobot.Run()
cwt: เอา tag Django ออกนะครับ code นี้ยังไม่เกี่ยวกับ D...
qulraf: มี invite เหลือไหมคับ :$ ><...
2 comment(s) 18/7/2009 23:11
