Beispiel #1
0
def inline_query(msg):
    if msg['query'] == '':
        db = dbc()
        if str(msg['from']['id']) in db:
            articles = inline(msg, bot)
        else:
            articles = []
        bot.answerInlineQuery(msg['id'], results=articles, is_personal=True, cache_time=0)
    elif msg['query'] != '':
        db = dbc()
        if str(msg['from']['id']) in db:
            articles = inline(msg, bot)
        else:
            articles = []
        result = lyricspy.auto(msg['query'])
        for a in result:
            teclado = InlineKeyboardMarkup(inline_keyboard=[
                [dict(text='Aguarde...', callback_data='a')]
            ])
            articles.append(InlineQueryResultArticle(
                id=a['link'],
                title=f'{a["musica"]} - {a["autor"]}',
                thumb_url='https://piics.ml/i/010.png',
                input_message_content=InputTextMessageContent(
                    message_text='Aguarde...',
                    parse_mode='markdown', disable_web_page_preview=True),
                reply_markup=teclado)
            )
        if not articles:
            articles = [InlineQueryResultArticle(id='a', title=f'sem resultado',
                                                 input_message_content=InputTextMessageContent(
                                                     message_text=f"sem resultado para {msg['query']}"))]
        bot.answerInlineQuery(msg['id'], results=articles, is_personal=True, cache_time=0)
 def update(account, single_personnel_id, data):
     # Mongo
     db = dbc().db
     personnel = db.personnel
     single_personnel = personnel.find_one(
         {"_id": ObjectId(single_personnel_id)})
     #check if the account has access to the organization
     if single_personnel['org_id'] in account['orgs']:
         #if the organization is being updated
         try:
             #check if the account has that organization
             if data['org_id'] in account['orgs']:
                 personnel.update({"_id": ObjectId(single_personnel_id)},
                                  {"$set": data})
                 return True, "Success!"
             else:
                 return False, "Account does not have access to the new organization"
         #we get here if the data['org_id'] was not set so
         except NameError:
             #no change in the organization
             personnel.update({"_id": ObjectId(single_personnel_id)},
                              {"$set": data})
             return True, "Success!"
     else:
         return False, "Account does not have access to this personnel"
Beispiel #3
0
    def delete(account_id):
        # Mongo
        db = dbc().db
        accounts = db.accounts
        accounts.remove({"_id": ObjectId(account_id)})

        return True, "Success!"
Beispiel #4
0
 def login(data):
     data['password'] = Accounts.c_hash(data['password'])
     mongo = dbc()
     accounts = mongo.db.accounts
     account = accounts.find_one(
         {'$and': [{
             'email': data['email'],
             'password': data['password']
         }]})
     if account:
         now = datetime.datetime.now()
         user_hash = Accounts.c_hash(account['email'] + str(time.time()) +
                                     str(random.randint(1, 10000)))
         #make sure to use push as method for MongoDB so we add this new session to the array of sessions
         result = accounts.update({'_id': account['_id']}, {
             '$push': {
                 'session_hashes': {
                     'hash': user_hash,
                     'last_action': str(now)
                 }
             }
         })
         if not result['updatedExisting']:
             return False, "Something went wrong"
         else:
             return True, user_hash
     else:
         return False, "Account does not exist"
Beispiel #5
0
def inline(msg, bot):
    db = dbc()
    a = get_current_playing(str(msg['from']['id']), db)
    if a is None:
        articles = [
            InlineQueryResultArticle(
                id='a',
                title='spoti: Você não está tocando nada',
                thumb_url='https://piics.ml/amn/lpy/spoti.png',
                input_message_content=InputTextMessageContent(
                    message_text="Você não está tocando nada"))
        ]
    else:
        a = lyricspy.auto(
            f"{a['item']['artists'][0]['name']} {a['item']['name']}",
            limit=1)[0]
        teclado = InlineKeyboardMarkup(
            inline_keyboard=[[dict(text='Aguarde...', callback_data='a')]])
        articles = [
            InlineQueryResultArticle(
                id=a['link'],
                thumb_url='https://piics.ml/amn/lpy/spoti.png',
                title=f'spoti: {a["musica"]} - {a["autor"]}',
                input_message_content=InputTextMessageContent(
                    message_text='Aguarde...',
                    parse_mode='markdown',
                    disable_web_page_preview=True),
                reply_markup=teclado)
        ]
    return articles
