예제 #1
0
파일: cmddo.py 프로젝트: xixitalk/xixiguys
def CmdUserDo(from_name,msg):
	ret_str = u'init'
	if GetCmdNum(msg) != 2:
		return 'error:need user nickname or gtalk'
	nickname = GetCmdByNum(msg,2)
	if mail.is_email_valid(nickname):
		user = funcs.getUserByName(nickname)
		if user is None:
			user = funcs.getUserByNickname(nickname)
	else:
		user = funcs.getUserByNickname(nickname)
	if user is None:
		ret_str = u'CANT find user:%s' % nickname
		return ret_str.encode('utf-8')
	ret_str = u'%s' % user.nickname
	if funcs.isAdmin(from_name) or user.gtalk==from_name:
		ret_str += u'(%s)' % user.gtalk
	ret_str += u',在%s第%d个加入本群\n' % (funcs.getNatureTime(user.time),funcs.getUserNo(user.gtalk))
	
	if funcs.isAdmin(from_name) or user.gtalk==from_name:
		ret_str += u'设置:'
		if user.recvOfflineMsg:
			ret_str += u'离线时接收消息'
		else:
			ret_str += u'离线时不接收消息'
		if user.recvOnlineMsg:
			ret_str += u',在线时接收消息\n'
		else:
			ret_str += u',在线时不接收消息\n'
	users_dict = funcs.getUserCountList()
	if user.gtalk in users_dict.keys():
		user_data = users_dict[user.gtalk]
		ret_str += u'共发%d个消息,最后一次发消息在%s' % (user_data['count'],funcs.getNatureTime2(user_data['time']))

	return ret_str.encode('utf-8')
예제 #2
0
파일: cmddo.py 프로젝트: jn7163/xixiguys
def CmdJoinDo(from_name, msg):
    if funcs.isInBalckList(from_name):
        return 'you are in black list,contact administrator'
    if funcs.isHavePassword() and not funcs.isInWhiteList(from_name):
        if GetCmdNum(msg) != 3:
            if not funcs.isInGroupUser(from_name):
                ret_str = '%s was trying to join group' % from_name
                funcs.sendMsgToAdminUsers(ret_str)
            return 'ERROR:this group need password!'
        passwd = GetCmdByNum(msg, 3)
        if not funcs.checkPassword(passwd):
            if not funcs.isInGroupUser(from_name):
                ret_str = '%s was trying to join group' % from_name
                funcs.sendMsgToAdminUsers(ret_str)
            return 'ERROR:group password not correct!'

    if GetCmdNum(msg) < 2:
        return 'need nickname'
    nickname = GetCmdByNum(msg, 2)
    user = funcs.getUserByNickname(nickname)

    if user:
        return 'nickname:%s is taken by somebody' % nickname
    user = funcs.getUserByName(from_name)
    if user:
        return 'you have been joined already'
    funcs.userJoin(from_name, nickname)
    ret_msg = u'welcome %s joined this group' % nickname
    funcs.Broadcast(ret_msg)
    return 'you join successfully'
예제 #3
0
파일: cmddo.py 프로젝트: xixitalk/xixiguys
def CmdJoinDo(from_name,msg):
	if funcs.isInBalckList(from_name):
		return 'you are in black list,contact administrator'
	if funcs.isHavePassword() and not funcs.isInWhiteList(from_name):
		if GetCmdNum(msg) != 3:
			if not funcs.isInGroupUser(from_name):
				ret_str = '%s was trying to join group' % from_name
				funcs.sendMsgToAdminUsers(ret_str)
			return 'ERROR:this group need password!'
		passwd = GetCmdByNum(msg,3)
		if not funcs.checkPassword(passwd):
			if not funcs.isInGroupUser(from_name):
				ret_str = '%s was trying to join group' % from_name
				funcs.sendMsgToAdminUsers(ret_str)
			return 'ERROR:group password not correct!'

	if GetCmdNum(msg) < 2:
		return 'need nickname'
	nickname = GetCmdByNum(msg,2)
	user = funcs.getUserByNickname(nickname)

	if user:
		return 'nickname:%s is taken by somebody' % nickname
	user = funcs.getUserByName(from_name)
	if user:
		return 'you have been joined already'
	funcs.userJoin(from_name,nickname)
	ret_msg = u'welcome %s joined this group' % nickname
	funcs.Broadcast(ret_msg)
	return 'you join successfully'
