Add typings for tgfancy

This commit is contained in:
Giorgio Garasto
2018-05-30 19:39:49 +02:00
parent bb1cc0e143
commit 03f64c066a
4 changed files with 126 additions and 0 deletions

76
types/tgfancy/index.d.ts vendored Normal file
View File

@@ -0,0 +1,76 @@
// Type definitions for tgfancy 0.13
// Project: https://github.com/GochoMugo/tgfancy
// Definitions by: Giorgio Garasto <https://github.com/Dabolus>
// 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<Tgfancy.ResolvedChat | Error>;
openWebSocket(): Promise<undefined | Error>;
closeWebSocket(): Promise<undefined | Error>;
hasOpenWebSocket(): boolean;
kickChatMember(chatId: number | string, userId: number | string, ban?: boolean): Promise<boolean | Error>;
}
export = Tgfancy;

View File

@@ -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);

View File

@@ -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"
]
}

View File

@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}