nestgram
Advanced tools
Comparing version 1.7.5 to 1.7.6
@@ -34,2 +34,4 @@ import { Audio, ContentTypes, Document, IAnswerCallbackQueryOptions, ICopyMessageOptions, IDeleteWebhookConfig, IFile, IForwardMessageOptions, IMessage, IMessageId, InputSupportedMedia, IOptions, ISendAnimationOptions, ISendAudioOptions, ISendDocumentOptions, ISendLocationOptions, ISendMediaGroupOptions, ISendPhotoOptions, ISendVideoNoteOptions, ISendVideoOptions, ISendVoiceOptions, IUser, IWebhookConfig, Keyboard, MessageCreator, Photo, Video, Voice, IStopMessageLiveLocationOptions, ISendVenueOptions, ISendContactOptions, ISendPollOptions, DiceEmojis, ISendDiceOptions, ChatActions, IUserProfilePhotos, IWebhookInfo } from '..'; | ||
getUserProfilePhotos(userId: number, limit?: number, offset?: number): Promise<IUserProfilePhotos>; | ||
ban(chatId: number | string, userId: number, untilDate?: number, revokeMessages?: boolean): Promise<true>; | ||
unban(chatId: number | string, userId: number, onlyIfBanned?: boolean): Promise<true>; | ||
answerCallbackQuery(callback_query_id: string, moreOptions?: IAnswerCallbackQueryOptions): Promise<boolean>; | ||
@@ -36,0 +38,0 @@ alert(callback_query_id: string, text: string, moreOptions?: IAnswerCallbackQueryOptions): Promise<boolean>; |
@@ -46,5 +46,7 @@ "use strict"; | ||
const formData = new FormData(); | ||
Api.appendMediaToFormData(formData, fromMediaKey, MediaCache_1.mediaCache.getMediaFileId(media.media) || media); | ||
Api.appendMediaToFormData(formData, fromMediaKey, media.useCache ? MediaCache_1.mediaCache.getMediaFileId(media.media) || media : media); | ||
if (config.thumb) { | ||
Api.appendMediaToFormData(formData, 'thumb', MediaCache_1.mediaCache.getMediaFileId(config.thumb.media) || config.thumb); | ||
Api.appendMediaToFormData(formData, 'thumb', media.useCache | ||
? MediaCache_1.mediaCache.getMediaFileId(config.thumb.media) || config.thumb | ||
: config.thumb); | ||
} | ||
@@ -322,2 +324,17 @@ Object.keys(config).forEach((key) => { | ||
} | ||
ban(chatId, userId, untilDate, revokeMessages) { | ||
return this.callApi('banChatMember', { | ||
chat_id: chatId, | ||
user_id: userId, | ||
until_date: untilDate, | ||
revoke_messages: revokeMessages, | ||
}); | ||
} | ||
unban(chatId, userId, onlyIfBanned) { | ||
return this.callApi('unbanChatMember', { | ||
chat_id: chatId, | ||
user_id: userId, | ||
only_if_banned: onlyIfBanned, | ||
}); | ||
} | ||
answerCallbackQuery(callback_query_id, moreOptions = {}) { | ||
@@ -324,0 +341,0 @@ return this.callApi('answerCallbackQuery', { |
@@ -1,2 +0,2 @@ | ||
import { Keyboard, ChatActions, ContentTypes, IAnswerCallbackQueryOptions, IForwardMessageOptions, ICopyMessageOptions, IStopMessageLiveLocationOptions, ISendOptions, IMessage, IUpdate, IFile, IUserProfilePhotos } from '../..'; | ||
import { Keyboard, ChatActions, ContentTypes, IAnswerCallbackQueryOptions, IForwardMessageOptions, ICopyMessageOptions, IStopMessageLiveLocationOptions, ISendOptions, IMessage, IUpdate, IFile, IUserProfilePhotos, IMessageId } from '../..'; | ||
import { MessageCreator } from '../Message'; | ||
@@ -17,5 +17,7 @@ import { Api } from '../Api'; | ||
forward(toChatId: number | string, moreOptions?: IForwardMessageOptions): Promise<IMessage>; | ||
copy(toChatId: number | string, keyboard?: Keyboard | null, moreOptions?: ICopyMessageOptions): Promise<import("../..").IMessageId>; | ||
copy(toChatId: number | string, keyboard?: Keyboard | null, moreOptions?: ICopyMessageOptions): Promise<IMessageId>; | ||
ban(untilDate?: number, revokeMessages?: boolean): Promise<true>; | ||
unban(onlyIfBanned?: boolean): Promise<true>; | ||
saveProfilePhoto(path: string, index?: number): Promise<boolean>; | ||
saveFile(path: string, fileId?: string): Promise<boolean>; | ||
} |
@@ -75,2 +75,20 @@ "use strict"; | ||
} | ||
ban(untilDate, revokeMessages) { | ||
const chatId = Filter_1.Filter.getChatId(this.update); | ||
if (!chatId) | ||
throw (0, logger_1.error)(`Can't find chatId from update`); | ||
const userId = Filter_1.Filter.getUserId(this.update); | ||
if (!userId) | ||
throw (0, logger_1.error)(`Can't find userId from update`); | ||
return this.api.ban(chatId, userId, untilDate, revokeMessages); | ||
} | ||
unban(onlyIfBanned) { | ||
const chatId = Filter_1.Filter.getChatId(this.update); | ||
if (!chatId) | ||
throw (0, logger_1.error)(`Can't find chatId from update`); | ||
const userId = Filter_1.Filter.getUserId(this.update); | ||
if (!userId) | ||
throw (0, logger_1.error)(`Can't find userId from update`); | ||
return this.api.unban(chatId, userId, onlyIfBanned); | ||
} | ||
async saveProfilePhoto(path, index = 0) { | ||
@@ -106,12 +124,13 @@ var _a; | ||
try { | ||
(0, axios_1.default)({ | ||
const response = await (0, axios_1.default)({ | ||
method: 'GET', | ||
url: `https://api.telegram.org/file/bot${this.token}/${fileInfo.file_path}`, | ||
responseType: 'stream', | ||
}).then((response) => { | ||
response.data.pipe(fs.createWriteStream(path)); | ||
}); | ||
return true; | ||
const pf = response.data.pipe(fs.createWriteStream(path)); | ||
return await new Promise((resolve) => { | ||
pf.on('finish', () => resolve(true)); | ||
}); | ||
} | ||
catch (_g) { | ||
catch (e) { | ||
return false; | ||
@@ -118,0 +137,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Handler = void 0; | ||
const Message_1 = require("../Message"); | ||
const Answer_1 = require("../Context/Answer"); | ||
const Filter_1 = require("../Context/Filter"); | ||
const Message_1 = require("../Message"); | ||
const FileLogger_1 = require("../Helpers/FileLogger"); | ||
@@ -20,7 +20,3 @@ const logger_1 = require("../../logger"); | ||
const nextFunction = middlewares[++middlewareIndex]; | ||
return () => { | ||
if (this.logging) | ||
(0, logger_1.info)('Calling next middleware', `(${update.update_id})`.grey); | ||
return (nextFunction || handler)(update, answer, params, this.getNextFunction(update, answer, params, middlewares, middlewareIndex, handlerIndex, handler, failFunction.bind(null, middlewareIndex, handlerIndex)), failFunction.bind(null, middlewareIndex, handlerIndex)); | ||
}; | ||
return () => (nextFunction || handler)(update, answer, params, this.getNextFunction(update, answer, params, middlewares, middlewareIndex, handlerIndex, handler, failFunction.bind(null, middlewareIndex, handlerIndex)), failFunction.bind(null, middlewareIndex, handlerIndex)); | ||
} | ||
@@ -76,2 +72,5 @@ handleMiddleware(index, update, answer, middlewareIndex = 0) { | ||
} | ||
else if (resultMessageToSend instanceof Message_1.Ban) { | ||
answerCallArgs.push(resultMessageToSend.untilDate, resultMessageToSend.revokeMessages); | ||
} | ||
else if (resultMessageToSend instanceof Message_1.Forward || resultMessageToSend instanceof Message_1.Copy) { | ||
@@ -97,4 +96,2 @@ if (resultMessageToSend instanceof Message_1.Forward) | ||
const failNextFunction = (middlewareIndex, handlerIndex) => { | ||
if (this.logging) | ||
(0, logger_1.info)('Middleware called fail function', `(${update.update_id})`.grey); | ||
if (handler.middlewares[middlewareIndex]) { | ||
@@ -105,4 +102,2 @@ return this.handleMiddleware(handlerIndex, update, answer, middlewareIndex); | ||
}; | ||
if (this.logging) | ||
(0, logger_1.info)('Calling first middleware/handler', `(${update.update_id})`.grey); | ||
handler.middlewares[middlewareIndex](update, answer, params, this.getNextFunction(update, answer, params, handler.middlewares, middlewareIndex, index, baseNextFunction, failNextFunction) || baseNextFunction, failNextFunction.bind(null, middlewareIndex + 1, index)); | ||
@@ -109,0 +104,0 @@ const isContinue = Reflect.getMetadata('continue', handler.controller[handler.methodKey]); |
@@ -7,6 +7,7 @@ import { MediaFileTypes, MediaPassTypes, MediaSendTypes } from '../../types'; | ||
readonly options?: any; | ||
readonly useCache: boolean; | ||
type: MediaFileTypes | MediaSendTypes; | ||
thumb?: Thumb; | ||
constructor(passType: MediaPassTypes, media: string, options?: any); | ||
constructor(passType: MediaPassTypes, media: string, options?: any, useCache?: boolean); | ||
setThumb(thumb: Thumb): this; | ||
} |
@@ -5,6 +5,7 @@ "use strict"; | ||
class Media { | ||
constructor(passType, media, options) { | ||
constructor(passType, media, options, useCache = true) { | ||
this.passType = passType; | ||
this.media = media; | ||
this.options = options; | ||
this.useCache = useCache; | ||
} | ||
@@ -11,0 +12,0 @@ setThumb(thumb) { |
@@ -8,1 +8,2 @@ export * from './MessageCreator'; | ||
export * from './Copy'; | ||
export * from './Ban'; |
@@ -24,2 +24,3 @@ "use strict"; | ||
__exportStar(require("./Copy"), exports); | ||
__exportStar(require("./Ban"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -5,4 +5,14 @@ "use strict"; | ||
require("colors"); | ||
function buildTime() { | ||
const date = new Date(); | ||
const day = date.getDate().toString().padStart(2, '0'); | ||
const month = (date.getMonth() + 1).toString().padStart(2, '0'); | ||
const year = date.getFullYear().toString(); | ||
const hours = date.getHours().toString().padStart(2, '0'); | ||
const minutes = date.getMinutes().toString().padStart(2, '0'); | ||
const seconds = date.getSeconds().toString().padStart(2, '0'); | ||
return `${day}.${month}.${year} ${hours}:${minutes}:${seconds}`; | ||
} | ||
function log(typeColor, ...contents) { | ||
console.log(`[NestGram, ${new Date().toISOString()}]`[typeColor], ...contents); | ||
console.log(`[NestGram, ${buildTime()}]`[typeColor], ...contents); | ||
} | ||
@@ -9,0 +19,0 @@ exports.log = log; |
@@ -208,2 +208,13 @@ import { IMessageEntity, IPhotoSize } from './update.types'; | ||
} | ||
export interface IBanChatMemberFetchOptions { | ||
chat_id: number | string; | ||
user_id: number; | ||
until_date?: number; | ||
revoke_messages?: boolean; | ||
} | ||
export interface IUnbanChatMemberFetchOptions { | ||
chat_id: number | string; | ||
user_id: number; | ||
only_if_banned?: boolean; | ||
} | ||
export interface ISendDiceOptions extends IDefaultOptions { | ||
@@ -210,0 +221,0 @@ } |
import { MediaFileTypes } from './media.types'; | ||
export declare type SendTypes = 'send' | 'alert' | 'toast' | 'forward' | 'copy' | 'chatAction'; | ||
export declare type SendTypes = 'send' | 'alert' | 'toast' | 'forward' | 'copy' | 'chatAction' | 'ban'; | ||
export declare type MessageCreatorTypes = MediaFileTypes | 'text' | 'location'; |
{ | ||
"name": "nestgram", | ||
"description": "Framework for working with Telegram Bot API on TypeScript like Nest.js", | ||
"version": "1.7.5", | ||
"version": "1.7.6", | ||
"main": "dist/index.js", | ||
@@ -6,0 +6,0 @@ "types": "dist/index.d.ts", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
223694
198
3159