Esempio n. 1
0
async def close_chat_and_disconnect_users( book: Book , chat: Chats ) :
	await set_state_by_id( chat.creator_id , AuthorState.action_menu.state )

	for user in chat.connected_users :
		await s( user.user_id , 'Чат перестал существовать' )
		await set_state_by_id( user.user_id , AuthorState.action_menu.state )
		if user.user_id != chat.creator_id :
			await new_book_or_review( user , None , book , need_to_add=False ,
			                          from_library=False , actions=True )
	chat.close()
Esempio n. 2
0
 def create_chat(update):
     msg = update.message
     q = Chats.objects(chat_id=msg.chat_id)
     if not q:
         new_chat = Chats(
                 chat_id=msg.chat_id,
                 title=msg.chat.title,
                 type=msg.chat.type,
                 date=msg.date
         )
         new_chat.save()
     else:
         q.update(add_to_set__users=update.message.from_user.id)
    def create_chat(user_id):

        req = request.get_json()
        utils.check_params(req, 'user2_id', 'tournament_id')

        chat = Chats.get(user_id, req['user2_id'], req['tournament_id'])
        if chat is not None:
            raise APIException('Chat already exists with id ' + str(chat.id),
                               400)

        chat = Chats(user1_id=user_id,
                     user2_id=req['user2_id'],
                     tournament_id=req['tournament_id'])
        db.session.add(chat)
        db.session.commit()

        return jsonify(chat.serialize())
def add_chat_id_to_db(owner_id, chat_id):
    """
    Функция добавления id чата в БД
    :return:
    """
    c = Chats(owner_id, chat_id)
    db.session.add(c)
    db.session.commit()
    def get_chat(user_id, user2_id=None, trmnt_id=None, chat_id=None):

        if chat_id:
            chat = Chats.query.get(chat_id)
        else:
            chat = Chats.get(user_id, user2_id, trmnt_id)
        if chat is None:
            raise APIException('Chat not found', 404)

        return jsonify(chat.serialize())
def chat():
    json = request.get_json()

    post = Chats(poll_id=json["poll_id"],
                 username=json["username"],
                 message=json["message"])
    db.session.add(post)
    db.session.commit()

    return 'added to chat'
Esempio n. 7
0
def start_mailing(bot: Bot, update: Update):
    uid = update.message.from_user.id
    message = update.message.text
    chats = Chats.select()
    for chat in chats:
        Messages.create(owner=uid,
                        text=message,
                        chat_id=chat.id,
                        send_dt=dt.now())
        bot.send_message(chat.id, message, parse_mode=ParseMode.HTML)
    bot.send_message(uid, 'Рассылку закончил')
    return ConversationHandler.END
Esempio n. 8
0
async def in_conversation( msg: types.Message , state: FSMContext ) :
	# await delete_temp_messages( state )

	# msg.text = f'{get_random_emodzi()}\n' + msg.text
	async with state.proxy() as data :
		chat = Chats.objects( id=data[ 'chat_id' ] ).first()
		if chat :
			pp( chat.smiles )
			smile = chat.smiles[ str( msg.from_user.id ) ]

			for user in chat.connected_users :
				if user.user_id != msg.from_user.id :
					await bot.send_chat_action( user.user_id , action='typing' )
					await resend_message_with_file( bot , msg , user.user_id , smile )
Esempio n. 9
0
async def accept_decline_callback( c: types.CallbackQuery , state: FSMContext ) :
	await c.answer()
	data = await state.get_data()
	# mark = get_accept_decline(data)
	#
	try :
		await c.message.delete()
	except exceptions.MessageToDeleteNotFound :
		pass

	u_id = c.from_user.id
	u = get_user( u_id )
	chat = Chats.objects( id=data[ 'chat_id' ] ).first()

	if c.data == 'accept' :

		if chat :
			print( f'user @{c.from_user.username} with id {c.from_user.id} accepted conversation ' )

			await s( u_id , 'Вы присоединились к обсуждению!' , reply_markup=simple_markup_back_end )
			u.connect_chat()
			if not chat.visited :
				await delete_temp_messages( FSMContext( storage , chat.creator_id , chat.creator_id ) )

				get_user( chat.creator_id ).update( waits_conversation=False , in_conversation=True )

				await s( chat.creator_id , in_contact ,
				         reply_markup=accept_decline_markup )
				# await creator_data.update(waiting_message_id=mes.message_id)

				chat.visited = True

			chat.connected_users.append( u )
			chat.save()
			await AuthorState.in_conversation.set()
		else :
			print(
					f'user @{c.from_user.username} with id {c.from_user.id} accepted conversation but chat does not exist' )
			await s( u_id , 'Чат уже не существует' )
			u.disconnect_chat()
	# await c.message.edit_text( 'Чат уже не существует' )

	elif c.data == 'decline' :
		print( f'user @{c.from_user.username} with id {c.from_user.id} declined conversation ' )
		# await disconnect_user_from_conversation( state )
		u.disconnect_chat()