Beispiel #6
0
    def update(account, work_order_id, data):
        # Mongo
        db = dbc().db
        work_orders = db.work_orders

        work_order = work_orders.find_one({"_id": ObjectId(work_order_id)})
        #check if the account has access to the organization
        if work_order['org_id'] in account['orgs']:
            #if the organization is being updated
            try:
                #check if the account has the new organization
                if data['org_id'] in account['orgs']:
                    work_orders.update({"_id": ObjectId(work_order_id)},
                                       {"$set": data})
                    return True, "Success!"
                else:
                    return False, "Account does not have access to the new organization"
            #we get here if the data['org_id'] was not set so
            except NameError:
                #no change in the organization
                work_orders.update({"_id": ObjectId(work_order_id)},
                                   {"$set": data})
                return True, "Success!"
        else:
            return False, "Account does not have access to this work order"
Beispiel #7
0
    def delete(org_id):
        # Mongo
        db = dbc().db
        orgs = db.orgs
        orgs.remove({"_id": ObjectId(org_id)})

        return True, "Success!"
Beispiel #8
0
    def update(org_id, data):
        # Mongo
        db = dbc().db
        orgs = db.orgs
        orgs.update({"_id": ObjectId(org_id)}, {"$set": data})

        return True, "Success!"
    def create(account, data):
        mongo = dbc()
        work_orders = mongo.db.work_orders
        if data['org_id'] in account['orgs']:
            _id = work_orders.insert_one(data)
            return True, ["Work order created successfully",str(_id.inserted_id)]

        return False, "Work order does not have access to the organization"
Beispiel #10
0
 def account_from_hash(user_hash):
     mongo = dbc()
     accounts = mongo.db.accounts
     return accounts.find_one(
         {'session_hashes': {
             '$elemMatch': {
                 'hash': user_hash
             }
         }})
Beispiel #11
0
 def get(account_id):
     # Mongo
     db = dbc().db
     accounts = db.accounts
     account = accounts.find_one({"_id": ObjectId(account_id)})
     account['id'] = str(account['_id'])
     del account['_id']
     del account['password']
     return True, account
Beispiel #12
0
    def get(org_id):
        # Mongo
        db = dbc().db
        orgs = db.orgs
        org = orgs.find_one({"_id": ObjectId(org_id)})
        org['id'] = str(org['_id'])
        del org['_id']

        return True, org
Beispiel #13
0
    def delete(account, work_order_id):
        db = dbc().db
        work_orders = db.work_orders
        work_order = work_orders.find_one({"_id": ObjectId(work_order_id)})
        if work_order['org_id'] in account['orgs']:
            work_orders.remove({"_id": ObjectId(work_order_id)})
            return True,"Success!"

        return False, "Account does not have access to this work order"
Beispiel #14
0
def adduser_per(user_id, p_id):
    db = dbc()
    try:
        temp_sql = "Insert into auth_user_per VALUES (%s,%s)" % (user_id, p_id)
        db.cur.execute(temp_sql)
        logging('info', temp_sql, '')
    except Exception as err:
        print err
        logging('info', temp_sql, err)
    db.commit()
Beispiel #15
0
 def get(account, work_order_id):
     db = dbc().db
     work_orders = db.work_orders
     work_order = work_orders.find_one({"_id": ObjectId(work_order_id)})
     if work_order['org_id'] in account['orgs']:
         work_order['id'] = str(work_order['_id'])
         del work_order['_id']
         return True,work_order
         
     return False, "Account does not have access to this work order"
Beispiel #16
0
    def create(account, data):
        # Mongodb
        mongo = dbc()
        assets = mongo.db.assets
        #check if the account has access to the organization
        if data['org_id'] in account['orgs']:
            _id = assets.insert_one(data)
            return True, ["Asset created successfully", str(_id.inserted_id)]

        return False, "Account does not have access to the organization"
Beispiel #17
0
def index():
    try:
        db = dbc()
        # Return hostname
        check_fields(request.data, [], [])
        return socket.gethostname()
    except FieldsException as e:
        return json.dumps({"success": 0, "message": str(e)})
    except Exception as e:
        return json.dumps({"success": 0, "message": "Something went wrong"})
Beispiel #18
0
    def delete(account, asset_id):
        # Mongo
        db = dbc().db
        assets = db.assets
        asset = assets.find_one({"_id": ObjectId(asset_id)})
        #check if the account has access to the organization
        if asset['org_id'] in account['orgs']:
            assets.remove({"_id": ObjectId(asset_id)})
            return True, "Success!"

        return False, "Account does not have access to this asset"
Beispiel #19
0
def modifyrole(r_id, r_name):
    db = dbc()
    try:
        temp_sql = "UPDATE auth_role_group SET role_name= '%s' where r_id=%s" % (
            r_name, r_id)
        db.cur.execute(temp_sql)
        logging('info', temp_sql, '')
    except Exception as err:
        print err
        logging('info', temp_sql, err)
    db.commit()
