示例#1
0
def subEvent(msg):
    data = tools.client.user.get(msg.source)
    try:
        username = data["nickname"]
        users = User.objects.filter(openId=msg.source)
        if len(users) > 0:
            user = users[0]
        else:
            user = User(name=data["nickname"],
                        sex=int(data["sex"]),
                        openId=msg.source,
                        comment=u"现在还是空的><")
            user.save()
            team = Team(name=basic_tools.teamName(None, username), type=0)
            team.save()
            team.members.add(user)
        user.name = username
        user.uid = int(random.random() * 100)
        if "headimgurl" in data:
            user.image = data["headimgurl"]
        user.save()
        date = basic_tools.getDate()
        #如果DayData不存在,则创建
        if DayData.objects.filter(user=user, date=date).count() == 0:
            dayData = DayData(user=user, date=date)
            basic_tools.updateDayData(dayData, user)
            dayData.save()
    except:
        username = ""
    return HttpResponse(
        create_reply(u"%s!欢迎使用新中韩无敌了的手环公众号!\n%s" % (username, tools.help_text),
                     message=msg))
示例#2
0
def subEvent(msg):
    data = tools.client.user.get(msg.source)
    try:
        username = data["nickname"]
        users = User.objects.filter(openId=msg.source)
        if len(users) > 0:
            user = users[0]
        else:
            user = User(name=data["nickname"],sex=int(data["sex"]),openId=msg.source,comment=u"现在还是空的><")
            user.save()
            team = Team(name=basic_tools.teamName(None, username),type=0)
            team.save()
            team.members.add(user)
        user.name = username
        user.uid = int(random.random() * 100)
        if "headimgurl" in data:
            user.image = data["headimgurl"]
        user.save()
        date = basic_tools.getDate()
        #如果DayData不存在,则创建
        if DayData.objects.filter(user=user,date=date).count() == 0:
            dayData = DayData(user=user,date=date)
            basic_tools.updateDayData(dayData, user)
            dayData.save()
    except:
        username = ""
    return HttpResponse(create_reply(u"%s!欢迎使用新中韩无敌了的手环公众号!\n%s" % (username, tools.help_text), message=msg))
示例#3
0
def match_join(request):
    if os.environ.get("TEST", None):
        request.session["userId"] = request.GET["userId"]
    if not "userId" in request.session:
        return HttpResponse("error")
    if not "userId" in request.GET:
        return HttpResponse("error")
    result = "success"
    try:
        matchId = int(request.GET["target"])
        match = Match.objects.get(id=matchId)
        userId = request.GET["userId"]
        user = User.objects.get(openId=userId)
        if not "team" in request.GET:
            team = tools.findTeam(match, user)
            match.user_members.remove(user)
            if team.type == 0:
                match.members.remove(team)
            else:
                team.members.remove(user)
                if team.members.all().count() == 1:
                    member = team.members.all()[0]
                    match.members.remove(team)
                    team.delete()
                    team = member.user_team_members.get(type=0)
                    match.members.add(team)
            if match.user_members.all().count() == 0:
                match.delete()
                result = "delete"
        else:
            match.user_members.add(user)
            teamId = int(request.GET["team"])
            if teamId == -1:
                team = user.user_team_members.get(type=0)
                match.members.add(team)
            else:
                team = Team.objects.get(id=teamId)
                if team.type == 0:
                    match.members.remove(team)
                    member = team.members.all()[0]
                    team = Team(name=basic_tools.teamName(team,user.name),type=1)
                    team.save()
                    team.members.add(member)
                    match.members.add(team)
                team.members.add(user)
    except:
        result="error"
    return HttpResponse(result)