Esempio n. 10
0
    def parse_chat_stats(self, update):
        users = Chats.objects(chat_id=update.message.chat_id).only('users').first().users
        user_stats_dict = self.get_chat_stats(update, users)
        user_stats = user_stats_dict['user_stats']
        max_messages = max(user_stats, key=lambda x: x['number_of_messages'])
        max_words = max(user_stats, key=lambda x: x['number_of_words'])
        msg_template = ("""Most messages sent: {user} with {user_msg} messages from a total of {total_msg}
Most words used: {user_maxw} with {user_words} words from a total of {total_words}""")

        return msg_template.format(
                user=self.get_user_name(max_messages['user']),
                user_msg=int(max_messages['number_of_messages']),
                total_msg=int(user_stats_dict['total_messages']),
                user_maxw=self.get_user_name(max_words['user']),
                user_words=int(max_words['number_of_words']),
                total_words=user_stats_dict['total_words']
        )
Esempio n. 11
0
async def disconnect_user_from_conversation( state: FSMContext , send_mes=True ) :
	async with state.proxy() as data :
		u = get_user( state.user )

		# print( f'user @{c.from_user.username} with id {c.from_user.id} declined conversation ' )
		chat = Chats.objects( id=data[ 'chat_id' ] ).first()
		book = get_book( data[ 'book_id' ] )
		if chat :
			if chat.creator_id == u.user_id :
				print(
						f'user @{u.username} get BACK from conversation, conversation closed because he is creator' )
				u.disconnect_chat()
				await close_chat_and_disconnect_users( book , chat )
			else :
				chat.disconnect_user( u )
		if send_mes :
			await add_to_temp( await new_book_or_review( u , None , book , need_to_add=False ,
			                                             from_library=data[ 'from_library' ] , actions=True ) , data )
Esempio n. 12
0
async def timeout_callback( loop , user_id , book_id ) :
	end_time = loop.time() + 300
	while True :
		print( datetime.datetime.now() )
		if (loop.time() + 1) >= end_time :
			break
		await asyncio.sleep( 150 )
	print( 'timer done, let\'t start connecting them!' )
	user = get_user( user_id )

	if user.waits_conversation and not user.in_conversation :
		my_chat = Chats.objects( creator_id=user_id ).first()
		my_chat.time_out()

		while True :
			chatslist = get_waiting_chats( book_id , user_id )
			pp( list( x.creator_id for x in chatslist ) )
			user = get_user( user_id )
			my_chat = Chats.objects( creator_id=user_id ).first()

			if not user.waits_conversation or user.in_conversation or not my_chat :
				print( 'func closed' )
				break
			if len( chatslist ) >= 4 :
				available_users = list( get_user( chat.creator_id ) for chat in chatslist )

				book = get_book( book_id )

				for chat in chatslist :
					await close_chat_and_disconnect_users( book , chat )

				await close_chat_and_disconnect_users( book , my_chat )

				new_chat = Chats( creator_id=user_id , book_id=book_id , invited_users=available_users )

				new_chat.get_emodzi()
				await set_chat_by_id( user_id , str( new_chat.id ) )

				await AuthorState.in_conversation.set()
				for u in available_users :
					await set_chat_by_id( u.user_id , str( new_chat.id ) )
					u_state = FSMContext( storage , u.user_id , u.user_id )
					await delete_temp_messages( u_state )
					mes = await s( u.user_id , f'Вас приглашают обсудить книгу *{book.article}*' ,
					               reply_markup=accept_decline_markup , parse_mode='Markdown' )
					await add_to_temp( mes , state=u_state )
					user.chat_waiting()
				await asyncio.create_task( timeout_callback( loop , user_id , book_id ) )
				break
			await asyncio.sleep( 10 )
			print( 'still waiting' )
Esempio n. 13
0
async def delete_active_user_from_chat( state , u_id ) :
	async with state.proxy() as data :
		if await state.get_state() == AuthorState.in_conversation.state :  # if user waited
			# remove user from query
			u = get_user( u_id )
			u.disconnect_chat()
			chat = Chats.objects( id=data[ 'chat_id' ] ).first()
			if chat :
				if u_id == chat.creator_id :
					print( 'he is creator' )
					try :
						await bot.delete_message( u_id , data[ 'waiting_message_id' ] )
					except exceptions.MessageToDeleteNotFound :
						pass

					for user in chat.connected_users :
						if user.user_id != u_id :
							await s( user.user_id , 'Создатель вышел из беседы, беседа закончена' )
						user.disconnect_chat()
					chat.close()

				else :
					chat.connected_users.remove( u )
					chat.save()
