def post(self): user_id = self.get_argument('user_id') text = self.get_argument('text', '') room_id = self.get_argument('room_id') video = self.get_argument('video', '') images = self.get_argument('images', '[]') if not room_id: return self.error(MISSING_PARAMS) if filter.check_sensitive(text): return self.error(SENSITIVE_WORD_EXISTS) user = User.get(user_id) if not user: return self.error(USER_NOT_FOUND) room_user = RoomUser.get_by_room_and_user(room_id, user_id) if not user.super_user: if not room_user: return self.error(ACCESS_NOT_ALLOWED) if int(room_user.status) == ROOM_USER_SILENT: return self.error(USER_IN_ROOM_SILENT_LIST) try: posts = Posts.add(user_id, room_id, text, images, video, room_user.status) except Exception as e: logger.error(u'添加帖子内容失败。Error:[%s]' % e) return self.error(SYSTEM_ERROR) handle_daily_create_content.delay(user_id, posts.id) return self.render({'status': 0, 'data': posts.jsonify()})
def post(self): try: room_id = self.get_argument('room_id') user_id = self.get_argument('user_id') silent_user_id = self.get_argument('silent_user_id') except MissingArgumentError: return self.error(MISSING_PARAMS) set_time = datetime.now() operator = User.get(user_id) silent_user = User.get(silent_user_id) if not silent_user: return self.error(USER_NOT_FOUND) room = Room.get(room_id) if not room: return self.error(ROOM_NOT_FOUND) room_operator = RoomUser.get_by_room_and_user(room_id, user_id) room_silent_user = RoomUser.get_by_room_and_user( room_id, silent_user_id) operator_status = room_operator.status if not room_operator.has_room_user_handle_access(room_silent_user): return self.error(ACCESS_NOT_ALLOWED) try: RoomUser.set_user_silent(room_id, silent_user_id, set_time) except Exception as e: logger.error(u'用户房间禁言失败。User:[%s], Room:[%s], Error:[%s]' % (silent_user_id, room_id, e)) return self.error(SYSTEM_ERROR) self.render({ 'status': 0, }) room_silent_user_notify.delay(operator, operator_status, room, silent_user) # scheduler = TornadoScheduler() # scheduler.add_jobstore('redis', jobs_key='room_user:silent:jobs', run_times_key='room_user:remove_silent') run_date = set_time + timedelta(days=1) tornado_scheduler.add_job( remove_room_silent_user, 'date', run_date=run_date, args=[room_id, user_id, room_silent_user.status]) # scheduler.start() return
def jsonify(self, user=None): from starmachine.model.content.content_like import ContentLiked options = VoteOption.gets_option_by_vote(self.id) data = { 'id': self.id, 'creator': { 'id': self.creator.id, 'name': self.creator.user_name, 'avatar': self.creator.avatar_url, }, 'name': self.name, 'deadline': self.deadline.strftime('%Y-%m-%d %H:%M:%S'), 'create_time': self.create_time if isinstance(self.create_time, basestring) else self.create_time.strftime('%Y-%m-%d %H:%M:%S'), 'options': [option.jsonify() for option in options], 'content_type': VOTE_TYPE, 'reward_amount': self.reward_amount, 'like_amount': self.like_amount, 'comment_amount': self.comment_amount, 'reward_user_amount': self.reward_user_amount, 'voted_amount': self.voted_amount, 'expired': self.expired, 'robed_user_amount': 0, } if user: data.update({ 'has_liked': bool(ContentLiked.has_liked(self.id, user.id)), 'has_voted': bool(VoteResult.has_voted(self.id, user.id)), 'has_robed': False, 'has_delivery': False, }) room_user = RoomUser.get_by_room_and_user(self.room_id, user.id) if room_user: data.update({ 'room_user_status': room_user.status, }) return data
def post(self): try: user_id = self.get_argument('user_id') room_id = self.get_argument('room_id') welfare_type = self.get_argument('welfare_type', WELFARE_TYPE_SPECIAL) price = float(self.get_argument('price')) count = int(self.get_argument('count')) name = self.get_argument('name') images = self.get_argument('images') start_time = self.get_argument('start_time') deadline = self.get_argument('deadline') except MissingArgumentError: return self.error(MISSING_PARAMS) user = User.get(user_id) room = Room.get(room_id) if not room: return self.error(ROOM_NOT_FOUND) star_fund = StarFund.get_by_room(room_id) amount = price * count + count * WELFARE_POSTAGE if float(star_fund.balance) < amount: return self.error(ROOM_STAR_FUND_NOT_ENOUGH) room_user = RoomUser.get_by_room_and_user(room_id, user_id) if not room_user or not int( room_user.status) in (ROOM_USER_ADMIN, ROOM_USER_CREATOR): return self.error(ACCESS_NOT_ALLOWED) try: welfare = Welfare.add(user_id, room_id, welfare_type, price, count, name, start_time, deadline, images, room_user.status, amount) except Exception as e: logger.error(u'创建福利失败。Error:[%s]' % e) return self.error(SYSTEM_ERROR) self.render({ 'status': 0, 'data': welfare.jsonify(), }) handle_daily_create_welfare.delay(user_id, welfare.id) welfare_created_notify.delay(room, welfare) # scheduler = TornadoScheduler() # scheduler.add_jobstore('redis', jobs_key='welfare:jobs', run_times_key='welfare:deadline') # tornado_scheduler.add_jobstore('redis', jobs_key='welfare:jobs', run_times_key='welfare:deadline') tornado_scheduler.add_job(welfare_end_notify, 'date', run_date=welfare.deadline, args=[welfare]) return
def post(self): try: user_id = self.get_argument('user_id') room_id = self.get_argument('room_id') name = self.get_argument('name') deadline = self.get_argument('deadline') options = self.get_argument('options') options = json.loads(options) except (MissingArgumentError, TypeError): return self.error(MISSING_PARAMS) if filter.check_sensitive(name): return self.error(SENSITIVE_WORD_EXISTS) for op in options: if filter.check_sensitive(op): return self.error(SENSITIVE_WORD_EXISTS) if len(op) > 24: return self.error(OPTION_TEXT_TOO_LONG) user = User.get(user_id) if not user: return self.error(USER_NOT_FOUND) room = Room.get(room_id) if not room: return self.error(ROOM_NOT_FOUND) room_user = RoomUser.get_by_room_and_user(room_id, user_id) if not user.super_user: if not room_user: return self.error(ACCESS_NOT_ALLOWED) if int(room_user.status) == ROOM_USER_SILENT: return self.error(USER_IN_ROOM_SILENT_LIST) try: vote = Vote.add(user_id, room_id, name, deadline, options, room_user.status) except Exception as e: logger.error(u'添加投票失败。Error:[%s]' % e) return self.error(SYSTEM_ERROR) handle_daily_create_content.delay(user_id, vote.id) return self.render({ 'status': 0, 'data': vote.jsonify(), })
def post(self): try: room_id = self.get_argument('room_id') user_id = self.get_argument('user_id') remove_user_id = self.get_argument('remove_user_id') except MissingArgumentError: return self.error(MISSING_PARAMS) operator = User.get(user_id) remove_user = User.get(remove_user_id) if not remove_user: return self.error(USER_NOT_FOUND) room = Room.get(room_id) if not room: return self.error(ROOM_NOT_FOUND) room_operator = RoomUser.get_by_room_and_user(room_id, user_id) room_remove_user = RoomUser.get_by_room_and_user( room_id, remove_user_id) if not room_operator.has_room_user_handle_access(room_remove_user): return self.error(ACCESS_NOT_ALLOWED) try: RoomUser.remove_and_black_user(room_id, remove_user_id) except Exception as e: logger.error(u'房间删除拉黑用户失败。User:[%s], Room:[%s], Error:[%s]' % (remove_user_id, room_id, e)) return self.error(SYSTEM_ERROR) self.render({ 'status': 0, }) room_remove_user_notify(operator, room_operator.status, room, remove_user) return
# coding: utf-8 from starmachine.model.content import Content from starmachine.model.room import Room from starmachine.model.room_user import RoomUser contents = Content.gets_all() for content in contents: room = Room.get(content.room_id) room_id = content.room_id user_id = content.creator_id room_user = RoomUser.get_by_room_and_user(room_id, user_id) if not room_user: content.update(room_user_status=1) else: content.update(room_user_status=room_user.status) room.update(last_content_updated=content.create_time)