const convert = require ( "convert-units" ) ; import * as TelegramBot from "node-telegram-bot-api" ; import * as PhotoData from "./photoData" ; const toMB = ( byte ) => convert ( byte ) . from ( "B" ) . to ( "MB" ) . toFixed ( 2 ) ; export const ADDED_INTO_QUEUE = "已加入序列" ; export const ALREADY_IN_QUEUE = "已在序列中" ; export const BANNED_PHOTO = "圖片已被封鎖" ; export const BANNED_TEXT = ( charId , fileId ) => `Receive Ban Queue for ${ charId } to ${ fileId }.` ; export const DELETE_PHOTO = "圖片已被刪除" ; export const DELETE_TEXT = ( charId , fileId ) => `Receive delete Queue for ${ charId } to ${ fileId }.` ; export const CAN_NOT_CHANGE_ALL_ADMINS_PHOTO = "I can't change group photo if all members are admin!" ; export const CAN_NOT_CHANGE_PHOTO = "I can't change your photo!" ; export enum COMMANDS { SET_PAUSED = "pause" , SET_RESUMED = "resume" , SET_INTERVAL = "setinterval" , NEXT_PHOTO = "next" , QUEUE_STATUS = "queue" , BAN = "ban" , UNBAN = "unban" , DELETE = "delete" } export const COMMANDS_ADMINS_ONLY = [ COMMANDS . SET_PAUSED , COMMANDS . SET_RESUMED , COMMANDS . SET_INTERVAL , COMMANDS . NEXT_PHOTO , COMMANDS . BAN , COMMANDS . UNBAN , COMMANDS . DELETE , ] ; export const CACHE_FILE_FOLDER = ".group_cache" ; export const CACHE_DATA_FILENAME = "data.yaml" ; export const CACHE_CREATED_FOLDER = ( folder ) => `Created cache folder at ${ folder }` ; export const CACHE_DOWNLOADED = ( filename , dest ) => `Downloaded as ${ filename } at ${ dest }` ; export const CACHE_DOWNLOADED_RENAME_ERROR = ( filename , dest , error ) => `${ CACHE_DOWNLOADED ( filename , dest ) }, but rename file has exception -> ${ error . message }` ; export const CACHE_DOWNLOADING = ( dest ) => `Downloading cache into ${ dest }` ; export const CACHE_DOWNLOAD_ERROR = ( dest , reason ) => `Cache download with error occurred for ${ dest } as ${ reason }` ; export const CACHE_DOWNLOAD_IGNORE = ( dest ) => `Ignore exists file of ${ dest }` ; export const CACHE_FOLDER_CHECKED = ( folder , files ) => `Cache folder exists at ${ folder } with ${ files . length } files` ; export const CHAT_DISABLED_BY_SYSTEM = ( chatId , reason ) => `Chat \`${ chatId }\` disabled because \`${ reason }\`` ; export const CONFIG_FILE_PATH = "./config.yaml" ; export const DATA_FILE_JSON_PATH = "./data.json" ; export const DATA_FILE_PATH = "./data.yaml" ; export const DISABLED_PIXIV_ACCOUNT = "There not configured for pixiv API account" ; export const ENABLED_PIXIV_ACCOUNT = ( account , refreshToken ) => `Pixiv API Account Enabled => \`${ account }\` with refresh token => \`${ refreshToken }\`.` ; export const ENABLING_REFRESHED_PIXIV_ACCOUNT = ( account , refreshToken ) => `Re-Enabling Pixiv API Account => \`${ account }\` by refresh token => \`${ refreshToken }\`.` ; export const ENABLING_PIXIV_ACCOUNT = ( account ) => `Enabling Pixiv API Account => \`${ account }\`.` ; export const FILE_ADD_INTO_QUEUE_UNSUPPORTED = ( fileName ) => `Unsupported file for \`${ fileName }\`.` ; export const FILE_ADDED_INTO_QUEUE = ( fileId ) => `File (${ fileId }) added into queue.` ; export const FILE_ALREADY_IN_QUEUE = ( fileId ) => `File (${ fileId }) already in the queue.` ; export const GET_CHAT_ERROR = ( chatId , reason ) => `Get Chat Error ${ chatId }: ${ reason }.` ; export const GROUP_PHOTO_CAPTION = "#群組圖片" ; export const GROUP_PHOTO_PIXIV_CAPTION = ( illust ) => `${ illust . title }(${ illust . userName })
${ illust . referralUrl } ${ GROUP_PHOTO_CAPTION }

${ illust . tags . join ( " " ) }
${ illust . caption }` ; export const IMAGE_FROM_URL_DIMENSION = ( mime , w , h ) => `Got Image file in type of ${ mime } as resolution in dimension (${ w }×${ h }).` ; export const INVALID_VALUE = "無效的數值" ; export const NEED_TELEGRAM_BOT_TOKEN = "Need a valid Telegram Bot Token." ; export const NOT_SUPPORT_FOR_HENTAI = ( url ) => `Not support for hentai: ${ url }` ; export const NOT_SUPPORT_FOR_HENTAI_MSG = ( url ) => `目前這個網址不提供紳士支援: ${ url }` ; export const NOW_INTERVAL = ( interval ) => `目前設定值為${ interval }小時` ; export const PAUSE_RESUME_MESSAGE = ( chat , chatData ) => `暫停更換群組圖狀態已設為: ${ chatData . paused ? "暫停中" : "正常中" }` ; export const PAUSE_RESUME_LOG_MESSAGE = ( chat , chatData ) => `Group/Peer ${ chat . title || chat . username }(${ chat . id }) set paused state to => ${ chatData . paused }.` ; export const PHOTO_CAPTION_MAX_LENGTH = 100 ; export const PHOTO_RETRY_MAX = process . env . PHOTO_RETRY_MAX !== undefined ? Number ( process . env . PHOTO_RETRY_MAX ) : 3 ; export const PHOTO_RETRY_DELETE_MESSAGE = ( fileId ) => `檔案/圖片 \`${ fileId }\` 重試失敗次數已超過 ${ PHOTO_RETRY_MAX } 次，已從序列移除。` ; export const PHOTO_RETRY_DELETE_FROM_QUEUE = ( charId , fileId ) => `Retry exceed the max retry of ${ PHOTO_RETRY_MAX } times, delete \`${ fileId }\` from \`${ charId }\` queue` ; export const PHOTO_RETRY_REQUEUE = ( charId , fileId ) => `Retry the photo of \`${ fileId }\` by re-add into \`${ charId }\` queue` ; export const PIXIV_ILLUST_IID_URL = ( iid ) => `https://www.pixiv.net/i/${ iid }` ; export const PIXIV_ILLUST_DETAIL = ( illust ) => `Got Illust \`${ illust . title } : ${ illust . caption } - ${ illust . userName }\` (${ illust . tags . join ( ", " ) }) ` + `with URL \`${ String ( illust . originalUrl ) }\` and square image URL \`${ String ( illust . squareMediumUrl ) }\`` ; export const PIXIV_URL_REVERSED_PROXY = ( oUrl , pUrl ) => `Convert Pixiv URL \`${ oUrl }\` => \`${ pUrl }\`` ; export const QUEUE_REQUEST_TEXT = ( type , name ) => `Receive ${ type } Queue Request from ${ name }.` ; export const QUEUE_TEXT = ( type , chat ) => `Receive ${ type } Queue from Group/Peer ${ chat . title || chat . username }(${ chat . id }).` ; export const QUEUE_WAS_BANNED = ( chatId , fileId ) => `The file of ${ fileId } was banned in ${ chatId }` ; export const REGEXP_MATCH_HENTAI_DOMAIN = /e[x\-]?hentai.org/i ; export const REGEXP_MATCH_PIXIV_DOMAIN = /\.pixiv\./i ; export const REGEXP_MATCH_PIXIV_ILLUST_ID = /illust_id=(\d+)|www.pixiv.net\/i\/(\d+)/i ; export const REGEXP_MATCH_PIXIV_IMAGE_DOMAIN = /^(https:\/\/)i.pximg.net(\/.+)$/i ; export const REGEXP_MATCH_TAG_COMMAND = /(#|＃)(群組圖|群组图)片/ig ; export const SET_INTERVAL = ( interval ) => `已設定變更間隔為${ interval }小時` ; export const UNBANNED_TEXT = ( charId , fileId ) => `Receive UnBan Queue for ${ charId } to ${ fileId }.` ; export const UNSUPPORTED_FILE_EXTENSIONS = ( fileName ) => `不支援檔案 \`${ fileName }\`，因此無法設定群圖` ; export const UPDATE_PHOTO_ERROR = ( chatId , reason ) => `Update photo rejected on ${ chatId }: ${ reason }.` ; export const UPDATE_PHOTO_IGNORE = ( chat ) => `Group/Peer ${ chat . title || chat . username }(${ chat . id }) ignore to update photo due to photo link was empty.` ; export const UPDATED_PHOTO = ( chat , fileLink ) => `Group/Peer ${ chat . title || chat . username }(${ chat . id }) updated photo to \`${ fileLink }\`.` ; export const UPLOADING_PHOTO = ( chatId , image , url ) => `Uploading the Photo from \`${ url }\` (size: ${ toMB ( image . byteLength ) }MB) to Chat: ${ chatId }.` ; export const URL_CONTENT_TYPE_NOT_ACCEPTED = ( url , mime ) => `The request of \`${ url }\` is not accept for the MIME type which is \`${ mime }\`, is only allowed image or html` ; export const URL_HTML_IGNORE = ( url ) => `Request of \`${ url }\` ignore to check size.` ; export const URL_PREPARE_TO_DOWNLOAD = ( msg , url ) => `Prepare to download \`${ url }\` for ${ msg . chat . title }(${ msg . chat . id }).` ; export const URL_FOUND_OG_IMAGE_URL = ( msg , url , ogUrl ) => `Found \`og:img\` to download \`${ url }\` => \`${ ogUrl }\` for ${ msg . chat . title }(${ msg . chat . id }).` ; export const URL_NOT_FOUND_OG_IMAGE_URL = ( msg , url ) => `\`og:img\` not found to download \`${ url }\` for ${ msg . chat . title }(${ msg . chat . id }), fallback to continue.` ; export const URL_REQUESTED_IS_NOT_A_IMAGE = ( url ) => `要求的網址 \`${ url }\` 不是可辨識的圖片，無法安排自動換圖` ; export const URL_REQUESTED_IS_NOT_OK = ( url ) => `要求的網址 \`${ url }\` 回傳不是成功要求，請檢查網址` ; export const URL_SIZE_CHECK = ( url ) => `Checking file size for \`${ url }\`.` ; export const URL_SIZE_RESULT = ( url , size ) => `The file size for \`${ url }\` is passed for ${ toMB ( size ) }MB.` ; export const URL_SIZE_OUT_OF_BOUND = ( url , size , limitation ) => `The request of \`${ url }\` is ${ toMB ( size ) }MB, ` + `that is exceed the limitation of ${ toMB ( limitation ) }MB.` ; export const WAITING_PHOTOS = ( chatData , nextTime ) => `等待的圖片數：${ chatData . queue . length }
封鎖的圖片數量：${ chatData . banList . length }
歷史記錄數量：${ chatData . history . length }
下次換圖時間：${ nextTime }${ chatData . paused ? " (暫停更換中)" : "" }` ;