Esempio n. 1
0
    def delete(self):
        '''
            刪除關鍵字
        '''
        if self.key is None:
            return '格式:\n刪除=<關鍵字>'

        self._count({'調教': 1})  #紀錄次數

        if self.key != text['名稱'] and self.key[:2] == text['名稱']:
            self.key = self.key[2:].strip(' \n')

        self.key = self.key.lower()
        reply_message = [
            '%s 刪除 <%s>' % (self.user.name if self.user else '', self.key)
        ]

        try:
            if self.group:
                if UserKeyword.delete(self.group_id, self.user_id, self.key):
                    reply_message.append(' 成功')
            if self.user:
                if UserKeyword.delete(self.user_id, self.user_id, self.key):
                    reply_message.append(' 成功')

        except Exception as e:
            return '刪除失敗: %s' % str(e)

        return ''.join(reply_message) if len(reply_message) > 1 else '喵喵喵? 愛醬不記得<%s>' % (self.key) \
            + '\n\n使用「網頁設定」更好操作'
Esempio n. 2
0
def event_delete(bot_id, group_id, user_id, message, key, value, **argv):
    MessageLogs.add(group_id, user_id, nAIset=1)  #紀錄次數
    if key is None:
        return '格式:\n刪除=<關鍵字>'

    reply_message = ['<%s>刪除了喔 ' % (key)]

    if group_id is not None and UserKeyword.delete(group_id, key):
        reply_message.append('(群組)')

    if user_id is not None and UserKeyword.delete(user_id, key):
        reply_message.append('(個人)')

    return ''.join(
        reply_message) if len(reply_message) > 1 else '喵喵喵? 愛醬不記得<%s>' % (key)
Esempio n. 3
0
def api_keyword(method):
    if 'token' not in session:
        abort(400)

    uid = session['uid'] #request.args.get('user_id')
    wd = WebUI.query.get(uid)
    keyword_mode = request.json.get('mode')
    _id = uid if keyword_mode == '個人' else wd.gid if wd and (datetime.now()-wd.gid_timeout).total_seconds() < 0 else None
    
        
    if method == 'get':
        if _id is None:
            return jsonify({
                'result':[],
                'total':0,
            })

        keywords = UserKeyword.get(_id)
        page = int(request.json.get('page', 1)) - 1
        length = int(request.json.get('length', len(keywords)))
        search = request.json.get('search', '')

        keywords.reverse()

        results = []
        for row in keywords:
            if search == '' or search in row.keyword or search in row.reply:
                results.append({
                    #'id':row._id,
                    'keyword':row.keyword,
                    'reply':row.reply,
                })

        return jsonify({
            'result':results[page*length : page*length+length],
            'total':len(results),
        })

    if method == 'add':
        keyword = request.json.get('keyword')
        reply = request.json.get('reply')

        try:
            UserKeyword.add_and_update(_id, uid, keyword, reply)
            db.session.commit()

            return 'ok'
        except Exception as e:
            abort(400)
            abort(Response(str(e)))

    if method == 'edit':
        old_keyword = request.json.get('old_keyword')
        keyword = request.json.get('keyword')
        reply = request.json.get('reply')

        try:
            if UserKeyword.add_and_update(_id, uid, keyword, reply):
                UserKeyword.delete(_id, uid, old_keyword)
            db.session.commit()

            return 'ok'
        except Exception as e:
            abort(400)
            abort(Response(str(e)))
        
    if method == 'delete':
        keyword = request.json.get('keyword')

        try:
            UserKeyword.delete(_id, uid, keyword)
            db.session.commit()

            return 'ok'
        except Exception as e:
            abort(400)
            abort(Response(str(e)))