示例#1
0
def handlemessage(user, msg, ctx=None):
# 	if msg == '.reset':# and user == 'ofYB4jt9Sk0uIY8tv2nrluSH6jcc':
# 		# 该操作很危险,会重置数据库,只允许特定用户
# 		reset_all(ctx)
# 		return 'reset ok'
	dba = ctx.dba
	sttm = entm = 0
	dba.add_object(tb_message, {
  							'userid':user,
  							'message':msg,
  							'type':'text',
  							'typeid': MESSAGE_TYPE_TEXT,
  							'dir':MESSAGE_DIR_UP,
  							'time':int(time())
  							}
  				)
	rets = '未处理'
	try:
		kvdb = ctx.kvdb
		curslt = SinLikeTerminal(kvdb, bulu_route, debug=False)
		msg = msg.replace('?', '?')
		sttm = time()
		rets = curslt.process_message(user, msg, ctx)
# 		print 'll:%d'%len(rets)
		entm = time()
	except:
		errinfo = traceback.format_exc()
		print errinfo
		if 'debug' in config and config['debug']:
			rets = errinfo
		else:
			rets = 'Oops...\n内部出错\n请重新试  ~_~\n%s' % BOTTOMHELPFULL
		dba.add_object(tb_message, {
	  							'userid':user,
	  							'message':msg,
	  							'type':'error',
	  							'typeid': MESSAGE_TYPE_ERROR,
	  							'dir':MESSAGE_DIR_INTER,
	  							'time':int(time())
	  							}
	  				)
	msgobj = None
	if type(rets) != type((1,)):
		msgobj = {	'userid':user,
					'message':rets,
					'type':'text(%s)' % (entm - sttm),
					'typeid': MESSAGE_TYPE_TEXT,
					'dir':MESSAGE_DIR_DOWN,
					'time':int(time())
					}
	else:
		msgobj = {	'userid':user,
					'message':rets[1],
					'type':'%s(%s)' % (rets[0] == MESSAGE_TYPE_IMAGE and 'image' or 'unknow', (entm - sttm)),
					'typeid': MESSAGE_TYPE_IMAGE,
					'dir':MESSAGE_DIR_DOWN,
					'time':int(time())
					}
	dba.add_object(tb_message, msgobj)
	ctx.msgobj = msgobj
	return rets
示例#2
0
# -*- coding: UTF-8 -*
'''
Created on 2013-9-14

@author: RobinTang
'''

from time import time
from SinLikeTerminal import SinLikeTerminal
from BuluFuncs import BOTTOMHELPFULL
import BuluFuncs
import traceback
from bulu.Adapters import BaseAdapter
config = {'debug':True}

slt = SinLikeTerminal()
slt.add_route('1', BuluFuncs.ynu_lib_search)
slt.add_route('1.echo', BuluFuncs.tool_echo)
slt.add_route('1.debug', BuluFuncs.tool_debug)
slt.add_route('1.config', BuluFuncs.tool_config)
slt.add_route('1.dev', BuluFuncs.tool_dev)


slt.refresh_allroute()
bulu_route = slt.route
del slt


tb_event = 'tb_bulu_event'
tpl_event = {
			'userid':'char(128)',