Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to TypeScript and Telegraf v4 #40

Open
wants to merge 44 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
3c7d3b2
refactor: migrate to typescript
EdJoPaTo Oct 7, 2020
7b2b45a
docs(readme): describe changes with typescript refactoring
EdJoPaTo Oct 7, 2020
133130e
fix: export context
EdJoPaTo Oct 7, 2020
2078409
chore(test): add testcoverage via nyc
EdJoPaTo Oct 7, 2020
8ad34e5
chore(npm): ensure build on pack
EdJoPaTo Oct 7, 2020
2722bcc
style: order imports
EdJoPaTo Oct 7, 2020
9a6dfe9
fix: require resourceKey on getTemplate
EdJoPaTo Oct 7, 2020
017453d
test(context): ensure context works as expected
EdJoPaTo Oct 7, 2020
8f9024d
test: simpler to read template
EdJoPaTo Oct 7, 2020
d1e0368
chore(npm): update xo
EdJoPaTo Oct 23, 2020
ba5929d
TemplateData in match method shouldnt be required as original version…
jfkz Nov 10, 2020
eff7e41
refactor: ensure typesafe array access
EdJoPaTo Jan 3, 2021
5806914
refactor(xo): adapt to new rules
EdJoPaTo Jan 3, 2021
1563771
refactor: update to js-yaml v4
EdJoPaTo Jan 11, 2021
5ad8d88
feat: update to telegraf v4
EdJoPaTo Jan 11, 2021
40de4d9
chore(dependabot): activate
EdJoPaTo Jan 11, 2021
0a08326
chore(github-workflow): test with nodejs
EdJoPaTo Jan 11, 2021
3dad929
chore(travis): remove
EdJoPaTo Jan 11, 2021
51175ed
docs(readme): no longer standard style
EdJoPaTo Jan 12, 2021
06a4c41
fix: correct match return type
EdJoPaTo Feb 3, 2021
7a10e79
refactor: create RegExpExecArray via Object.assign
EdJoPaTo Feb 3, 2021
0471509
chore(npm): bump xo from 0.37.1 to 0.38.1 (#4)
dependabot[bot] Feb 22, 2021
f0ac5b8
fix: correct typings
EdJoPaTo Apr 4, 2021
0e1b15a
refactor: update tsconfig
EdJoPaTo Apr 4, 2021
4d90140
ci(dependabot): improve config
EdJoPaTo Apr 4, 2021
b7f0d57
chore(npm): bump @types/node from 14.14.43 to 15.0.1 (#8)
dependabot[bot] May 1, 2021
73a38d6
chore(npm): update dependencies
EdJoPaTo May 1, 2021
a0b7c8f
chore(npm): reorder package.json
EdJoPaTo May 1, 2021
85d0693
ci(actions): test on Node.js 16
EdJoPaTo May 1, 2021
9838614
ci(dependabot): increase pullrequest limit
EdJoPaTo May 1, 2021
c0fc907
refactor(xo): adapt to new rules
EdJoPaTo May 10, 2021
5329eef
refactor(xo): adapt to new rules
EdJoPaTo May 18, 2021
4f678d7
chore(npm): bump ts-node from 9.1.1 to 10.0.0 (#10)
dependabot[bot] May 25, 2021
a96542e
chore(npm): bump del-cli from 3.0.1 to 4.0.0 (#11)
dependabot[bot] Jun 22, 2021
b5f52f1
chore(npm): bump @types/node from 15.14.1 to 16.0.0 (#13)
dependabot[bot] Jul 6, 2021
f311cce
ci(dependabot): improve config
EdJoPaTo Jul 7, 2021
2beba79
ci(nodejs): check weekly with current dependencies
EdJoPaTo Jul 7, 2021
c3d718d
refactor(xo): adapt to new rules
EdJoPaTo Jul 7, 2021
1354174
build(npm): bump xo from 0.41.0 to 0.42.0 (#15)
dependabot[bot] Jul 19, 2021
19dbb56
refactor: typescript variant of tableize-object
EdJoPaTo Jul 31, 2021
bfe35ef
refactor: remove telegraf dependency and work with grammY
EdJoPaTo Jul 31, 2021
0484226
fixup! refactor: remove telegraf dependency and work with grammY
EdJoPaTo Jul 31, 2021
37d8e23
docs(readme): remove shields
EdJoPaTo Jul 31, 2021
4c628c1
docs: explain archive
EdJoPaTo Aug 4, 2021
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
8 changes: 3 additions & 5 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

[*.txt]
trim_trailing_whitespace = false
[*.{yml,yaml}]
indent_style = space
indent_size = 2
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
20 changes: 20 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
open-pull-requests-limit: 30
schedule:
interval: "weekly"
time: "03:37" # UTC
commit-message:
prefix: "build(npm):"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
commit-message:
prefix: "ci(actions):"
27 changes: 27 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Node.js

on:
push:
pull_request:
schedule:
# Check if it works with current dependencies (weekly on Wednesday 2:32 UTC)
- cron: '32 2 * * 3'

jobs:
test:
name: Node.js ${{ matrix.node-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version:
- 16
- 14
- 12
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
36 changes: 4 additions & 32 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,34 +1,6 @@
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
.nyc_output
/*-*.*.*.tgz
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
dist
node_modules

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history
package-lock.json
yarn.lock
7 changes: 0 additions & 7 deletions .travis.yml

This file was deleted.

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# i18n for grammY and Telegraf

This fork is now available as [@grammyjs/i18n](https://github.com/grammyjs/i18n) and works with both grammY and Telegraf.
56 changes: 0 additions & 56 deletions examples/example-bot.js

This file was deleted.

65 changes: 65 additions & 0 deletions examples/example-grammy-bot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import * as path from 'path'

import {Bot, Context as BaseContext, session} from 'grammy'

import {I18n, pluralize, I18nContext} from '../source'

interface Session {
apples?: number;
}

interface MyContext extends BaseContext {
readonly i18n: I18nContext;
session: Session;
}

// I18n options
const i18n = new I18n({
directory: path.resolve(__dirname, 'locales'),
defaultLanguage: 'en',
sessionName: 'session',
useSession: true,
templateData: {
pluralize,
uppercase: (value: string) => value.toUpperCase(),
},
})

const bot = new Bot<MyContext>(process.env['BOT_TOKEN']!)
bot.use(session())
bot.use(i18n.middleware())

// Start message handler
bot.command('start', async ctx => ctx.reply(ctx.i18n.t('greeting'), {parse_mode: 'HTML'}))

// Set locale to `en`
bot.command('en', async ctx => {
ctx.i18n.locale('en-US')
return ctx.reply(ctx.i18n.t('greeting'), {parse_mode: 'HTML'})
})

// Set locale to `ru`
bot.command('ru', async ctx => {
ctx.i18n.locale('ru')
return ctx.reply(ctx.i18n.t('greeting'), {parse_mode: 'HTML'})
})

// Add apple to cart
bot.command('add', async ctx => {
ctx.session.apples = ctx.session.apples ?? 0
ctx.session.apples++
const message = ctx.i18n.t('cart', {apples: ctx.session.apples})
return ctx.reply(message)
})

// Add apple to cart
bot.command('cart', async ctx => {
const message = ctx.i18n.t('cart', {apples: ctx.session.apples ?? 0})
return ctx.reply(message)
})

// Checkout
bot.command('checkout', async ctx => ctx.reply(ctx.i18n.t('checkout')))

// eslint-disable-next-line @typescript-eslint/no-floating-promises
bot.start()
65 changes: 65 additions & 0 deletions examples/example-telegraf-bot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import * as path from 'path'

import {Telegraf, Context as BaseContext, session} from 'telegraf'

import {I18n, pluralize, I18nContext} from '../source'

interface Session {
apples?: number;
}

interface MyContext extends BaseContext {
readonly i18n: I18nContext;
session: Session;
}

// I18n options
const i18n = new I18n({
directory: path.resolve(__dirname, 'locales'),
defaultLanguage: 'en',
sessionName: 'session',
useSession: true,
templateData: {
pluralize,
uppercase: (value: string) => value.toUpperCase(),
},
})

const bot = new Telegraf<MyContext>(process.env['BOT_TOKEN']!)
bot.use(session())
bot.use(i18n.middleware())

// Start message handler
bot.command('start', async ctx => ctx.reply(ctx.i18n.t('greeting'), {parse_mode: 'HTML'}))

// Set locale to `en`
bot.command('en', async ctx => {
ctx.i18n.locale('en-US')
return ctx.reply(ctx.i18n.t('greeting'), {parse_mode: 'HTML'})
})

// Set locale to `ru`
bot.command('ru', async ctx => {
ctx.i18n.locale('ru')
return ctx.reply(ctx.i18n.t('greeting'), {parse_mode: 'HTML'})
})

// Add apple to cart
bot.command('add', async ctx => {
ctx.session.apples = ctx.session.apples ?? 0
ctx.session.apples++
const message = ctx.i18n.t('cart', {apples: ctx.session.apples})
return ctx.reply(message)
})

// Add apple to cart
bot.command('cart', async ctx => {
const message = ctx.i18n.t('cart', {apples: ctx.session.apples ?? 0})
return ctx.reply(message)
})

// Checkout
bot.command('checkout', async ctx => ctx.reply(ctx.i18n.t('checkout')))

// eslint-disable-next-line @typescript-eslint/no-floating-promises
bot.launch()
1 change: 1 addition & 0 deletions examples/locales/en.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
greeting: <b>Hello ${uppercase(from.first_name)}!</b>
cart: ${from.first_name}, in your cart ${pluralize(apples, 'apple', 'apples')}
checkout: Thank you
help: help
61 changes: 0 additions & 61 deletions lib/context.js

This file was deleted.

Loading