예제 #4
0
파일: cmddo.py 프로젝트: xixitalk/xixiguys
def CmdNickDo(from_name,msg):
	if GetCmdNum(msg) < 2:
		return 'need nickname'
	ret_msg = None
	nickname = GetCmdByNum(msg,2)
	if len(nickname) > 20:
		ret_msg = u'nickname %s too long(<=20)' % nickname
		return ret_msg.encode('utf-8')
	user = funcs.getUserByNickname(nickname)
	if user:
		if user.gtalk == from_name:
			ret_msg = u'your nickname is %s already.' % nickname
		else:
			ret_msg = u'nickname:%s is taken by somebody' % nickname
		return ret_msg.encode('utf-8')
	user = funcs.getUserByNameFromDb(from_name)
	if user is None:
		return 'you are not joined'
	old_name = user.nickname
	user.nickname = nickname
	user.put()
	funcs.updateUserListFromCache(user)
	
	try:
		ret_msg = u'%s change nickname to %s' % (old_name,nickname)
		funcs.broastcastMsg(ret_msg,from_name)
	except:
		pass
	ret_msg = u'you have changed nickname:%s' % nickname
	return ret_msg.encode('utf-8')
예제 #5
0
파일: cmddo.py 프로젝트: jn7163/xixiguys
def CmdNickDo(from_name, msg):
    if GetCmdNum(msg) < 2:
        return 'need nickname'
    ret_msg = None
    nickname = GetCmdByNum(msg, 2)
    if len(nickname) > 20:
        ret_msg = u'nickname %s too long(<=20)' % nickname
        return ret_msg.encode('utf-8')
    user = funcs.getUserByNickname(nickname)
    if user:
        if user.gtalk == from_name:
            ret_msg = u'your nickname is %s already.' % nickname
        else:
            ret_msg = u'nickname:%s is taken by somebody' % nickname
        return ret_msg.encode('utf-8')
    user = funcs.getUserByNameFromDb(from_name)
    if user is None:
        return 'you are not joined'
    old_name = user.nickname
    user.nickname = nickname
    user.put()
    funcs.updateUserListFromCache(user)

    try:
        ret_msg = u'%s change nickname to %s' % (old_name, nickname)
        funcs.broastcastMsg(ret_msg, from_name)
    except:
        pass
    ret_msg = u'you have changed nickname:%s' % nickname
    return ret_msg.encode('utf-8')
예제 #6
0
파일: cmddo.py 프로젝트: xixitalk/xixiguys
def CmdBlockDo(from_name,msg):
	if GetCmdNum(msg) != 2:
		return 'error:need user nickname'
	nickname = GetCmdByNum(msg,2)
	user = funcs.getUserByNickname(nickname)
	if user is None:
		ret_str = u'cant find user %s' % nickname
		return ret_str.encode('utf-8')
	if funcs.isInDarkRoomUserList(from_name) and from_name!=user.gtalk:
		return 'you are in DarkRoom,CANT block somebody'
	funcs.addBlockUserList(from_name,user.gtalk)
	funcs.checkBlockUserList(2,10)
	ret_str = u'block %s ok' % nickname
	return ret_str.encode('utf-8')
예제 #7
0
파일: cmddo.py 프로젝트: xixitalk/xixiguys
def CmdPrivateMsgDo(from_name,msg):
	if GetCmdNum(msg) < 3:
		return 'need nickname and msg'
	nickname = GetCmdByNum(msg,2)
	user = funcs.getUserByNickname(nickname)
	if user is None:
		return 'nickname %s is unknowned' % nickname
	from_user = funcs.getUserByName(from_name)
	msg_pre = '@%s:' % from_user.nickname
	msgbody = msg_pre + msg[msg.find(nickname) + len(nickname)+1:].strip()
	
	xmpp_api.xmpp_sendmsg(user.gtalk,msgbody)
	ret_str = u'you send private msg to %s successfully' % nickname
	return ret_str.encode('utf-8')
예제 #8
0
파일: cmddo.py 프로젝트: jn7163/xixiguys
def CmdBlockDo(from_name, msg):
    if GetCmdNum(msg) != 2:
        return 'error:need user nickname'
    nickname = GetCmdByNum(msg, 2)
    user = funcs.getUserByNickname(nickname)
    if user is None:
        ret_str = u'cant find user %s' % nickname
        return ret_str.encode('utf-8')
    if funcs.isInDarkRoomUserList(from_name) and from_name != user.gtalk:
        return 'you are in DarkRoom,CANT block somebody'
    funcs.addBlockUserList(from_name, user.gtalk)
    funcs.checkBlockUserList(2, 10)
    ret_str = u'block %s ok' % nickname
    return ret_str.encode('utf-8')