def run():

    Chats.query.delete(
    )  #Arrange the deletes in the opposite order of the models
    Voters_Table.query.delete()
    Polls.query.delete()
    Users.query.delete()

    # MYSQL database for gitpod
    db.session.execute("ALTER TABLE chats AUTO_INCREMENT = 1")
    db.session.execute("ALTER TABLE polls AUTO_INCREMENT = 1")
    db.session.execute("ALTER TABLE users AUTO_INCREMENT = 1")
    db.session.execute("ALTER TABLE voters_table AUTO_INCREMENT = 1")

    # POSTGRES database for heroku
    # db.session.execute("ALTER SEQUENCE chats_id_seq RESTART")
    # db.session.execute("ALTER SEQUENCE polls_id_seq RESTART")
    # db.session.execute("ALTER SEQUENCE users_id_seq RESTART")
    # db.session.execute("ALTER SEQUENCE voters_table_id_seq RESTART")

    now = datetime.utcnow()

    ##################
    #     USERS
    ##################
    Issac = Users(first_name='Issac',
                  last_name='Alleyne',
                  username='******',
                  password=utils.sha256('Awesom3'),
                  date_of_birth='10/22/1994',
                  email='*****@*****.**')
    db.session.add(Issac)
    Naz = Users(first_name='Nhinhoshxhy',
                last_name='Desprez',
                username='******',
                password=utils.sha256('HHH'),
                date_of_birth='1/2/1999',
                email='*****@*****.**')
    db.session.add(Naz)
    Chouerlee = Users(first_name='Chouerlee',
                      last_name='Victor',
                      username='******',
                      password=utils.sha256('Fry'),
                      date_of_birth='10/12/1997',
                      email='*****@*****.**')
    db.session.add(Chouerlee)
    Zion = Users(first_name='Zion',
                 last_name='Raymond',
                 username='******',
                 password=utils.sha256('Zee'),
                 date_of_birth='1/33/1998',
                 email='*****@*****.**')
    db.session.add(Zion)
    Rajae = Users(first_name='Rajae',
                  last_name='Lindsay',
                  username='******',
                  password=utils.sha256('$$'),
                  date_of_birth='4/4/1996',
                  email='[email protected]')
    db.session.add(Rajae)
    Anthony = Users(first_name='Anthony',
                    last_name='Smith',
                    username='******',
                    password=utils.sha256('Dez'),
                    date_of_birth='1/23/1995',
                    email='*****@*****.**')
    Hernan = Users(first_name='Hernan',
                   last_name='Garcia',
                   username='******',
                   password=utils.sha256('geek'),
                   date_of_birth='5/17/1984',
                   email='*****@*****.**')
    db.session.add(Hernan)
    Ms_Achille = Users(first_name='Classified',
                       last_name='Achille',
                       username='******',
                       password=utils.sha256('off-center'),
                       date_of_birth='5/17/1978',
                       email='*****@*****.**')
    db.session.add(Ms_Achille)

    ##################
    #     POLLS
    ##################
    db.session.add(
        Polls(
            creator_user=Chouerlee,
            poll_question="What's the best way to travel?",
            poll_description=
            "A luxury cruise, flying first class, a glamourous bullet train, a scenic drive through the country; which getaway sounds best to you?",
            info_link="",
            image_link=
            "https://images.pexels.com/photos/776030/pexels-photo-776030.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500",
            option1="Boat",
            option2="Plane",
            option3="Train",
            option4="Drive Myself"))
    db.session.add(
        Polls(
            creator_user=Issac,
            poll_question="Is the government hiding aliens in area 51?",
            poll_description=
            "If there were aliens, we'd know about it now, right? Or would we?",
            info_link="",
            image_link=
            "https://images.pexels.com/photos/365625/pexels-photo-365625.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500",
            option1="I'm a believer",
            option2="Conspiracy Theories aren't my thing",
            option3="The Government is hiding something, just not aliens",
            option4="The Government would never lie to us. Ever."))
    db.session.add(
        Polls(
            creator_user=Naz,
            poll_question="Should the drinking age be lowered to 18?",
            poll_description=
            "The drinking age is 21 everywhere in the United States, but are 18 year olds mature enough to drink responsibly?",
            info_link="https://drinkingage.procon.org/",
            image_link=
            "https://images.pexels.com/photos/696218/pexels-photo-696218.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500",
            option1="Yes",
            option2="No, it's fine the way it is",
            option3="It should be raised"))
    db.session.add(
        Polls(
            creator_user=Zion,
            poll_question="Is revenge cheating justified?",
            poll_description=
            "If you're cheated on, you're hurt, angry, and feel disrespected, and rightfully so. But do you cheat back",
            info_link="",
            image_link=
            "https://images.pexels.com/photos/3694011/pexels-photo-3694011.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500",
            option1="Yes, they have it coming",
            option2="No, two wrongs won't make things right"))
    db.session.add(
        Polls(
            creator_user=Rajae,
            poll_question="Which is the better sport?",
            poll_description=
            "Sports are a part of everyday life, whether you prefer to play, watch or both. These three are some of the most popular in America, so how do they stack against each other?",
            info_link="",
            image_link=
            "https://i2.wp.com/digiday.com/wp-content/uploads/2014/10/naenae.gif?resize=320%2C240&ssl=1",
            option1="Football. The American Version",
            option2="Basketball",
            option3="Baseball; there's a reason it's called America's Pastime.",
            option4="I don't really watch these"))
    db.session.add(
        Polls(
            creator_user=Anthony,
            poll_question="What element would you want to control?",
            poll_description=
            "Manipulating the elements is a standard superpower to have, but often quite powerful. If you could choose one of these four elements, which would you master?",
            info_link="",
            image_link=
            "https://images.pexels.com/photos/1118873/pexels-photo-1118873.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500",
            option1="Water",
            option2="Earth",
            option3="Fire",
            option4="Air"))
    db.session.add(
        Polls(
            creator_user=Hernan,
            poll_question=
            "If you could travel in time, what would you want to see?",
            poll_description=
            "A world far off or long forgotten, time travel has much appeal, but is it for you?",
            info_link="",
            image_link=
            "https://images.pexels.com/photos/552598/pexels-photo-552598.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500",
            option1="The past",
            option2="The future",
            option3="There is enough in the present"))
    db.session.add(
        Polls(
            creator_user=Ms_Achille,
            poll_question=
            "If you could have one of these superpowers, which one would you choose?",
            poll_description=
            "We've all dreamt of having superpowers and being more than ordinary; which of these abilities fits you best?",
            info_link="",
            image_link=
            "https://images.pexels.com/photos/346796/pexels-photo-346796.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500",
            option1="Invisibility",
            option2="Super Strength",
            option3="Flight",
            option4="Telekinesis"))
    db.session.add(
        Polls(
            creator_user=Naz,
            poll_question="Is this website visually appealing?",
            poll_description=
            "The person who designed it went crazy on every little detail, but honestly you don't have to like it, tell us what you think.",
            info_link="",
            image_link=
            "https://images.pexels.com/photos/57690/pexels-photo-57690.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500",
            option1="It looks very good",
            option2="It's okay",
            option3="Not great, TBH",
            option4="I honestly don't care"))

    ##################
    #  VOTERS_TABLE
    ##################

    db.session.add(
        Voters_Table(user_id=1,
                     poll_id=1,
                     username="******",
                     poll_name="What's the best way to travel?",
                     option_picked="Boat"))
    db.session.add(
        Voters_Table(user_id=2,
                     poll_id=1,
                     username="******",
                     poll_name="What's the best way to travel?",
                     option_picked="Boat"))
    db.session.add(
        Voters_Table(user_id=3,
                     poll_id=1,
                     username="******",
                     poll_name="What's the best way to travel?",
                     option_picked="Plane"))
    db.session.add(
        Voters_Table(user_id=4,
                     poll_id=1,
                     username="******",
                     poll_name="What's the best way to travel?",
                     option_picked="Drive Myself"))
    db.session.add(
        Voters_Table(user_id=5,
                     poll_id=1,
                     username="******",
                     poll_name="What's the best way to travel?",
                     option_picked="Boat"))
    db.session.add(
        Voters_Table(user_id=6,
                     poll_id=1,
                     username="******",
                     poll_name="What's the best way to travel?",
                     option_picked="Plane"))
    db.session.add(
        Voters_Table(user_id=7,
                     poll_id=1,
                     username="******",
                     poll_name="What's the best way to travel?",
                     option_picked="Drive Myself"))
    db.session.add(
        Voters_Table(user_id=8,
                     poll_id=1,
                     username="******",
                     poll_name="What's the best way to travel?",
                     option_picked="Plane"))
    #########################################
    db.session.add(
        Voters_Table(
            user_id=1,
            poll_id=2,
            username="******",
            poll_name="Is the government hiding aliens in area 51?",
            option_picked="The Government is hiding something, just not aliens"
        ))
    db.session.add(
        Voters_Table(user_id=2,
                     poll_id=2,
                     username="******",
                     poll_name="Is the government hiding aliens in area 51?",
                     option_picked="I'm a believer"))
    db.session.add(
        Voters_Table(user_id=3,
                     poll_id=2,
                     username="******",
                     poll_name="Is the government hiding aliens in area 51?",
                     option_picked="Conspiracy Theories aren't my thing"))
    db.session.add(
        Voters_Table(
            user_id=4,
            poll_id=2,
            username="******",
            poll_name="Is the government hiding aliens in area 51?",
            option_picked="The Government would never lie to us. Ever."))
    db.session.add(
        Voters_Table(
            user_id=5,
            poll_id=2,
            username="******",
            poll_name="Is the government hiding aliens in area 51?",
            option_picked="The Government would never lie to us. Ever."))
    db.session.add(
        Voters_Table(user_id=6,
                     poll_id=2,
                     username="******",
                     poll_name="Is the government hiding aliens in area 51?",
                     option_picked="I'm a believer"))
    db.session.add(
        Voters_Table(user_id=7,
                     poll_id=2,
                     username="******",
                     poll_name="Is the government hiding aliens in area 51?",
                     option_picked="I'm a believer"))
    db.session.add(
        Voters_Table(
            user_id=8,
            poll_id=2,
            username="******",
            poll_name="Is the government hiding aliens in area 51?",
            option_picked="The Government is hiding something, just not aliens"
        ))
    ######################################
    db.session.add(
        Voters_Table(user_id=1,
                     poll_id=3,
                     username="******",
                     poll_name="Should the drinking age be lowered to 18?",
                     option_picked="It should be raised"))
    db.session.add(
        Voters_Table(user_id=2,
                     poll_id=3,
                     username="******",
                     poll_name="Should the drinking age be lowered to 18?",
                     option_picked="Yes"))
    db.session.add(
        Voters_Table(user_id=3,
                     poll_id=3,
                     username="******",
                     poll_name="Should the drinking age be lowered to 18?",
                     option_picked="No, it's fine the way it is"))
    db.session.add(
        Voters_Table(user_id=4,
                     poll_id=3,
                     username="******",
                     poll_name="Should the drinking age be lowered to 18?",
                     option_picked="Yes"))
    db.session.add(
        Voters_Table(user_id=5,
                     poll_id=3,
                     username="******",
                     poll_name="Should the drinking age be lowered to 18?",
                     option_picked="No, it's fine the way it is"))
    db.session.add(
        Voters_Table(user_id=6,
                     poll_id=3,
                     username="******",
                     poll_name="Should the drinking age be lowered to 18?",
                     option_picked="No, it's fine the way it is"))
    db.session.add(
        Voters_Table(user_id=7,
                     poll_id=3,
                     username="******",
                     poll_name="Should the drinking age be lowered to 18?",
                     option_picked="Yes"))
    db.session.add(
        Voters_Table(user_id=8,
                     poll_id=3,
                     username="******",
                     poll_name="Should the drinking age be lowered to 18?",
                     option_picked="It should be raised"))
    #######################################
    db.session.add(
        Voters_Table(user_id=1,
                     poll_id=4,
                     username="******",
                     poll_name="Is revenge cheating justified?",
                     option_picked="No, two wrongs won't make things right"))
    db.session.add(
        Voters_Table(user_id=2,
                     poll_id=4,
                     username="******",
                     poll_name="Is revenge cheating justified?",
                     option_picked="Yes, they have it coming"))
    db.session.add(
        Voters_Table(user_id=3,
                     poll_id=4,
                     username="******",
                     poll_name="Is revenge cheating justified?",
                     option_picked="Yes, they have it coming"))
    db.session.add(
        Voters_Table(user_id=4,
                     poll_id=4,
                     username="******",
                     poll_name="Is revenge cheating justified?",
                     option_picked="Yes, they have it coming"))
    db.session.add(
        Voters_Table(user_id=5,
                     poll_id=4,
                     username="******",
                     poll_name="Is revenge cheating justified?",
                     option_picked="No, two wrongs won't make things right"))
    db.session.add(
        Voters_Table(user_id=6,
                     poll_id=4,
                     username="******",
                     poll_name="Is revenge cheating justified?",
                     option_picked="Yes, they have it coming"))
    db.session.add(
        Voters_Table(user_id=7,
                     poll_id=4,
                     username="******",
                     poll_name="Is revenge cheating justified?",
                     option_picked="No, two wrongs won't make things right"))
    db.session.add(
        Voters_Table(user_id=8,
                     poll_id=4,
                     username="******",
                     poll_name="Is revenge cheating justified?",
                     option_picked="Yes, they have it coming"))
    ###########################################
    db.session.add(
        Voters_Table(user_id=1,
                     poll_id=5,
                     username="******",
                     poll_name="Which is the better sport?",
                     option_picked="Football. The American Version"))
    db.session.add(
        Voters_Table(user_id=2,
                     poll_id=5,
                     username="******",
                     poll_name="Which is the better sport?",
                     option_picked="Basketball"))
    db.session.add(
        Voters_Table(user_id=3,
                     poll_id=5,
                     username="******",
                     poll_name="Which is the better sport?",
                     option_picked="I don't really watch these"))
    db.session.add(
        Voters_Table(user_id=4,
                     poll_id=5,
                     username="******",
                     poll_name="Which is the better sport?",
                     option_picked="Basketball"))
    db.session.add(
        Voters_Table(user_id=5,
                     poll_id=5,
                     username="******",
                     poll_name="Which is the better sport?",
                     option_picked="I don't really watch these"))
    db.session.add(
        Voters_Table(user_id=6,
                     poll_id=5,
                     username="******",
                     poll_name="Which is the better sport?",
                     option_picked="Basketball"))
    db.session.add(
        Voters_Table(
            user_id=7,
            poll_id=5,
            username="******",
            poll_name="Which is the better sport?",
            option_picked=
            "Baseball; there's a reason it's called America's Pastime."))
    db.session.add(
        Voters_Table(user_id=8,
                     poll_id=5,
                     username="******",
                     poll_name="Which is the better sport?",
                     option_picked="Football. The American Version"))
    ######################################
    db.session.add(
        Voters_Table(user_id=1,
                     poll_id=6,
                     username="******",
                     poll_name="What element would you want to control?",
                     option_picked="Earth"))
    db.session.add(
        Voters_Table(user_id=2,
                     poll_id=6,
                     username="******",
                     poll_name="What element would you want to control?",
                     option_picked="Air"))
    db.session.add(
        Voters_Table(user_id=3,
                     poll_id=6,
                     username="******",
                     poll_name="What element would you want to control?",
                     option_picked="Water"))
    db.session.add(
        Voters_Table(user_id=4,
                     poll_id=6,
                     username="******",
                     poll_name="What element would you want to control?",
                     option_picked="Water"))
    db.session.add(
        Voters_Table(user_id=5,
                     poll_id=6,
                     username="******",
                     poll_name="What element would you want to control?",
                     option_picked="Fire"))
    db.session.add(
        Voters_Table(user_id=6,
                     poll_id=6,
                     username="******",
                     poll_name="What element would you want to control?",
                     option_picked="Fire"))
    db.session.add(
        Voters_Table(user_id=7,
                     poll_id=6,
                     username="******",
                     poll_name="What element would you want to control?",
                     option_picked="Air"))
    db.session.add(
        Voters_Table(user_id=8,
                     poll_id=6,
                     username="******",
                     poll_name="What element would you want to control?",
                     option_picked="Fire"))
    ######################################
    db.session.add(
        Voters_Table(
            user_id=1,
            poll_id=7,
            username="******",
            poll_name=
            "If you could travel in time, what would you want to see?",
            option_picked="The past"))
    db.session.add(
        Voters_Table(
            user_id=2,
            poll_id=7,
            username="******",
            poll_name=
            "If you could travel in time, what would you want to see?",
            option_picked="There is enough in the present"))
    db.session.add(
        Voters_Table(
            user_id=3,
            poll_id=7,
            username="******",
            poll_name=
            "If you could travel in time, what would you want to see?",
            option_picked="There is enough in the present"))
    db.session.add(
        Voters_Table(
            user_id=4,
            poll_id=7,
            username="******",
            poll_name=
            "If you could travel in time, what would you want to see?",
            option_picked="The past"))
    db.session.add(
        Voters_Table(
            user_id=5,
            poll_id=7,
            username="******",
            poll_name=
            "If you could travel in time, what would you want to see?",
            option_picked="The future"))
    db.session.add(
        Voters_Table(
            user_id=6,
            poll_id=7,
            username="******",
            poll_name=
            "If you could travel in time, what would you want to see?",
            option_picked="The past"))
    db.session.add(
        Voters_Table(
            user_id=7,
            poll_id=7,
            username="******",
            poll_name=
            "If you could travel in time, what would you want to see?",
            option_picked="There is enough in the present"))
    db.session.add(
        Voters_Table(
            user_id=8,
            poll_id=7,
            username="******",
            poll_name=
            "If you could travel in time, what would you want to see?",
            option_picked="The future"))
    ######################################
    db.session.add(
        Voters_Table(
            user_id=1,
            poll_id=8,
            username="******",
            poll_name=
            "If you could have one of these superpowers, which one would you choose?",
            option_picked="Telekinesis"))
    db.session.add(
        Voters_Table(
            user_id=2,
            poll_id=8,
            username="******",
            poll_name=
            "If you could have one of these superpowers, which one would you choose?",
            option_picked="Super Strength"))
    db.session.add(
        Voters_Table(
            user_id=3,
            poll_id=8,
            username="******",
            poll_name=
            "If you could have one of these superpowers, which one would you choose?",
            option_picked="Flight"))
    db.session.add(
        Voters_Table(
            user_id=4,
            poll_id=8,
            username="******",
            poll_name=
            "If you could have one of these superpowers, which one would you choose?",
            option_picked="Flight"))
    db.session.add(
        Voters_Table(
            user_id=5,
            poll_id=8,
            username="******",
            poll_name=
            "If you could have one of these superpowers, which one would you choose?",
            option_picked="Super Strength"))
    db.session.add(
        Voters_Table(
            user_id=6,
            poll_id=8,
            username="******",
            poll_name=
            "If you could have one of these superpowers, which one would you choose?",
            option_picked="Invisibility"))
    db.session.add(
        Voters_Table(
            user_id=7,
            poll_id=8,
            username="******",
            poll_name=
            "If you could have one of these superpowers, which one would you choose?",
            option_picked="Telekinesis"))
    db.session.add(
        Voters_Table(
            user_id=8,
            poll_id=8,
            username="******",
            poll_name=
            "If you could have one of these superpowers, which one would you choose?",
            option_picked="Invisibility"))

    ##################
    #     CHATS
    ##################

    db.session.add(
        Chats(poll_id=1,
              username="******",
              message="'Sup",
              created_at=now + timedelta(minutes=1)))
    db.session.add(
        Chats(poll_id=1,
              username="******",
              message="Konichiwa",
              created_at=now + timedelta(minutes=2)))
    db.session.add(
        Chats(poll_id=1,
              username="******",
              message="Hey",
              created_at=now + timedelta(minutes=3)))
    db.session.add(
        Chats(poll_id=1,
              username="******",
              message="Dude",
              created_at=now + timedelta(minutes=4)))
    db.session.add(
        Chats(poll_id=1,
              username="******",
              message="Yo",
              created_at=now + timedelta(minutes=5)))
    db.session.add(
        Chats(poll_id=1,
              username="******",
              message="Hi",
              created_at=now + timedelta(minutes=6)))
    ############################################
    db.session.add(
        Chats(poll_id=2,
              username="******",
              message="Konichiwa, kolis10",
              created_at=now + timedelta(minutes=1)))
    db.session.add(
        Chats(poll_id=2,
              username="******",
              message="'Sup, Naz",
              created_at=now + timedelta(minutes=2)))
    db.session.add(
        Chats(poll_id=2,
              username="******",
              message="Hi, Curly-Fry",
              created_at=now + timedelta(minutes=3)))
    db.session.add(
        Chats(poll_id=2,
              username="******",
              message="Yo, Coder",
              created_at=now + timedelta(minutes=4)))
    db.session.add(
        Chats(poll_id=2,
              username="******",
              message="Dude, Rager",
              created_at=now + timedelta(minutes=5)))
    db.session.add(
        Chats(poll_id=2,
              username="******",
              message="Hey, Tony",
              created_at=now + timedelta(minutes=6)))
    db.session.commit()
    return 'seeds ran successfully'
