Exemple #1
0
def speaker():
    idx = {
        k.split('_')[-1]: k for k in request.cookies
        if k.startswith(options.discuz_cookiepre)
    }

    if not ('auth' in idx and 'saltkey' in idx):
        response.status = 403
        return

    auth = unquote(request.get_cookie(idx['auth']))
    saltkey = unquote(request.get_cookie(idx['saltkey']))
    uid, pwd = Account.decode_cookie(auth, saltkey)
    user = Account.find(uid)
    if not user:
        return 'false'

    if user.jiecao < 0:
        return 'false'

    message = request.forms.get('message').decode('utf-8', 'ignore')
    username = user.username.decode('utf-8', 'ignore')

    interconnect.publish('speaker', [username, message])

    return 'true'
Exemple #2
0
def speaker():
    idx = {
        k.split('_')[-1]: k
        for k in request.cookies if k.startswith(options.discuz_cookiepre)
    }

    if not ('auth' in idx and 'saltkey' in idx):
        response.status = 403
        return

    auth = unquote(request.get_cookie(idx['auth']))
    saltkey = unquote(request.get_cookie(idx['saltkey']))
    uid, pwd = Account.decode_cookie(auth, saltkey)
    user = Account.find(uid)
    if not user:
        return 'false'

    if user.jiecao < 0:
        return 'false'

    message = request.forms.get('message').decode('utf-8', 'ignore')
    username = user.username.decode('utf-8', 'ignore')

    interconnect.publish('speaker', [username, message])

    return 'true'
Exemple #3
0
def charge(username, message):
    user = Account.find(username)
    if not user:
        log.info('User %s not found' % username)
        return

    uid = user.id
    if uid in privileged:
        log.info('User %s in privileged group, not charging.' % username)
        return

    t, fee = history[uid]
    now = time.time()
    fee = max(fee - (now - t) / 30.0, 5)
    if not isinstance(message, unicode):
        message = message.decode('utf-8')

    l = len(message)

    fee += 0 if l < 40 else (l - 40) * 1
    history[uid] = (now, min(fee * 2, 2000))
    fee  = int(fee)
    log.info('Charge %s for %s' % (username, fee))
    Account.add_user_credit(user, [['jiecao', -fee]])
    interconnect.publish('aya_charge', [uid, fee])
Exemple #4
0
def charge(username, message):
    user = Account.find(username)
    if not user:
        log.info('User %s not found' % username)
        return

    uid = user.id
    if uid in privileged:
        log.info('User %s in privileged group, not charging.' % username)
        return

    t, fee = history[uid]
    now = time.time()
    fee = max(fee - (now - t) / 30.0, 5)
    if not isinstance(message, unicode):
        message = message.decode('utf-8')

    l = len(message)

    fee += 0 if l < 40 else (l - 40) * 1
    history[uid] = (now, min(fee * 2, 2000))
    fee  = int(fee)
    log.info('Charge %s for %s' % (username, fee))
    Account.add_user_credit(user, [['jiecao', -fee]])
    interconnect.publish('aya_charge', [uid, fee])
