博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
在Openwrt上跑xmpppy
阅读量:5833 次
发布时间:2019-06-18

本文共 3285 字,大约阅读时间需要 10 分钟。

首先,将python,libexpat,python-expat,libopenssl,python-openssl这几个包编译到固件中。 然后,将xmpp,dnspython这两个包复制到python的库文件目录: /usr/lib/python2.6/ 然后运行测试程序:
#!/usr/bin/python# -*- coding: utf-8 -*-# $Id: bot.py,v 1.2 2006/10/06 12:30:42 normanr Exp $# edit by TLightSky 2012/06/08 16:05import sysimport xmppcommands={}i18n={'ru':{},'en':{}}########################### user handlers start ##################################i18n['en']['HELP']="This is example jabber bot.\nAvailable commands: %s"def helpHandler(user,command,args,mess):    lst=commands.keys()    lst.sort()    return "HELP",', '.join(lst)i18n['en']['EMPTY']="%s"i18n['en']['HOOK1']='Responce 1: %s'def hook1Handler(user,command,args,mess):    return "HOOK1",'You requested: %s'%argsi18n['en']['HOOK2']='Responce 2: %s'def hook2Handler(user,command,args,mess):    return "HOOK2","hook2 called with %s"%(`(user,command,args,mess)`)i18n['en']['HOOK3']='Responce 3: static string'def hook3Handler(user,command,args,mess):    return "HOOK3"*int(args)########################### user handlers stop ############################################################### bot logic start #####################################i18n['en']["UNKNOWN COMMAND"]='Unknown command "%s". Try "help"'i18n['en']["UNKNOWN USER"]="I do not know you. Register first."def messageCB(conn,mess):    text=mess.getBody()    user=mess.getFrom()    user.lang='en'      # dup    if text.find(' ')+1: command,args=text.split(' ',1)    else: command,args=text,''    cmd=command.lower()    if commands.has_key(cmd): reply=commands[cmd](user,command,args,mess)    else: reply=("UNKNOWN COMMAND",cmd)    if type(reply)==type(()):        key,args=reply        if i18n[user.lang].has_key(key): pat=i18n[user.lang][key]        elif i18n['en'].has_key(key): pat=i18n['en'][key]        else: pat="%s"        if type(pat)==type(''): reply=pat%args        else: reply=pat(**args)    else:        try: reply=i18n[user.lang][reply]        except KeyError:            try: reply=i18n['en'][reply]            except KeyError: pass    if reply: conn.send(xmpp.Message(mess.getFrom(),reply))for i in globals().keys():    if i[-7:]=='Handler' and i[:-7].lower()==i[:-7]: commands[i[:-7]]=globals()[i]############################# bot logic stop #####################################def StepOn(conn):    try:        conn.Process(1)    except KeyboardInterrupt: return 0    return 1def GoOn(conn):    while StepOn(conn): passif len(sys.argv)<3:    print "Usage: bot.py username@server.net password"else:    jid=xmpp.JID(sys.argv[1])    user,server,password=jid.getNode(),jid.getDomain(),sys.argv[2]    conn=xmpp.Client(server)#,debug=[])    conres=conn.connect()    if not conres:        print "Unable to connect to server %s!"%server        sys.exit(1)    if conres<>'tls':        print "Warning: unable to estabilish secure connection - TLS failed!"    authres=conn.auth(user,password)    if not authres:        print "Unable to authorize on %s - check login/password."%server        sys.exit(1)    if authres<>'sasl':        print "Warning: unable to perform SASL auth os %s. Old authentication method used!"%server    conn.RegisterHandler('message',messageCB)    conn.sendInitPresence()    print "Bot started."    GoOn(conn)

转载于:https://www.cnblogs.com/TLightSky/archive/2012/06/08/2941476.html

你可能感兴趣的文章
CSS——(2)与标准流盒模型
查看>>
C#中的Marshal
查看>>
linux命令:ls
查看>>
Using RequireJS in AngularJS Applications
查看>>
【SAP HANA】关于SAP HANA中带层次结构的计算视图Cacultation View创建、激活状况下在系统中生成对象的研究...
查看>>
DevOps 前世今生 | mPaaS 线上直播 CodeHub #1 回顾
查看>>
iOS 解决UITabelView刷新闪动
查看>>
CentOS 7 装vim遇到的问题和解决方法
查看>>
JavaScript基础教程1-20160612
查看>>
【ros】Create a ROS package:package dependencies报错
查看>>
通过容器编排和服务网格来改进Java微服务的可测性
查看>>
使用《Deep Image Prior》来做图像复原
查看>>
Linux基础命令---rmdir
查看>>
Squid 反向代理服务器配置
查看>>
Java I/O操作
查看>>
Tomcat性能调优
查看>>
Android自学--一篇文章基本掌握所有的常用View组件
查看>>
灰度图像和彩色图像
查看>>
FreeMarker-Built-ins for strings
查看>>
argparse - 命令行选项与参数解析(转)
查看>>