Esempio n. 15
0
def run():

    #Arrange the deletes in the opposite order of the models
    Invites.query.delete()
    Messages.query.delete()
    Chats.query.delete()

    # MYSQL database for gitpod
    db.session.execute("ALTER TABLE invites AUTO_INCREMENT = 1")
    db.session.execute("ALTER TABLE messages AUTO_INCREMENT = 1")
    db.session.execute("ALTER TABLE chats AUTO_INCREMENT = 1")

    # POSTGRES database for heroku
    # db.session.execute("ALTER SEQUENCE messages_id_seq RESTART")
    # db.session.execute("ALTER SEQUENCE chats_id_seq RESTART")

    db.session.add(Chats())
    db.session.add(Chats())
    db.session.add(Chats())
    db.session.add(Chats())
    db.session.add(Chats())
    db.session.add(Chats())

    now = datetime.utcnow()

    ##################
    #     INVITES
    ##################
    db.session.add(Invites(chat_id=1, username="******"))
    db.session.add(Invites(chat_id=1, username="******"))

    ##################
    #     MESSAGES
    ##################
    db.session.add(
        Messages(chat_id=1,
                 writer_username="******",
                 message="'Sup",
                 created_at=now))
    db.session.add(
        Messages(chat_id=2,
                 writer_username="******",
                 message="Konichiwa",
                 created_at=now))
    db.session.add(
        Messages(chat_id=3,
                 writer_username="******",
                 message="Hey",
                 created_at=now))
    db.session.add(
        Messages(chat_id=4,
                 writer_username="******",
                 message="Dude",
                 created_at=now))
    db.session.add(
        Messages(chat_id=5,
                 writer_username="******",
                 message="Yo",
                 created_at=now))
    db.session.add(
        Messages(chat_id=6,
                 writer_username="******",
                 message="Hi",
                 created_at=now))
    ############################################
    db.session.add(
        Messages(chat_id=1,
                 writer_username="******",
                 message="Konichiwa, kolis10",
                 created_at=now + timedelta(minutes=2)))
    db.session.add(
        Messages(chat_id=2,
                 writer_username="******",
                 message="'Sup, Naz",
                 created_at=now + timedelta(minutes=2)))
    db.session.add(
        Messages(chat_id=3,
                 writer_username="******",
                 message="Hi, Curly-Fry",
                 created_at=now + timedelta(minutes=2)))
    db.session.add(
        Messages(chat_id=4,
                 writer_username="******",
                 message="Yo, Coder",
                 created_at=now + timedelta(minutes=2)))
    db.session.add(
        Messages(chat_id=5,
                 writer_username="******",
                 message="Dude, Rager",
                 created_at=now + timedelta(minutes=2)))
    db.session.add(
        Messages(chat_id=6,
                 writer_username="******",
                 message="Hey, Tony",
                 created_at=now + timedelta(minutes=2)))

    db.session.commit()
    return 'seeds ran successfully'
