Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

19 changes: 0 additions & 19 deletions .eslintrc

This file was deleted.

26 changes: 26 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = {
parser: '@typescript-eslint/parser',
extends: [
'eslint:recommended',
'prettier'
],
plugins: ['@typescript-eslint', 'prettier'],
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module'
},
env: {
node: true,
es6: true,
mocha: true
},
rules: {
'prettier/prettier': 'error',
'@typescript-eslint/no-unused-vars': 'error',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-non-null-assertion': 'warn'
},
ignorePatterns: ['lib/', 'node_modules/', '*.js']
};
17 changes: 16 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,19 @@ output.md
output/
lib/
lib-doc/
.DS_Store
dist/
.DS_Store

# Prevent compiled files in source directories
src/**/*.js
src/**/*.d.ts
src/**/*.js.map
src/**/*.d.ts.map
test/**/*.js
test/**/*.d.ts
test/**/*.js.map
test/**/*.d.ts.map
examples/**/*.js
examples/**/*.d.ts
examples/**/*.js.map
examples/**/*.d.ts.map
12 changes: 12 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ output/
test/
examples/
lib-doc/
dist/
src/

# TypeScript configs
tsconfig.json
tsconfig.build.json
tsconfig.test.json
tsconfig.examples.json

# ESLint configs
eslint.config.mjs

# dotfiles
.travis.yml
Expand All @@ -19,3 +30,4 @@ lib-doc/
.babelrc
.gitignore
.git
.prettierrc
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"semi": true,
"trailingComma": "es5",
"singleQuote": true,
"printWidth": 100,
"tabWidth": 2,
"useTabs": false
}
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
language: node_js
node_js:
- "12"
- "10"
- "8"
- "6"
- "22"
- "20"
- "18"
- "16"
#
# create required bash scripts to run builds on pull requests in the future
#
Expand Down
110 changes: 110 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import js from '@eslint/js';
import tseslint from 'typescript-eslint';
import prettier from 'eslint-plugin-prettier';
import globals from 'globals';

export default [
// Base JavaScript configuration
js.configs.recommended,
{
languageOptions: {
globals: {
...globals.node,
},
},
plugins: {
prettier,
},
rules: {
'prettier/prettier': 'error',
'no-unused-vars': 'off',
'no-console': 'warn',
'prefer-const': 'error',
'no-var': 'error',
},
},

// JavaScript files - more lenient
// {
// files: ['**/*.js'],
// rules: {
// '@typescript-eslint/no-require-imports': 'off',
// '@typescript-eslint/no-var-requires': 'off',
// 'no-undef': 'off', // Allow global requires in JS files
// },
// },

// TypeScript configuration - only for .ts files except test
...tseslint.configs.recommended,
{
files: ['**/*.ts'],
ignores: ['test/**/*', '**/*.test.ts', '**/*.spec.ts'],
languageOptions: {
parser: tseslint.parser,
parserOptions: {
project: './tsconfig.build.json',
},
},
rules: {
'@typescript-eslint/no-unused-vars': 'error',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-non-null-assertion': 'warn',
'@typescript-eslint/no-require-imports': 'error',
'@typescript-eslint/no-var-requires': 'error',
'@typescript-eslint/no-empty-object-type': 'warn',
'@typescript-eslint/no-unsafe-function-type': 'warn',
},
},

// Test files - no project for TypeScript
{
files: ['test/**/*.{js,ts}', '**/*.test.{js,ts}', '**/*.spec.{js,ts}'],
languageOptions: {
parser: tseslint.parser,
parserOptions: {
// No project for test files
},
globals: {
describe: 'readonly',
it: 'readonly',
before: 'readonly',
after: 'readonly',
beforeEach: 'readonly',
afterEach: 'readonly',
expect: 'readonly',
},
},
rules: {
'no-console': 'off',
'@typescript-eslint/no-unused-vars': 'off', // Test files often have unused setup vars
'@typescript-eslint/no-explicit-any': 'off', // Test files often need any for mocking
'@typescript-eslint/no-require-imports': 'off', // Allow require in tests
'@typescript-eslint/no-var-requires': 'off', // Allow require in tests
},
},

// Examples - more lenient
{
files: ['examples/**/*.{js,ts}'],
rules: {
'no-console': 'off',
'@typescript-eslint/no-unused-vars': 'warn',
},
},

// Ignore patterns
{
ignores: [
'lib/**/*',
'node_modules/**/*',
'docs/**/*',
'coverage/**/*',
'*.min.js',
'dist/**/*',
'**/*.js',

],
},
];
19 changes: 9 additions & 10 deletions examples/game/game.js → examples/game/game.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
/**
* This example demonstrates using HTML5 games with Telegram.
*/
/* eslint-disable no-console */

const TOKEN = process.env.TELEGRAM_TOKEN || 'YOUR_TELEGRAM_BOT_TOKEN';
const gameName = process.env.TELEGRAM_GAMENAME || 'YOUR_TELEGRAM_GAMENAME';
// Specify '0' to use ngrok i.e. localhost tunneling
let url = process.env.URL || 'https://<PUBLIC-URL>';
const port = process.env.PORT || 8080;
const port = process.env.PORT ? parseInt(process.env.PORT, 10) : 8080;

const TelegramBot = require('../..');
const express = require('express');
const path = require('path');
import { TelegramBot } from '../..';
import express from 'express';
import path from 'path';

const bot = new TelegramBot(TOKEN, { polling: true });
const app = express();
Expand All @@ -25,29 +24,29 @@ app.set('view engine', 'ejs');
// you paid for. :)
if (url === '0') {
const ngrok = require('ngrok');
ngrok.connect(port, function onConnect(error, u) {
ngrok.connect(port, (error: Error | null, u: string) => {
if (error) throw error;
url = u;
console.log(`Game tunneled at ${url}`);
});
}

// Matches /start
bot.onText(/\/start/, function onPhotoText(msg) {
bot.onText(/\/start/, (msg: any) => {
bot.sendGame(msg.chat.id, gameName);
});

// Handle callback queries
bot.on('callback_query', function onCallbackQuery(callbackQuery) {
bot.on('callback_query', (callbackQuery: any) => {
bot.answerCallbackQuery(callbackQuery.id, { url });
});

// Render the HTML game
app.get('/', function requestListener(req, res) {
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'game.html'));
});

// Bind server to port
app.listen(port, function listen() {
app.listen(port, () => {
console.log(`Server is listening at http://localhost:${port}`);
});
92 changes: 0 additions & 92 deletions examples/polling.js

This file was deleted.

Loading