import * as moment from "moment" ; import * as TelegramBot from "node-telegram-bot-api" ; import { BotConfig } from "./botConfig" ; import * as CONSTS from "./consts" ; import * as PhotoData from "./photoData" ; const tracer = require ( "tracer" ) ; const logger = tracer . colorConsole ( { level : process . env . DEBUG !== undefined ? process . env . DEBUG : "info" } ) ; class Commands { param msg public static async _COMMANDS_SET_PAUSED ( getData , data , bot , msg ) { const chatId = msg . chat . id ; const chatData = getData ( data , chatId ) ; chatData . paused = true ; logger . info ( CONSTS . PAUSE_RESUME_LOG_MESSAGE ( msg . chat , chatData ) ) ; return bot . sendMessage ( chatId , CONSTS . PAUSE_RESUME_MESSAGE ( msg . chat , chatData ) ) ; } param msg public static async _COMMANDS_SET_RESUMED ( getData , data , bot , msg ) { const chatId = msg . chat . id ; const chatData = getData ( data , chatId ) ; chatData . paused = false ; logger . info ( CONSTS . PAUSE_RESUME_LOG_MESSAGE ( msg . chat , chatData ) ) ; return bot . sendMessage ( chatId , CONSTS . PAUSE_RESUME_MESSAGE ( msg . chat , chatData ) ) ; } param msg public static async _COMMANDS_SET_INTERVAL ( getData , data , bot , config , msg , commandArgs ) { const chatId = msg . chat . id ; const chatData = getData ( data , chatId ) ; if ( msg . text ) { const args = commandArgs . join ( " " ) ; if ( args . length === 0 ) { return bot . sendMessage ( chatId , CONSTS . NOW_INTERVAL ( chatData . interval . toString ( ) ) ) ; } if ( args . length > 0 && Number ( args ) >= config . minBotInterval ) { chatData . interval = Number ( args ) ; return bot . sendMessage ( chatId , CONSTS . SET_INTERVAL ( chatData . interval . toString ( ) ) ) ; } else { return bot . sendMessage ( chatId , CONSTS . INVALID_VALUE ) ; } } } param msg public static async _COMMANDS_NEXT_PHOTO ( getData , data , bot , msg ) { const chatId = msg . chat . id ; const chatData = getData ( data , chatId ) ; return chatData . nextPhoto ( bot ) ; } param msg public static async _COMMANDS_BAN ( delPhoto , data , bot , msg ) { return delPhoto ( data , bot , msg , true ) ; } param msg public static async _COMMANDS_UNBAN ( unbanPhoto , data , msg ) { if ( msg . reply_to_message && ( msg . reply_to_message . photo || msg . reply_to_message . document ) ) { return unbanPhoto ( data , msg ) ; } } param msg public static async _COMMANDS_DELETE ( delPhoto , data , bot , msg ) { return delPhoto ( data , bot , msg ) ; } param msg public static async _COMMANDS_QUEUE_STATUS ( getData , data , bot , msg ) { const chatId = msg . chat . id ; const chatData = getData ( data , chatId ) ; const nextTime = moment ( chatData . last ) . add ( chatData . interval , "h" ) . format ( "LLL" ) ; return bot . sendMessage ( chatId , CONSTS . WAITING_PHOTOS ( chatData , nextTime ) ) ; } public constructor ( ) { this . init ( ) ; } public init ( ) { logger . DEBUG ( "Commands initialized" ) ; } } export { Commands } ;