예제 #9
0
파일: cmddo.py 프로젝트: jn7163/xixiguys
def CmdPrivateMsgDo(from_name, msg):
    if GetCmdNum(msg) < 3:
        return 'need nickname and msg'
    nickname = GetCmdByNum(msg, 2)
    user = funcs.getUserByNickname(nickname)
    if user is None:
        return 'nickname %s is unknowned' % nickname
    from_user = funcs.getUserByName(from_name)
    msg_pre = '@%s:' % from_user.nickname
    msgbody = msg_pre + msg[msg.find(nickname) + len(nickname) + 1:].strip()

    xmpp_api.xmpp_sendmsg(user.gtalk, msgbody)
    ret_str = u'you send private msg to %s successfully' % nickname
    return ret_str.encode('utf-8')
예제 #10
0
파일: cmddo.py 프로젝트: jn7163/xixiguys
def CmdUserDo(from_name, msg):
    ret_str = u'init'
    if GetCmdNum(msg) != 2:
        return 'error:need user nickname or gtalk'
    nickname = GetCmdByNum(msg, 2)
    if mail.is_email_valid(nickname):
        user = funcs.getUserByName(nickname)
        if user is None:
            user = funcs.getUserByNickname(nickname)
    else:
        user = funcs.getUserByNickname(nickname)
    if user is None:
        ret_str = u'CANT find user:%s' % nickname
        return ret_str.encode('utf-8')
    ret_str = u'%s' % user.nickname
    if funcs.isAdmin(from_name) or user.gtalk == from_name:
        ret_str += u'(%s)' % user.gtalk
    ret_str += u',在%s第%d个加入本群\n' % (funcs.getNatureTime(
        user.time), funcs.getUserNo(user.gtalk))

    if funcs.isAdmin(from_name) or user.gtalk == from_name:
        ret_str += u'设置:'
        if user.recvOfflineMsg:
            ret_str += u'离线时接收消息'
        else:
            ret_str += u'离线时不接收消息'
        if user.recvOnlineMsg:
            ret_str += u',在线时接收消息\n'
        else:
            ret_str += u',在线时不接收消息\n'
    users_dict = funcs.getUserCountList()
    if user.gtalk in users_dict.keys():
        user_data = users_dict[user.gtalk]
        ret_str += u'共发%d个消息,最后一次发消息在%s' % (
            user_data['count'], funcs.getNatureTime2(user_data['time']))

    return ret_str.encode('utf-8')
예제 #11
0
파일: cmddo.py 프로젝트: xixitalk/xixiguys
def CmdKickDo(from_name,msg):
	if not funcs.isAdmin(from_name):
		return 'you are not administrator'
	if GetCmdNum(msg) == 1:
		blacklist = funcs.getBlackList()
		if blacklist is None or len(blacklist) == 0:
			return 'blacklist is null'
		else:
			retstr = ''
			for item in blacklist:
				retstr += item + ','
			return retstr

	if GetCmdNum(msg) != 3:
		return 'para error'
	cmd = GetCmdByNum(msg,2)
	para3 = GetCmdByNum(msg,3)
	if mail.is_email_valid(para3):
		gtalk = para3
	else:
		user = funcs.getUserByNickname(para3)
		gtalk = user.gtalk

	if cmd == 'add':
		ret = funcs.kickuser(gtalk,from_name)
		if ret:
			return 'kick %s success' % gtalk
		else:
			return 'kick %s fail' % gtalk
	if cmd == 'del':
		ret =  funcs.delBlackList(gtalk)
		if ret:
			return 'del %s from blacklist success' % gtalk
		else:
			return 'del %s from blacklist fail' % gtalk
	return 'para error'
예제 #12
0
파일: cmddo.py 프로젝트: jn7163/xixiguys
def CmdKickDo(from_name, msg):
    if not funcs.isAdmin(from_name):
        return 'you are not administrator'
    if GetCmdNum(msg) == 1:
        blacklist = funcs.getBlackList()
        if blacklist is None or len(blacklist) == 0:
            return 'blacklist is null'
        else:
            retstr = ''
            for item in blacklist:
                retstr += item + ','
            return retstr

    if GetCmdNum(msg) != 3:
        return 'para error'
    cmd = GetCmdByNum(msg, 2)
    para3 = GetCmdByNum(msg, 3)
    if mail.is_email_valid(para3):
        gtalk = para3
    else:
        user = funcs.getUserByNickname(para3)
        gtalk = user.gtalk

    if cmd == 'add':
        ret = funcs.kickuser(gtalk, from_name)
        if ret:
            return 'kick %s success' % gtalk
        else:
            return 'kick %s fail' % gtalk
    if cmd == 'del':
        ret = funcs.delBlackList(gtalk)
        if ret:
            return 'del %s from blacklist success' % gtalk
        else:
            return 'del %s from blacklist fail' % gtalk
    return 'para error'