Esempio n. 16
0
def chat_maker():
    

    db.session.add(Chats())
    db.session.commit()
    return 'chat created'
Esempio n. 17
0
def get_and_save_chat(bot: Bot, update: Update):
    if update.message.new_chat_member == bot.get_me():
        chat_id = update.effective_chat.id
        Chats.create(id=chat_id)
Esempio n. 18
0
async def action_menu( c: types.CallbackQuery , state: FSMContext ) :
	# await delete_temp_messages( state )

	u_id = c.from_user.id
	msg_id = c.message.message_id
	try :
		await c.answer()
	except :
		pass

	if c.data == 'go_into_conversation' :
		await c.message.delete()
		# await bot.delete_message( u_id , msg_id )
		async with state.proxy() as data :
			# userqueue should not include users who have already in_conversation state and
			print( data[ 'book_id' ] )
			# we should optimize function that will get all "good" users to us
			user = get_user( u_id )
			user.chat_waiting()
			# if we have user that waits, then connect them, else add new user to queue

			book = get_book( data[ 'book_id' ] )
			available_users = get_available_users_with_book( u_id , book )

			new_chat = Chats( creator_id=c.from_user.id , book_id=data[ 'book_id' ] , invited_users=available_users )

			new_chat.get_emodzi()
			data[ 'chat_id' ] = str( new_chat.id )

			for user in available_users :
				await s( user.user_id , f'Вас приглашают обсудить книгу *{book.article}*' ,
				         reply_markup=accept_decline_markup , parse_mode='Markdown' )
				await state.storage.update_data( chat=user.user_id , user=user.user_id , chat_id=str( new_chat.id ) )
				user.chat_waiting()

			mes = await s( u_id , 'Идет поиск собеседника...' , reply_markup=back_inline_markup , )
			await add_to_temp( mes , data )
			await AuthorState.in_conversation.set()

			print( f'user @{c.from_user.username} waits conversation for book {book.article}' )

		task = asyncio.create_task( timeout_callback( loop , u_id , str( book.id ) ) )
		await task

	elif c.data == 'watch_reviews_from' :
		print( f'user @{c.from_user.username} watches types of reviews ' )
		await AuthorState.watch_reviews_from.set()
		await bot.edit_message_text( 'У нас много отзывов, выберите' , u_id , msg_id ,
		                             reply_markup=inline_markup_reviews )



	elif c.data == 'delete' :

		async with state.proxy() as data :
			book = Book.objects( id=data[ 'book_id' ] ).first()
			print( f'user @{c.from_user.username} deleted book {book.article}' )

			u = get_user( u_id )
			u.books.remove( book )
			u.save()
			await add_to_temp( await new_book_or_review( u , c , book , need_to_add=False , actions=True ,
			                                             from_library=data[ 'from_library' ] ) , data )
Esempio n. 19
0
def delete_chat(bot: Bot, update: Update):
    if update.message.left_chat_member == bot.get_me():
        chat_id = update.effective_chat.id
        c = Chats.get(Chats.id == chat_id)
        c.delete_instance()
Esempio n. 20
0
def get_waiting_chats( book_id , creator_id ) :
	return Chats.get_not_visited( book_id=book_id , creator_id__ne=creator_id )[ :5 ]