Google Wave Workshop - Day 1

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

cwtbot1

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
CWT
:::All Blogs:::
Moblin 2.1 กับภาษาไทย และ wireless
STOU Graduate
Google Wave Workshop - Day 1
ภาพ HDR
หน้าต่างคอนโด
ทดสอบ libthai บน Mac OS X
วันเกิดแป๋ม
สามัญสำนึกใช่ว่าจะถูกเสมอไป
โปรดระวังการใช้ emoticon ใน pantip.com
ทดสอบ javascript ของ WebKit เทียบกับ Firefox
diff list by set part 2
diff list by set
ICT Block Web
The Cathedral And The Bazaar
สวนหลวง ร.9
โฆษณาบ่งบอกความใส่ใจ
run Django ใน mode prefork นี่น่ากลัวแฮะ
อักษรพิเศษใน Title
Thai locale in Django-SVN
เบื่อและเซ็ง
Code Sprint VS. Dev Fest
My Real Nickname and The Story of My Alias Name
My Books
หมอนรองกระดูกทับเส้นประสาท
python-markdown2
การใช้ Nginx กับ Django
ลองเล่น Django's Comments Framework
Bashell Upgraded
ช่วงนี้ซื้อแต่ HP
Work@NY - Day1
Blog เริ่มใช้งานได้แล้ว
Penguin and Dolphin
Use Squid proxy on Windows Server
Test Markdown
A Django project.
Valid XHTML 1.0 Transitio
nal