Skip to content

Commit

Permalink
updating dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Fazendaaa committed Sep 8, 2020
1 parent 8fb8e74 commit 6629ba9
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 51 deletions.
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ci
docs
documentation
_config.yml
.snk
.travis.yml
app.jon
build.sh
index.md
LICENSE
Procfile
9 changes: 8 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ EXPOSE 8080

WORKDIR /usr/src/app

COPY package.json .

RUN [ "npm", "install" ]

COPY . .

ENTRYPOINT [ "npm", "run", "docker" ]
RUN [ "mv", "session.d.ts", "node_modules/telegraf-session-local/lib/" ]
RUN [ "npm", "run", "build" ]

ENTRYPOINT [ "npm", "run", "bot" ]
Empty file modified build.sh
100644 → 100755
Empty file.
34 changes: 34 additions & 0 deletions session.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
declare module 'telegraf-session-local' {
import { AdapterSync, AdapterAsync, BaseAdapter } from 'lowdb'
import { Middleware } from 'telegraf';
import { TelegrafContext } from 'telegraf/typings/context';

export interface LocalSessionOptions<TSession> {
storage?: AdapterSync | AdapterAsync
database?: string
property?: string
state?: TSession
format?: {
serialize?: (value: TSession) => string
deserialize?: (value: string) => TSession
}
getSessionKey?: (ctx: TelegrafContext) => string
}

class LocalSession<TSession> {
public DB: unknown

constructor(options?: LocalSessionOptions<TSession>)

getSessionKey(ctx: TelegrafContext): string
getSession(key: string): TSession
saveSession(key: string, data: TSession): Promise<TSession>
middleware(property?: string): Middleware<TelegrafContext>
static get storageFileSync(): AdapterSync
static get storageFileAsync(): AdapterAsync
static get storageMemory(): AdapterSync
static get storageBase(): BaseAdapter
}

export default LocalSession;
}
38 changes: 0 additions & 38 deletions src/@types/telegraf-session-local/index.d.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { InlineKeyboardMarkup } from 'telegram-typings';
import { ContextMessageUpdate } from 'telegraf';
import I18n from 'telegraf-i18n';
import { TelegrafContext } from 'telegraf/typings/context';

export interface Context {
id?: number;
Expand All @@ -23,7 +23,7 @@ interface ISession {
user: boolean;
}

export interface IBotContext extends ContextMessageUpdate {
export interface IBotContext extends TelegrafContext {
readonly i18n: I18n;
session: ISession | null;
}
19 changes: 10 additions & 9 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { config } from 'dotenv';
import { connect } from 'mongoose';
import { connect, set } from 'mongoose';
import { join } from 'path';
import { TelegrafConstructor } from 'telegraf';
import I18n from 'telegraf-i18n';
import LocalSession from 'telegraf-session-local';
import { IBotContext } from '.';
Expand All @@ -15,7 +14,7 @@ config();

// ---------------------------------------------------------------------------------------------------------------------

const Telegraf = <TelegrafConstructor> require('telegraf');
const Telegraf = require('telegraf');

const bot = new Telegraf(process.env.BOT_KEY);
const i18n = new I18n({
Expand All @@ -42,14 +41,16 @@ bot.telegram.getMe()

let dbStatus = false;

connect(process.env.MONGODB_URI, { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => {
cleanDB();
console.log('DB connected.');
connect(<string>process.env.MONGODB_URI, {
useNewUrlParser: true,
useUnifiedTopology: true
}).then(() => {
// https://stackoverflow.com/a/51918795/7092954
set('useCreateIndex', true);
set('useFindAndModify', false);

dbStatus = true;
})
.catch(err => {
}).catch(err => {
console.error(err);

dbStatus = false;
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"ci",
"node_modules",
"dist",
"__tests__"
"__tests__",
"session.d.ts"
]
}

0 comments on commit 6629ba9

Please sign in to comment.