Exemplo n.º 1
0
def is_command_autodelete_channel(ctx):
    if os.path.exists(hassan_env.CMD_AUTODEL_CHANNEL_PATH):
        file = open(hassan_env.CMD_AUTODEL_CHANNEL_PATH,
                    mode='rt',
                    encoding='utf-8')
        lines = file.readlines()
        file.close()

        for line in lines:
            system_log(str(ctx.channel.id) + ' vs ' + line.replace('\n', ''))
            if str(ctx.channel.id) == line.replace('\n', ''):
                return True

    return False
Exemplo n.º 2
0
def _download_single_dccon(dccon):
    try:
        session = requests.Session()
        dccon_img = "http://dcimg5.dcinside.com/dccon.php?no=" + dccon['path']
        dccon_img_request = session.get(
            dccon_img, headers={'Referer': hassan_env.DCCON_HOME_URL})

        buffer = BytesIO(dccon_img_request.content)
        file_name = dccon['title'] + '.' + dccon['ext']

        return buffer, file_name
    except Exception as e:
        system_log('dccon_download : ' + str(e))

    return ['', '']
Exemplo n.º 3
0
def is_exactly_same_exist(author_id, keyword):
    file_path = os.path.join(hassan_env.FAVORITE_PATH, str(author_id) + '.txt')

    exist = False

    file = open(file_path, mode='rt', encoding='utf-8')
    lines = file.readlines()
    for line in lines:
        splited = line.split('\t')
        if splited[0] == keyword:
            system_log(
                f'add_favorite {keyword} of {author_id} is already exists.')
            exist = True
            break
    file.close()

    return exist
Exemplo n.º 4
0
def add_cache(package_name, idx, file_name, buffer):
    if hassan_env.CACHE_MAX == 0:
        return

    if not os.path.isdir(hassan_env.CACHE_PATH):
        if not create_directory(
                hassan_env.CACHE_PATH):  # 캐시 폴더가 존재하지 않으면 생성. 생성 실패시 오류메시지 출력.
            system_log('creating cache directory failed')

    # 캐시 개수 체크
    if _get_count_of_cache() >= hassan_env.CACHE_MAX:
        _remove_latest_cache()

    # 이미지 저장
    cache_path = os.path.join(hassan_env.CACHE_PATH, f'{file_name}')
    with open(cache_path, 'wb') as out:  ## Open temporary file as bytes
        out.write(buffer.read())  ## Read bytes into file

    # 캐시 인덱스에 append
    # 캐시 인덱스에 중복추가안하게 해라
    cache_idx_path = os.path.join(hassan_env.CACHE_PATH, 'cacheIdx.txt')
    file = open(cache_idx_path, mode='at', encoding='utf-8')
    file.write(package_name + '\t' + idx + '\t' + file_name + '\n')
    file.close()
Exemplo n.º 5
0
def create_directory(path):
    try:
        if not (os.path.isdir(path)):
            system_log(f'creating directory at {path}')
            os.makedirs(os.path.join(path))
            system_log(f'directory created at {path}')

        return True
    except OSError as e:
        if e.errno != errno.EEXIST:
            system_log(f'failed to create directory at {path}!')

        return False
Exemplo n.º 6
0
def print_on_ready():
    system_log('Bot ready')
    system_log(f'BOT_TOKEN : {hassan_env.BOT_TOKEN}')
    system_log(f'OWNER_ID : {hassan_env.OWNER_ID}')
    system_log(f'FAVORITE_PATH : {hassan_env.FAVORITE_PATH}')
    system_log(f'FAVORITE_MAX : {hassan_env.FAVORITE_MAX}')
    system_log(f'CACHE_PATH : {hassan_env.CACHE_PATH}')
    system_log(f'CACHE_MAX : {hassan_env.CACHE_MAX}')
    system_log(
        f'CONCMD_AUTODEL_CHANNEL_PATH : {hassan_env.CMD_AUTODEL_CHANNEL_PATH}')