コード例 #1
0
def set_privacy(bot, update):
    chat_id = update.message.chat_id
    chat_type = update.message.chat.type
    user_id = update.message.from_user.id
    msg_id = update.message.message_id

    user = User.get(user_id)

    if user:
        privacy = user.public

        if privacy:
            public = False
            msg = 'Your statistics is *private*'
        else:
            public = True
            msg = 'Your statistics is *public*\n\n' \
                  '{0}/user/{1}'.format(CONFIG['site_url'], user_id)

        User.update(user_id, {'public': public})
        cache.delete('user_{}'.format(user_id))
    else:
        msg = 'User not found'

    bot.sendMessage(chat_id,
                    msg,
                    parse_mode=ParseMode.MARKDOWN,
                    reply_to_message_id=msg_id)
コード例 #2
0
    def get(uid):
        cached = cache.get('user_{}'.format(uid))

        if cached:
            return cached
        else:
            q = db.query(User) \
                .filter(User.uid == uid) \
                .limit(1) \
                .all()
            if q:
                cache.set('user_{}'.format(uid), q[0])
                cache.delete('web_user_{}'.format(uid))
                return q[0]
            else:
                return False
コード例 #3
0
    def get(cid):
        cached = cache.get('chat_{}'.format(cid))

        if cached:
            return cached
        else:
            q = db.query(Chat) \
                .filter(Chat.cid == cid) \
                .order_by(Chat.id.desc()) \
                .limit(1) \
                .all()
            if q:
                cache.set('chat_{}'.format(cid), q[0])
                cache.delete('web_chat_{}'.format(cid))
                return q[0]
            else:
                return False
コード例 #4
0
    def add(self, cid, title, public_link=''):
        chat = self.get(cid)

        if chat:
            if chat.title != title:
                self.update(cid, {'title': title})

            if chat.public_link != public_link:
                self.update(cid, {'public_link': public_link})
        else:
            db.add(Chat(cid=cid,
                        title=title,
                        public_link=public_link))

        cache.set('chat_{}'.format(cid),
                  Chat(cid=cid, title=title))
        cache.delete('web_chat_{}'.format(cid))
        db.commit()
コード例 #5
0
def update_to_supergroup(bot, update):
    old_id = update.message.migrate_from_chat_id
    new_id = update.message.chat_id
    user_id = update.message.from_user.id

    if old_id:
        UserStat.update(user_id, old_id, {'cid': new_id})
        Entity.update_all(old_id, {'cid': new_id})
        Chat.update(old_id, {'cid': new_id})

        # Update all rows in chat_stats
        for c in db.query(ChatStat)\
                .filter(ChatStat.cid == old_id)\
                .all():
            c.cid = new_id
        db.commit()

        bot.sendMessage(new_id, 'Group was updated to supergroup')
        cache.delete('last_{}'.format(old_id))
        logger.info('Group {} was updated to supergroup {}'.format(
            old_id, new_id))
コード例 #6
0
    def add(self, uid, username, fullname):
        user = self.get(uid)
        update = {}

        if user:
            if user.username != username:
                update['username'] = username

            if user.fullname != fullname:
                update['fullname'] = fullname

            if update:
                self.update(uid, update)
        else:
            db.add(User(uid=uid,
                        username=username,
                        fullname=fullname))
            db.commit()

        cache.set('user_'.format(uid), User(uid=uid,
                                            username=username,
                                            fullname=fullname))
        cache.delete('web_user_{}'.format(uid))
コード例 #7
0
def refresh_flags():
    key = get_db_flags.make_cache_key()
    cache.delete(key)
コード例 #8
0
ファイル: feature_flag.py プロジェクト: emfcamp/Website
def refresh_flags():
    key = get_db_flags.make_cache_key()
    cache.delete(key)
コード例 #9
0
def refresh_states():
    key = get_states.make_cache_key()
    cache.delete(key)
コード例 #10
0
ファイル: cache.py プロジェクト: Hazel1603/awesomediary
def clear_from_order(user: User, session_id):
    orders_key = __current_orders_key(user, session_id)
    cache.delete(orders_key)
コード例 #11
0
ファイル: site_state.py プロジェクト: bfirsh/Website
def refresh_states():
    key = get_states.make_cache_key()
    cache.delete(key)