Comparing version 1.7.6 to 1.7.7
@@ -1,2 +0,2 @@ | ||
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 '..'; | ||
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, IChatPermissions, IPromoteChatPermissions } from '..'; | ||
import { Animation, VideoNote } from './Media'; | ||
@@ -36,2 +36,5 @@ export declare class Api { | ||
unban(chatId: number | string, userId: number, onlyIfBanned?: boolean): Promise<true>; | ||
adminTitle(chatId: number | string, userId: number, title: string): Promise<true>; | ||
restrict(chatId: number | string, userId: number, permissions: IChatPermissions, untilDate?: number): Promise<true>; | ||
promote(chatId: number | string, userId: number, permissions: IPromoteChatPermissions): Promise<true>; | ||
answerCallbackQuery(callback_query_id: string, moreOptions?: IAnswerCallbackQueryOptions): Promise<boolean>; | ||
@@ -38,0 +41,0 @@ alert(callback_query_id: string, text: string, moreOptions?: IAnswerCallbackQueryOptions): Promise<boolean>; |
@@ -338,2 +338,24 @@ "use strict"; | ||
} | ||
adminTitle(chatId, userId, title) { | ||
return this.callApi('setChatAdministratorCustomTitle', { | ||
chat_id: chatId, | ||
user_id: userId, | ||
custom_title: title, | ||
}); | ||
} | ||
restrict(chatId, userId, permissions, untilDate) { | ||
return this.callApi('restrictChatMember', { | ||
chat_id: chatId, | ||
user_id: userId, | ||
until_date: untilDate, | ||
permissions, | ||
}); | ||
} | ||
promote(chatId, userId, permissions) { | ||
return this.callApi('promoteChatMember', { | ||
chat_id: chatId, | ||
user_id: userId, | ||
...permissions, | ||
}); | ||
} | ||
answerCallbackQuery(callback_query_id, moreOptions = {}) { | ||
@@ -340,0 +362,0 @@ return this.callApi('answerCallbackQuery', { |
@@ -1,2 +0,2 @@ | ||
import { Keyboard, ChatActions, ContentTypes, IAnswerCallbackQueryOptions, IForwardMessageOptions, ICopyMessageOptions, IStopMessageLiveLocationOptions, ISendOptions, IMessage, IUpdate, IFile, IUserProfilePhotos, IMessageId } from '../..'; | ||
import { Keyboard, ChatActions, ContentTypes, IAnswerCallbackQueryOptions, IForwardMessageOptions, ICopyMessageOptions, IStopMessageLiveLocationOptions, ISendOptions, IMessage, IUpdate, IFile, IUserProfilePhotos, IMessageId, IChatPermissions, IPromoteChatPermissions } from '../..'; | ||
import { MessageCreator } from '../Message'; | ||
@@ -18,6 +18,9 @@ import { Api } from '../Api'; | ||
copy(toChatId: number | string, keyboard?: Keyboard | null, moreOptions?: ICopyMessageOptions): Promise<IMessageId>; | ||
ban(untilDate?: number, revokeMessages?: boolean): Promise<true>; | ||
unban(onlyIfBanned?: boolean): Promise<true>; | ||
ban(untilDate?: number, revokeMessages?: boolean, userId?: number): Promise<true>; | ||
unban(onlyIfBanned?: boolean, userId?: number): Promise<true>; | ||
restrict(permissions: IChatPermissions, userId?: number, untilDate?: number): Promise<true>; | ||
promote(permissions: IPromoteChatPermissions, userId?: number): Promise<true>; | ||
adminTitle(title: string, userId?: number): Promise<true>; | ||
saveProfilePhoto(path: string, index?: number): Promise<boolean>; | ||
saveFile(path: string, fileId?: string): Promise<boolean>; | ||
} |
@@ -75,20 +75,52 @@ "use strict"; | ||
} | ||
ban(untilDate, revokeMessages) { | ||
ban(untilDate, revokeMessages, userId) { | ||
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) | ||
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) { | ||
unban(onlyIfBanned, userId) { | ||
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) | ||
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); | ||
} | ||
restrict(permissions, userId, untilDate) { | ||
const chatId = Filter_1.Filter.getChatId(this.update); | ||
if (!chatId) | ||
throw (0, logger_1.error)(`Can't find chatId from update`); | ||
if (!userId) | ||
userId = Filter_1.Filter.getUserId(this.update); | ||
if (!userId) | ||
throw (0, logger_1.error)(`Can't find userId from update`); | ||
return this.api.restrict(chatId, userId, permissions, untilDate); | ||
} | ||
promote(permissions, userId) { | ||
const chatId = Filter_1.Filter.getChatId(this.update); | ||
if (!chatId) | ||
throw (0, logger_1.error)(`Can't find chatId from update`); | ||
if (!userId) | ||
userId = Filter_1.Filter.getUserId(this.update); | ||
if (!userId) | ||
throw (0, logger_1.error)(`Can't find userId from update`); | ||
return this.api.promote(chatId, userId, permissions); | ||
} | ||
adminTitle(title, userId) { | ||
const chatId = Filter_1.Filter.getChatId(this.update); | ||
if (!chatId) | ||
throw (0, logger_1.error)(`Can't find chatId from update`); | ||
if (!userId) | ||
userId = Filter_1.Filter.getUserId(this.update); | ||
if (!userId) | ||
throw (0, logger_1.error)(`Can't find userId from update`); | ||
return this.api.adminTitle(chatId, userId, title); | ||
} | ||
async saveProfilePhoto(path, index = 0) { | ||
@@ -95,0 +127,0 @@ var _a; |
@@ -12,4 +12,5 @@ import { IHandler, IUpdate } from '../../types'; | ||
private getNextFunction; | ||
static getAnswerInfo(resultMessageToSend: any): [string, any[]]; | ||
private handleMiddleware; | ||
handleUpdate(update: IUpdate): Promise<void>; | ||
} |
@@ -22,2 +22,53 @@ "use strict"; | ||
} | ||
static getAnswerInfo(resultMessageToSend) { | ||
let sendMethodKey = 'send'; | ||
const answerCallArgs = []; | ||
if (resultMessageToSend instanceof Message_1.MessageCreator) { | ||
sendMethodKey = resultMessageToSend.sendType; | ||
if (resultMessageToSend instanceof Message_1.Alert || resultMessageToSend instanceof Message_1.Toast) { | ||
answerCallArgs.push(resultMessageToSend.text, resultMessageToSend.options); | ||
} | ||
else if (resultMessageToSend instanceof Message_1.ChatAction) { | ||
answerCallArgs.push(resultMessageToSend.action); | ||
} | ||
else if (resultMessageToSend instanceof Message_1.SaveFile) { | ||
answerCallArgs.push(resultMessageToSend.path, resultMessageToSend.fileId); | ||
} | ||
else if (resultMessageToSend instanceof Message_1.SaveProfilePhoto) { | ||
answerCallArgs.push(resultMessageToSend.path, resultMessageToSend.index); | ||
} | ||
else if (resultMessageToSend instanceof Message_1.Ban) { | ||
answerCallArgs.push(resultMessageToSend.untilDate, resultMessageToSend.revokeMessages, resultMessageToSend.userId); | ||
} | ||
else if (resultMessageToSend instanceof Message_1.Unban) { | ||
answerCallArgs.push(resultMessageToSend.onlyIfBanned, resultMessageToSend.userId); | ||
} | ||
else if (resultMessageToSend instanceof Message_1.Restrict) { | ||
answerCallArgs.push(resultMessageToSend.permissions, resultMessageToSend.userId, resultMessageToSend.untilDate); | ||
} | ||
else if (resultMessageToSend instanceof Message_1.Promote) { | ||
answerCallArgs.push(resultMessageToSend.permissions, resultMessageToSend.userId); | ||
} | ||
else if (resultMessageToSend instanceof Message_1.AdminTitle) { | ||
answerCallArgs.push(resultMessageToSend.title, resultMessageToSend.userId); | ||
} | ||
else if (resultMessageToSend instanceof Message_1.Forward || resultMessageToSend instanceof Message_1.Copy) { | ||
if (resultMessageToSend instanceof Message_1.Forward) | ||
answerCallArgs.push(resultMessageToSend.toChatId, resultMessageToSend.options); | ||
else if (resultMessageToSend instanceof Message_1.Copy) | ||
answerCallArgs.push(resultMessageToSend.toChatId, resultMessageToSend.keyboard, resultMessageToSend.options); | ||
} | ||
else if (resultMessageToSend instanceof Message_1.MessageSend) { | ||
sendMethodKey = 'send'; | ||
answerCallArgs.push(resultMessageToSend.content, resultMessageToSend.keyboard, resultMessageToSend.options); | ||
} | ||
else { | ||
answerCallArgs.push(resultMessageToSend); | ||
} | ||
} | ||
else { | ||
answerCallArgs.push(resultMessageToSend); | ||
} | ||
return [sendMethodKey, answerCallArgs]; | ||
} | ||
handleMiddleware(index, update, answer, middlewareIndex = 0) { | ||
@@ -49,2 +100,3 @@ const handler = this.handlers[index]; | ||
message === null || message === void 0 ? void 0 : message.dice, | ||
message === null || message === void 0 ? void 0 : message.chat, | ||
]; | ||
@@ -63,33 +115,10 @@ const handlerMethod = handler.controller[handler.methodKey].bind(handler.controller); | ||
return; | ||
let sendMethodKey = 'send'; | ||
const answerCallArgs = []; | ||
if (resultMessageToSend instanceof Message_1.MessageCreator) { | ||
sendMethodKey = resultMessageToSend.sendType; | ||
if (resultMessageToSend instanceof Message_1.Alert || resultMessageToSend instanceof Message_1.Toast) { | ||
answerCallArgs.push(resultMessageToSend.text, resultMessageToSend.options); | ||
} | ||
else if (resultMessageToSend instanceof Message_1.ChatAction) { | ||
answerCallArgs.push(resultMessageToSend.action); | ||
} | ||
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) { | ||
if (resultMessageToSend instanceof Message_1.Forward) | ||
answerCallArgs.push(resultMessageToSend.toChatId, resultMessageToSend.options); | ||
else if (resultMessageToSend instanceof Message_1.Copy) | ||
answerCallArgs.push(resultMessageToSend.toChatId, resultMessageToSend.keyboard, resultMessageToSend.options); | ||
} | ||
else if (resultMessageToSend instanceof Message_1.MessageSend) { | ||
sendMethodKey = 'send'; | ||
answerCallArgs.push(resultMessageToSend.content, resultMessageToSend.keyboard, resultMessageToSend.options); | ||
} | ||
else { | ||
answerCallArgs.push(resultMessageToSend); | ||
} | ||
const messagesToSend = [ | ||
resultMessageToSend, | ||
...(resultMessageToSend instanceof Message_1.MessageCreator ? resultMessageToSend.otherMessages : []), | ||
]; | ||
for (const messageToSend of messagesToSend) { | ||
const [sendMethodKey, answerCallArgs] = Handler.getAnswerInfo(messageToSend); | ||
await answer[sendMethodKey](...answerCallArgs); | ||
} | ||
else { | ||
answerCallArgs.push(resultMessageToSend); | ||
} | ||
await answer[sendMethodKey](...answerCallArgs); | ||
}; | ||
@@ -96,0 +125,0 @@ const failNextFunction = (middlewareIndex, handlerIndex) => { |
@@ -6,5 +6,6 @@ import { MessageCreator } from './MessageCreator'; | ||
readonly revokeMessages?: boolean; | ||
readonly userId?: number; | ||
sendType: SendTypes; | ||
type: MessageCreatorTypes; | ||
constructor(untilDate?: number, revokeMessages?: boolean); | ||
constructor(untilDate?: number, revokeMessages?: boolean, userId?: number); | ||
} |
@@ -6,6 +6,7 @@ "use strict"; | ||
class Ban extends MessageCreator_1.MessageCreator { | ||
constructor(untilDate, revokeMessages) { | ||
constructor(untilDate, revokeMessages, userId) { | ||
super({}); | ||
this.untilDate = untilDate; | ||
this.revokeMessages = revokeMessages; | ||
this.userId = userId; | ||
this.sendType = 'ban'; | ||
@@ -12,0 +13,0 @@ this.type = 'text'; |
@@ -5,5 +5,11 @@ export * from './MessageCreator'; | ||
export * from './Toast'; | ||
export * from './Restrict'; | ||
export * from './Promote'; | ||
export * from './ChatAction'; | ||
export * from './AdminTitle'; | ||
export * from './Forward'; | ||
export * from './Copy'; | ||
export * from './Unban'; | ||
export * from './Ban'; | ||
export * from './SaveProfilePhoto'; | ||
export * from './SaveFile'; |
@@ -21,6 +21,12 @@ "use strict"; | ||
__exportStar(require("./Toast"), exports); | ||
__exportStar(require("./Restrict"), exports); | ||
__exportStar(require("./Promote"), exports); | ||
__exportStar(require("./ChatAction"), exports); | ||
__exportStar(require("./AdminTitle"), exports); | ||
__exportStar(require("./Forward"), exports); | ||
__exportStar(require("./Copy"), exports); | ||
__exportStar(require("./Unban"), exports); | ||
__exportStar(require("./Ban"), exports); | ||
__exportStar(require("./SaveProfilePhoto"), exports); | ||
__exportStar(require("./SaveFile"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import { MessageCreatorTypes, SendTypes } from '../../types'; | ||
import { ContentTypes, MessageCreatorTypes, SendTypes } from '../../types'; | ||
export declare class MessageCreator { | ||
@@ -6,3 +6,5 @@ readonly options: any; | ||
sendType: SendTypes; | ||
otherMessages: (MessageCreator | ContentTypes)[]; | ||
constructor(options?: any); | ||
add(message: MessageCreator | ContentTypes): this; | ||
} |
@@ -7,5 +7,10 @@ "use strict"; | ||
this.options = options; | ||
this.otherMessages = []; | ||
} | ||
add(message) { | ||
this.otherMessages.push(message); | ||
return this; | ||
} | ||
} | ||
exports.MessageCreator = MessageCreator; | ||
//# sourceMappingURL=MessageCreator.js.map |
@@ -12,2 +12,3 @@ import { MessageEntityTypes } from '../../types'; | ||
export declare const Sender: () => ParameterDecorator; | ||
export declare const Chat: () => ParameterDecorator; | ||
export declare const UserId: () => ParameterDecorator; | ||
@@ -14,0 +15,0 @@ export declare const GetLocation: () => ParameterDecorator; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.GetDice = exports.ReceivedPoll = exports.GetPoll = exports.ReceivedVenue = exports.GetVenue = exports.ReceivedContact = exports.GetContact = exports.ReceivedLocation = exports.GetLocation = exports.UserId = exports.Sender = exports.Params = exports.CommandParams = exports.Entities = exports.Update = exports.Message = exports.Answ = exports.GetAnswer = exports.Text = exports.Entity = void 0; | ||
exports.GetDice = exports.ReceivedPoll = exports.GetPoll = exports.ReceivedVenue = exports.GetVenue = exports.ReceivedContact = exports.GetContact = exports.ReceivedLocation = exports.GetLocation = exports.UserId = exports.Chat = exports.Sender = exports.Params = exports.CommandParams = exports.Entities = exports.Update = exports.Message = exports.Answ = exports.GetAnswer = exports.Text = exports.Entity = void 0; | ||
function defineArgumentMetadata(target, propertyKey, parameterIndex, gotIndexName, metadataKey = 'gotIndex') { | ||
@@ -42,2 +42,4 @@ Reflect.defineMetadata(metadataKey, { | ||
exports.Sender = Sender; | ||
const Chat = () => buildArgumentDecorator('chat'); | ||
exports.Chat = Chat; | ||
const UserId = () => buildArgumentDecorator('userId'); | ||
@@ -44,0 +46,0 @@ exports.UserId = UserId; |
@@ -19,2 +19,3 @@ "use strict"; | ||
'dice', | ||
'chat', | ||
]; | ||
@@ -21,0 +22,0 @@ function setupArguments(target, propertyName, descriptor) { |
@@ -5,2 +5,3 @@ import { IMessageEntity, IPhotoSize } from './update.types'; | ||
import { Thumb } from '../classes'; | ||
import { IChatPermissions } from './chat.types'; | ||
export declare type IOptions = ISendOptions | ISendPhotoOptions | ISendVideoOptions; | ||
@@ -220,2 +221,30 @@ export declare type ParseModes = 'HTML' | 'Markdown' | 'MarkdownV2'; | ||
} | ||
export interface IRestrictChatMemberFetchOptions { | ||
chat_id: number | string; | ||
user_id: number; | ||
permissions: IChatPermissions; | ||
until_date?: number; | ||
} | ||
export interface IPromoteChatMemberFetchOptions extends IPromoteChatPermissions { | ||
chat_id: number | string; | ||
user_id: number; | ||
} | ||
export interface IPromoteChatPermissions { | ||
is_anonymous?: boolean; | ||
can_manage_chat?: boolean; | ||
can_post_messages?: boolean; | ||
can_edit_messages?: boolean; | ||
can_delete_messages?: boolean; | ||
can_manage_video_chats?: boolean; | ||
can_restrict_members?: boolean; | ||
can_promote_members?: boolean; | ||
can_change_info?: boolean; | ||
can_invite_users?: boolean; | ||
can_pin_messages?: boolean; | ||
} | ||
export interface ISetChatAdministratorCustomTitle { | ||
chat_id: number | string; | ||
user_id: number; | ||
custom_title: string; | ||
} | ||
export interface ISendDiceOptions extends IDefaultOptions { | ||
@@ -222,0 +251,0 @@ } |
@@ -28,3 +28,3 @@ import { IMessage } from './update.types'; | ||
pinned_message?: IMessage; | ||
permissions?: any; | ||
permissions?: IChatPermissions; | ||
slow_mode_delay?: number; | ||
@@ -38,1 +38,11 @@ message_auto_delete_time?: number; | ||
} | ||
export interface IChatPermissions { | ||
can_send_messages?: boolean; | ||
can_send_media_messages?: boolean; | ||
can_send_polls?: boolean; | ||
can_send_other_messages?: boolean; | ||
can_add_web_page_previews?: boolean; | ||
can_change_info?: boolean; | ||
can_invite_users?: boolean; | ||
can_pin_messages?: boolean; | ||
} |
@@ -5,3 +5,3 @@ import { ControllerClass } from './decorators.types'; | ||
import { Answer, Media, MessageCreator } from '../classes'; | ||
import { IUser } from './chat.types'; | ||
import { IChat, IUser } from './chat.types'; | ||
export interface IHandler { | ||
@@ -26,3 +26,4 @@ controller: ControllerClass; | ||
IPoll, | ||
IDice | ||
IDice, | ||
IChat | ||
]; | ||
@@ -29,0 +30,0 @@ export declare type ContentTypes = Media | string | undefined | null; |
import { MediaFileTypes } from './media.types'; | ||
export declare type SendTypes = 'send' | 'alert' | 'toast' | 'forward' | 'copy' | 'chatAction' | 'ban'; | ||
export declare type SendTypes = 'send' | 'alert' | 'toast' | 'forward' | 'copy' | 'chatAction' | 'ban' | 'unban' | 'restrict' | 'promote' | 'adminTitle' | 'saveFile' | 'saveProfilePhoto'; | ||
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.6", | ||
"version": "1.7.7", | ||
"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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
242232
216
3455