Exemple #5
0
    def _message(self, type, msg):
        not_registered_text = (u'文文不认识你,不会帮你发新闻的哦。\n'
                               u'回复“文文求交朋友 uid 密码”,不要带引号,文文就会认识你啦。\n'
                               u'uid可以在登陆论坛或者游戏后知道,密码就是论坛的密码。\n'
                               u'比如这样:\n'
                               u'文文求交朋友 23333 wodemima23333\n'
                               u'\n'
                               u'文文帮你发新闻是要收费的,一发5节操。不过连续发的话收费会翻倍哦。')

        registered_text = (u'哎呀呀呀,原来你是%s啊,文文认识你了。\n' u'只要你的节操还在,文文就会帮你发新闻~\n')

        help_text = (u'所有在QQ群里以“`”或者“\'”开头的聊天都会被当做发新闻的请求~\n'
                     u'比如这样:\n'
                     u'`文文最是清正廉直!\n'
                     u'\n'
                     u'文文帮你发新闻是要收费的,一发5节操。不过连续发的话收费会翻倍哦。')

        fail_text = (u'文文调查了一下你,发现你的密码填的不对!\n' u'快说你到底是谁!')

        qq = self.uin2qq(msg['from_uin'])

        if type == 'buddy':
            send = lambda t: self.send_buddy_message(msg['from_uin'], t)
        elif type == 'sess':
            send = lambda t: self.send_sess_message(msg['id'], msg['from_uin'],
                                                    t)

        uid = State.dao.get_binding(qq)
        if not uid:
            content = self._plaintext(msg['content']).strip()
            req = content.split(None, 2)
            req = [i.strip() for i in req]
            try:
                check(len(req) == 3)
                check(req[0] == u'文文求交朋友')
                check(req[1].isdigit())
            except CheckFailed:
                send(not_registered_text)
                return

            uid = int(req[1])
            pwd = req[2]

            username = None
            user = Account.find(uid)
            if not (user
                    and Account.validate_by_password(user.dz_member, pwd)):
                send(fail_text)
                return
            username = user.username

            State.dao.set_binding(qq, uid)

            send(registered_text % username + help_text)
            return

        send(help_text)
Exemple #6
0
    def do_speaker(self, uin, content, group_uin=None):
        fail_text = u'文文不认识你,才不帮你发新闻呢。想跟文文做朋友么?悄悄地告诉文文吧。'
        insufficient_funds_text = u'你的节操掉了一地,才不帮你发新闻呢。'

        qq = self.uin2qq(uin)
        uid = State.dao.get_binding(qq)
        if not uid:
            group_uin and self.send_group_message(group_uin, fail_text)
            return

        user = Account.find(uid)
        username = user.username

        if user.jiecao < 0:
            group_uin and self.send_group_message(group_uin,
                                                  insufficient_funds_text)
            return

        # April Fool!
        from datetime import datetime
        import random
        b4 = datetime(2016, 4, 1)
        af = datetime(2016, 4, 2)
        if b4 < datetime.now() < af:
            content += random.choice([
                u'喵~',
                u'汪~',
                u'poi~',
                u'的说~',
                u'呱~',
                u'niconiconi~',
                u'(PS:灵梦没节操——',
                u'(PS:油咖喱的脚很臭——',
                u'(PS:河童喜欢巨大的黄瓜——',
                u'(PS:妖梦是男孩子——',
                u'(PS:茨木华扇又在卖自己的本子——',
                u'(PS:幽香和天子又在做爱做的事——',
                u'(PS:藤原妹红穿的是男士胖次——',
                u'(PS:帕秋莉喜欢在房间里练习娇喘——',
                u'(PS:椛椛想要——',
                u'(PS:爱丽丝又在扎小人——',
                u'(PS:有看到小伞和盖伦在酒吧喝酒——',
                u'(PS:四季的胸还不到A罩杯——',
                u'(PS:早苗的欧派,赞——',
                u'(PS:森近霖之助昨天买了好多卫生纸——',
                u'(PS:咲夜又买了更大号的PAD——',
                u'(PS:昨天下午菜市场关门了,原因是幽幽子上午去过——',
                u'(PS:昨天琪露诺和灵乌路空比算数,灵乌路空赢了——',
                u'(PS:守矢大法好—— 天灭博丽,退博保平安—— 人在做,天在看,毫无节操留祸患—— 上网搜“10万元COS”有真相——',
            ])
            # --------

        State.interconnect.publish('speaker', [username, content])