Beispiel #20
0
def deleteuser_per(user_id, p_id):
    db = dbc()
    try:
        temp_sql = "delete from auth_user_per where user_id=%s and p_id=%s" % (
            user_id, p_id)
        db.cur.execute(temp_sql)
        logging('info', temp_sql, '')
    except Exception as err:
        print err
        logging('info', temp_sql, err)
    db.commit()
Beispiel #21
0
def modifyuser(user_id, r_id):
    db = dbc()
    try:
        temp_sql = "Update auth_user set r_id = %s WHERE user_id=%s" % (
            r_id, user_id)
        db.cur.execute(temp_sql)
        logging('info', temp_sql, '')
    except Exception as err:
        print err
        logging('info', temp_sql, err)
    db.commit()
Beispiel #22
0
def modifyper(p_id, new_name):
    db = dbc()
    try:
        temp_sql = "UPDATE auth_per set permit_name = '%s' where p_id =%s" % (
            new_name, p_id)
        db.cur.execute(temp_sql)
        logging('info', temp_sql, '')
        db.commit()
    except Exception as err:
        print err
        logging('info', temp_sql, err)
Beispiel #23
0
 def create(data):
     # Mongodb
     mongo = dbc()
     accounts = mongo.db.accounts
     account = accounts.find_one({'email': data['email']})
     if account:
         return False, "Account was not created, email already used"
     else:
         data['password'] = Accounts.c_hash(data['password'])
         _id = accounts.insert_one(data)
     return True, ["Account created successfully", str(_id.inserted_id)]
Beispiel #24
0
def modifygroup(g_id, g_name):
    db = dbc()
    try:
        temp_sql = "UPDATE auth_group SET group_name='%s' WHERE g_id=%s" % (
            g_name, g_id)
        db.cur.execute(temp_sql)
        logging('info', temp_sql, '')
    except Exception as err:
        print err
        logging('info', temp_sql, err)
    db.commit()
Beispiel #25
0
    def delete(account, single_personnel_id):
        # Mongo
        db = dbc().db
        personnel = db.personnel
        single_personnel = personnel.find_one(
            {"_id": ObjectId(single_personnel_id)})
        #check if the account has access to the organization
        if single_personnel['org_id'] in account['orgs']:
            personnel.remove({"_id": ObjectId(single_personnel_id)})
            return True, "Success!"

        return False, "Account does not have access to this personnel"
Beispiel #26
0
    def get(account, asset_id):
        # Mongo
        db = dbc().db
        assets = db.assets
        asset = assets.find_one({"_id": ObjectId(asset_id)})
        #check if the account has access to the organization
        if asset['org_id'] in account['orgs']:
            asset['id'] = str(asset['_id'])
            del asset['_id']
            return True, asset

        return False, "Account does not have access to this asset"
Beispiel #27
0
def updatepwd(user_id, pwd):
    # todo 验证
    db = dbc()
    try:
        temp_sql = "Update auth_user set pwd = '%s' WHERE user_id=%s" % (
            pwd, user_id)
        db.cur.execute(temp_sql)
        logging('info', temp_sql, '')
    except Exception as err:
        print err
        logging('info', temp_sql, err)
    db.commit()
Beispiel #28
0
 def logout(account_id, user_hash):
     mongo = dbc()
     accounts = mongo.db.accounts
     #the account should have been checked already, as it was got from the user hash supplied in the cookie
     result = accounts.update(
         {'_id': account_id},
         {'$pull': {
             'session_hashes': {
                 'hash': user_hash
             }
         }})
     return True, "Successfully logout"
Beispiel #29
0
def query_role_name():
    db = dbc()
    try:
        temp_sql = "SELECT r_id,role_name FROM auth_role_group ORDER BY r_id"
        db.cur.execute(temp_sql)
        temp = db.cur.fetchall()
        temp = list([list(x) for x in temp])
        logging('info', temp_sql, '')
        return temp
    except Exception as err:
        print err
        logging('info', temp_sql, err)
Beispiel #30
0
    def get(account, single_personnel_id):
        # Mongo
        db = dbc().db
        personnel = db.personnel
        single_personnel = personnel.find_one(
            {"_id": ObjectId(single_personnel_id)})
        #check if the account has access to the organization
        if single_personnel['org_id'] in account['orgs']:
            single_personnel['id'] = str(single_personnel['_id'])
            del single_personnel['_id']
            return True, single_personnel

        return False, "Account does not have access to this personnel"