diff --git a/types/tgfancy/index.d.ts b/types/tgfancy/index.d.ts new file mode 100644 index 0000000000..d37083456d --- /dev/null +++ b/types/tgfancy/index.d.ts @@ -0,0 +1,76 @@ +// Type definitions for tgfancy 0.13 +// Project: https://github.com/GochoMugo/tgfancy +// Definitions by: Giorgio Garasto +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +import * as TelegramBot from 'node-telegram-bot-api'; + +declare namespace Tgfancy { + interface ChatIdResolutionOptions { + resolve(token: string, chatId: number | string, callback: ((error: Error | null, target: any) => void)): void; + } + + interface EmojificationOptions { + emojify(text: string): string; + } + + interface RatelimitingOptions { + maxRetries?: number; + timeout?: number; + notify?(methodName: string, ...args: any[]): void; + maxBackoff?: number; + } + + interface WebSocketOptions { + url: string; + autoOpen?: boolean; + } + + interface TgfancyOptions { + chatIdResolution?: boolean | ChatIdResolutionOptions; + emojification?: boolean | EmojificationOptions; + kickWithoutBan?: boolean; + openshiftWebHook?: boolean; + orderedSending?: boolean; + ratelimiting?: boolean | RatelimitingOptions; + textPaging?: boolean; + webSocket?: boolean | WebSocketOptions; + } + + interface ConstructorOptions extends TelegramBot.ConstructorOptions { + tgfancy?: TgfancyOptions; + } + + interface ResolvedChat { + id: number | string; + username: string; + type: string; + when: string; + } + + interface ResolvedGroupOrChannel extends ResolvedChat { + title: string; + } + + interface ResolvedUser extends ResolvedChat { + first_name: string; + last_name?: string; + } +} + +declare class Tgfancy extends TelegramBot { + constructor(token: string, options?: Tgfancy.ConstructorOptions); + + resolveChatId(chatId: string): Promise; + + openWebSocket(): Promise; + + closeWebSocket(): Promise; + + hasOpenWebSocket(): boolean; + + kickChatMember(chatId: number | string, userId: number | string, ban?: boolean): Promise; +} + +export = Tgfancy; diff --git a/types/tgfancy/tgfancy-tests.ts b/types/tgfancy/tgfancy-tests.ts new file mode 100644 index 0000000000..75f2f9fe1c --- /dev/null +++ b/types/tgfancy/tgfancy-tests.ts @@ -0,0 +1,24 @@ +import tgfancy = require('tgfancy'); + +const MyTgFancyBot = new tgfancy('token', { + tgfancy: { + chatIdResolution: true, + emojification: true, + kickWithoutBan: true, + ratelimiting: { + maxRetries: 132, + timeout: 40000 + }, + webSocket: { + url: 'ws://example.ws', + autoOpen: true + } + } +}); + +MyTgFancyBot.resolveChatId('chat id'); +MyTgFancyBot.openWebSocket(); +MyTgFancyBot.closeWebSocket(); +MyTgFancyBot.hasOpenWebSocket(); +MyTgFancyBot.kickChatMember('chat id', 'user id'); +MyTgFancyBot.kickChatMember(13128219, 3181422, true); diff --git a/types/tgfancy/tsconfig.json b/types/tgfancy/tsconfig.json new file mode 100644 index 0000000000..386549171f --- /dev/null +++ b/types/tgfancy/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "tgfancy-tests.ts" + ] +} diff --git a/types/tgfancy/tslint.json b/types/tgfancy/tslint.json new file mode 100644 index 0000000000..d88586e5bd --- /dev/null +++ b/types/tgfancy/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}