Exemple #7
0
    def do_speaker(self, uin, content, group_uin=None):
        fail_text = u'文文不认识你,才不帮你发新闻呢。想跟文文做朋友么?悄悄地告诉文文吧。'
        insufficient_funds_text = u'你的节操掉了一地,才不帮你发新闻呢。'

        qq = self.uin2qq(uin)
        uid = State.dao.get_binding(qq)
        if not uid:
            group_uin and self.send_group_message(group_uin, fail_text)
            return

        user = Account.find(uid)
        username = user.username

        if user.jiecao < 0:
            group_uin and self.send_group_message(group_uin, insufficient_funds_text)
            return

        # April Fool!
        from datetime import datetime
        import random
        b4 = datetime(2016, 4, 1)
        af = datetime(2016, 4, 2)
        if b4 < datetime.now() < af:
            content += random.choice([
                u'喵~', u'汪~', u'poi~', u'的说~', u'呱~', u'niconiconi~',
                u'(PS:灵梦没节操——',
                u'(PS:油咖喱的脚很臭——',
                u'(PS:河童喜欢巨大的黄瓜——',
                u'(PS:妖梦是男孩子——',
                u'(PS:茨木华扇又在卖自己的本子——',
                u'(PS:幽香和天子又在做爱做的事——',
                u'(PS:藤原妹红穿的是男士胖次——',
                u'(PS:帕秋莉喜欢在房间里练习娇喘——',
                u'(PS:椛椛想要——',
                u'(PS:爱丽丝又在扎小人——',
                u'(PS:有看到小伞和盖伦在酒吧喝酒——',
                u'(PS:四季的胸还不到A罩杯——',
                u'(PS:早苗的欧派,赞——',
                u'(PS:森近霖之助昨天买了好多卫生纸——',
                u'(PS:咲夜又买了更大号的PAD——',
                u'(PS:昨天下午菜市场关门了,原因是幽幽子上午去过——',
                u'(PS:昨天琪露诺和灵乌路空比算数,灵乌路空赢了——',
                u'(PS:守矢大法好—— 天灭博丽,退博保平安—— 人在做,天在看,毫无节操留祸患—— 上网搜“10万元COS”有真相——',
            ])
            # --------

        State.interconnect.publish('speaker', [username, content])
Exemple #8
0
    def _message(self, type, msg):
        not_registered_text = (
            u'文文不认识你,不会帮你发新闻的哦。\n'
            u'回复“文文求交朋友 uid 密码”,不要带引号,文文就会认识你啦。\n'
            u'uid可以在登陆论坛或者游戏后知道,密码就是论坛的密码。\n'
            u'比如这样:\n'
            u'文文求交朋友 23333 wodemima23333\n'
            u'\n'
            u'文文帮你发新闻是要收费的,一发5节操。不过连续发的话收费会翻倍哦。'
        )

        registered_text = (
            u'哎呀呀呀,原来你是%s啊,文文认识你了。\n'
            u'只要你的节操还在,文文就会帮你发新闻~\n'
        )

        help_text = (
            u'所有在QQ群里以“`”或者“\'”开头的聊天都会被当做发新闻的请求~\n'
            u'比如这样:\n'
            u'`文文最是清正廉直!\n'
            u'\n'
            u'文文帮你发新闻是要收费的,一发5节操。不过连续发的话收费会翻倍哦。'
        )

        fail_text = (
            u'文文调查了一下你,发现你的密码填的不对!\n'
            u'快说你到底是谁!'
        )

        qq = self.uin2qq(msg['from_uin'])

        if type == 'buddy':
            send = lambda t: self.send_buddy_message(msg['from_uin'], t)
        elif type == 'sess':
            send = lambda t: self.send_sess_message(msg['id'], msg['from_uin'], t)

        uid = State.dao.get_binding(qq)
        if not uid:
            content = self._plaintext(msg['content']).strip()
            req = content.split(None, 2)
            req = [i.strip() for i in req]
            try:
                check(len(req) == 3)
                check(req[0] == u'文文求交朋友')
                check(req[1].isdigit())
            except CheckFailed:
                send(not_registered_text)
                return

            uid = int(req[1])
            pwd = req[2]

            username = None
            user = Account.find(uid)
            if not (user and Account.validate_by_password(user.dz_member, pwd)):
                send(fail_text)
                return
            username = user.username

            State.dao.set_binding(qq, uid)

            send(registered_text % username + help_text)
            return

        send(help_text)