Compare commits
No commits in common. "7309a343194ba9f84262a29fd6ac51f0c7befc2a" and "806828b30edb77b80949bff737682df16fee25e4" have entirely different histories.
7309a34319
...
806828b30e
|
|
@ -9,7 +9,6 @@
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"debug-level": "^3.1.2",
|
|
||||||
"input": "^1.0.1",
|
"input": "^1.0.1",
|
||||||
"mongodb": "^6.3.0",
|
"mongodb": "^6.3.0",
|
||||||
"mongoose": "^8.1.1",
|
"mongoose": "^8.1.1",
|
||||||
|
|
@ -3047,6 +3046,7 @@
|
||||||
"version": "4.3.0",
|
"version": "4.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
|
||||||
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
|
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
|
||||||
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"color-convert": "^2.0.1"
|
"color-convert": "^2.0.1"
|
||||||
},
|
},
|
||||||
|
|
@ -3297,28 +3297,12 @@
|
||||||
"tslib": "^2.3.1"
|
"tslib": "^2.3.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/asyncc": {
|
|
||||||
"version": "2.0.6",
|
|
||||||
"resolved": "https://registry.npmjs.org/asyncc/-/asyncc-2.0.6.tgz",
|
|
||||||
"integrity": "sha512-m3nkCP6CKuLubt2vwqoOio8NmOJPjUL6dcaNNxqc9q4H2Rq9wNs+2UsIzBegiJzUtoyh9X9iBe4GIhqu1uOvqA==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=6.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/asynckit": {
|
"node_modules/asynckit": {
|
||||||
"version": "0.4.0",
|
"version": "0.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||||
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==",
|
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/atomic-sleep": {
|
|
||||||
"version": "1.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/atomic-sleep/-/atomic-sleep-1.0.0.tgz",
|
|
||||||
"integrity": "sha512-kNOjDqAh7px0XWNI+4QbzoiR/nTkHAWNud2uvnJquD1/x5a7EQZMJT0AczqK0Qn67oY/TTQ1LbUKajZpp3I9tQ==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=8.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/available-typed-arrays": {
|
"node_modules/available-typed-arrays": {
|
||||||
"version": "1.0.5",
|
"version": "1.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz",
|
"resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz",
|
||||||
|
|
@ -3876,6 +3860,7 @@
|
||||||
"version": "4.1.2",
|
"version": "4.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
|
||||||
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
|
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
|
||||||
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ansi-styles": "^4.1.0",
|
"ansi-styles": "^4.1.0",
|
||||||
"supports-color": "^7.1.0"
|
"supports-color": "^7.1.0"
|
||||||
|
|
@ -4118,6 +4103,7 @@
|
||||||
"version": "2.0.1",
|
"version": "2.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
|
||||||
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
|
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
|
||||||
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"color-name": "~1.1.4"
|
"color-name": "~1.1.4"
|
||||||
},
|
},
|
||||||
|
|
@ -4128,7 +4114,8 @@
|
||||||
"node_modules/color-name": {
|
"node_modules/color-name": {
|
||||||
"version": "1.1.4",
|
"version": "1.1.4",
|
||||||
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
|
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
|
||||||
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
|
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
|
||||||
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/color-support": {
|
"node_modules/color-support": {
|
||||||
"version": "1.1.3",
|
"version": "1.1.3",
|
||||||
|
|
@ -4504,31 +4491,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/debug-level": {
|
|
||||||
"version": "3.1.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/debug-level/-/debug-level-3.1.2.tgz",
|
|
||||||
"integrity": "sha512-YyD8cnCVnTlN7la4/cKUWJq15clsrff8ZXbj7RND8dd0YAl+/SdBhtfemZUY3oU8oxXPfGirrPfPBPFaulLlGA==",
|
|
||||||
"dependencies": {
|
|
||||||
"asyncc": "^2.0.6",
|
|
||||||
"chalk": "^4.1.2",
|
|
||||||
"fast-safe-stringify": "^2.1.1",
|
|
||||||
"flatstr": "^1.0.12",
|
|
||||||
"map-lru": "^2.0.0",
|
|
||||||
"ms": "^2.1.3",
|
|
||||||
"sonic-boom": "^3.2.1"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=12"
|
|
||||||
},
|
|
||||||
"optionalDependencies": {
|
|
||||||
"debug": "^4.3.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/debug-level/node_modules/ms": {
|
|
||||||
"version": "2.1.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
|
||||||
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="
|
|
||||||
},
|
|
||||||
"node_modules/decamelize": {
|
"node_modules/decamelize": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz",
|
||||||
|
|
@ -5741,11 +5703,6 @@
|
||||||
"integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==",
|
"integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/fast-safe-stringify": {
|
|
||||||
"version": "2.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.1.1.tgz",
|
|
||||||
"integrity": "sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA=="
|
|
||||||
},
|
|
||||||
"node_modules/fastq": {
|
"node_modules/fastq": {
|
||||||
"version": "1.17.0",
|
"version": "1.17.0",
|
||||||
"resolved": "https://registry.npmjs.org/fastq/-/fastq-1.17.0.tgz",
|
"resolved": "https://registry.npmjs.org/fastq/-/fastq-1.17.0.tgz",
|
||||||
|
|
@ -5928,11 +5885,6 @@
|
||||||
"node": "^10.12.0 || >=12.0.0"
|
"node": "^10.12.0 || >=12.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/flatstr": {
|
|
||||||
"version": "1.0.12",
|
|
||||||
"resolved": "https://registry.npmjs.org/flatstr/-/flatstr-1.0.12.tgz",
|
|
||||||
"integrity": "sha512-4zPxDyhCyiN2wIAtSLI6gc82/EjqZc1onI4Mz/l0pWrAlsSfYH/2ZIcU+e3oA2wDwbzIWNKwa23F8rh6+DRWkw=="
|
|
||||||
},
|
|
||||||
"node_modules/flatted": {
|
"node_modules/flatted": {
|
||||||
"version": "3.2.9",
|
"version": "3.2.9",
|
||||||
"resolved": "https://registry.npmjs.org/flatted/-/flatted-3.2.9.tgz",
|
"resolved": "https://registry.npmjs.org/flatted/-/flatted-3.2.9.tgz",
|
||||||
|
|
@ -6490,6 +6442,7 @@
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
|
||||||
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
|
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
|
||||||
|
"dev": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
}
|
}
|
||||||
|
|
@ -8612,14 +8565,6 @@
|
||||||
"node": ">=4"
|
"node": ">=4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/map-lru": {
|
|
||||||
"version": "2.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/map-lru/-/map-lru-2.0.0.tgz",
|
|
||||||
"integrity": "sha512-a5TlnsxvczXMY7U/U4P0b7GI3KSAonc+u2MQtWQS5L21K9UV4fYQbbgktj3eqP5ch04XtCOcoqR0OlILo906nA==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=12"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/map-obj": {
|
"node_modules/map-obj": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/map-obj/-/map-obj-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/map-obj/-/map-obj-2.0.0.tgz",
|
||||||
|
|
@ -12832,14 +12777,6 @@
|
||||||
"node": ">= 10"
|
"node": ">= 10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/sonic-boom": {
|
|
||||||
"version": "3.8.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/sonic-boom/-/sonic-boom-3.8.0.tgz",
|
|
||||||
"integrity": "sha512-ybz6OYOUjoQQCQ/i4LU8kaToD8ACtYP+Cj5qd2AO36bwbdewxWJ3ArmJ2cr6AvxlL2o0PqnCcPGUgkILbfkaCA==",
|
|
||||||
"dependencies": {
|
|
||||||
"atomic-sleep": "^1.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/sort-keys": {
|
"node_modules/sort-keys": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/sort-keys/-/sort-keys-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/sort-keys/-/sort-keys-2.0.0.tgz",
|
||||||
|
|
@ -13199,6 +13136,7 @@
|
||||||
"version": "7.2.0",
|
"version": "7.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
|
||||||
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
|
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
|
||||||
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"has-flag": "^4.0.0"
|
"has-flag": "^4.0.0"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,6 @@
|
||||||
"typescript": "4.9.5"
|
"typescript": "4.9.5"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"debug-level": "^3.1.2",
|
|
||||||
"input": "^1.0.1",
|
"input": "^1.0.1",
|
||||||
"mongodb": "^6.3.0",
|
"mongodb": "^6.3.0",
|
||||||
"mongoose": "^8.1.1",
|
"mongoose": "^8.1.1",
|
||||||
|
|
|
||||||
68
src/bot.ts
68
src/bot.ts
|
|
@ -1,9 +1,6 @@
|
||||||
import { Context, NarrowedContext, Telegraf } from 'telegraf';
|
import { Telegraf } from 'telegraf';
|
||||||
import { message } from 'telegraf/filters';
|
import { message } from 'telegraf/filters';
|
||||||
import { ChatFromGetChat, Update } from 'telegraf/typings/core/types/typegram';
|
import { ChatFromGetChat } from 'telegraf/typings/core/types/typegram';
|
||||||
import { ioc } from './utils/ioc';
|
|
||||||
import { AudienceChangeController, audienceChangeSymbol } from './controllers/audienceChange';
|
|
||||||
import { log } from './utils/log';
|
|
||||||
|
|
||||||
export type ChannelInfo = {
|
export type ChannelInfo = {
|
||||||
chatId: number,
|
chatId: number,
|
||||||
|
|
@ -12,7 +9,7 @@ export type ChannelInfo = {
|
||||||
|
|
||||||
export type MessageInfo = {
|
export type MessageInfo = {
|
||||||
|
|
||||||
};
|
}
|
||||||
|
|
||||||
export class ChannelBot {
|
export class ChannelBot {
|
||||||
private readonly bot: Telegraf;
|
private readonly bot: Telegraf;
|
||||||
|
|
@ -32,8 +29,6 @@ export class ChannelBot {
|
||||||
process.once('SIGINT', () => this.bot.stop('SIGINT'));
|
process.once('SIGINT', () => this.bot.stop('SIGINT'));
|
||||||
process.once('SIGTERM', () => this.bot.stop('SIGTERM'));
|
process.once('SIGTERM', () => this.bot.stop('SIGTERM'));
|
||||||
|
|
||||||
this.bot.on('chat_member', this.handleChatMemberUpdate.bind(this));
|
|
||||||
|
|
||||||
this.bot.launch(
|
this.bot.launch(
|
||||||
{
|
{
|
||||||
allowedUpdates: [
|
allowedUpdates: [
|
||||||
|
|
@ -48,45 +43,6 @@ export class ChannelBot {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleChatMemberUpdate(ctx: NarrowedContext<Context<Update>, Update.ChatMemberUpdate>): Promise<void> {
|
|
||||||
try {
|
|
||||||
log.bot.info('chat_member event', JSON.stringify(ctx.chatMember));
|
|
||||||
|
|
||||||
const change = ctx.chatMember;
|
|
||||||
const status = change.new_chat_member.status;
|
|
||||||
const statusBefore = change.old_chat_member.status;
|
|
||||||
const role = ['restricted', 'left', 'kicked'].includes(status)
|
|
||||||
? statusBefore
|
|
||||||
: status;
|
|
||||||
|
|
||||||
const ctrl = ioc.get<AudienceChangeController>(audienceChangeSymbol);
|
|
||||||
|
|
||||||
const chatMemberCount = await this.bot.telegram.getChatMembersCount(change.chat.id);
|
|
||||||
|
|
||||||
ctrl.add({
|
|
||||||
channelId: change.chat.id,
|
|
||||||
user: {
|
|
||||||
id: change.new_chat_member.user.id,
|
|
||||||
username: change.new_chat_member.user.username,
|
|
||||||
firstName: change.new_chat_member.user.first_name,
|
|
||||||
lastName: change.new_chat_member.user.last_name,
|
|
||||||
isBot: change.new_chat_member.user.is_bot,
|
|
||||||
isPremium: change.new_chat_member.user.is_premium ? true : false,
|
|
||||||
role,
|
|
||||||
},
|
|
||||||
timestamp: new Date(change.date * 1000),
|
|
||||||
status,
|
|
||||||
statusBefore,
|
|
||||||
invitedByLink: change.invite_link?.invite_link ?? undefined,
|
|
||||||
|
|
||||||
memberCountAfter: chatMemberCount,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
log.bot.error('chat member change processing error', err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async getChannelInfo(channelId: number): Promise<ChannelInfo> {
|
public async getChannelInfo(channelId: number): Promise<ChannelInfo> {
|
||||||
|
|
||||||
const memberCount = await this.bot.telegram.getChatMembersCount(channelId);
|
const memberCount = await this.bot.telegram.getChatMembersCount(channelId);
|
||||||
|
|
@ -107,3 +63,21 @@ export class ChannelBot {
|
||||||
// await sendChannelStats(ctx.chat.id);
|
// await sendChannelStats(ctx.chat.id);
|
||||||
// });
|
// });
|
||||||
|
|
||||||
|
// bot.on('new_chat_members', async (ctx) => {
|
||||||
|
// console.log('new_chat_members');
|
||||||
|
// console.dir(ctx.chatMember);
|
||||||
|
|
||||||
|
// await sendChannelStats(ctx.chat.id);
|
||||||
|
// });
|
||||||
|
|
||||||
|
// bot.on('chat_member', async (ctx) => {
|
||||||
|
// console.log('chat_member');
|
||||||
|
// console.dir(ctx.chatMember);
|
||||||
|
|
||||||
|
// await sendChannelStats(ctx.chat.id);
|
||||||
|
// });
|
||||||
|
|
||||||
|
// // bot.start((ctx) => ctx.reply('Welcome'));
|
||||||
|
// // bot.help((ctx) => ctx.reply('Send me a sticker'));
|
||||||
|
// // bot.on(message('sticker'), (ctx) => ctx.reply('👍'));
|
||||||
|
// // bot.hears('hi', (ctx) => ctx.reply('Hey there'));
|
||||||
|
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
import { AudienceChangeModel, IAudienceChange } from '../model/audienceChange';
|
|
||||||
import { IUser } from '../model/user';
|
|
||||||
import { ioc } from '../utils/ioc';
|
|
||||||
import { log } from '../utils/log';
|
|
||||||
|
|
||||||
export const audienceChangeSymbol = Symbol('audienceChange');
|
|
||||||
|
|
||||||
export class AudienceChangeController {
|
|
||||||
public static register() {
|
|
||||||
ioc.set(audienceChangeSymbol, new AudienceChangeController());
|
|
||||||
}
|
|
||||||
|
|
||||||
public async add(change: IAudienceChange): Promise<void> {
|
|
||||||
log.db.info(`inserting audience change for chat ${change.channelId} ${change.status} ${change.user.id}`);
|
|
||||||
await AudienceChangeModel.create(change);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
import mongoose from "mongoose";
|
|
||||||
|
|
||||||
export async function connect() {
|
|
||||||
const dbUri = process.env.MONGO_URI ?? '';
|
|
||||||
|
|
||||||
await mongoose.connect(dbUri);
|
|
||||||
console.log("Connected to db");
|
|
||||||
}
|
|
||||||
32
src/index.ts
32
src/index.ts
|
|
@ -1,16 +1,8 @@
|
||||||
import { ChannelClient } from './client';
|
import { ChannelClient } from './client';
|
||||||
import { ChannelBot } from './bot';
|
import { ChannelBot } from './bot';
|
||||||
import { connect } from './database';
|
|
||||||
import { ioc } from './utils/ioc';
|
|
||||||
import { AudienceChangeController } from './controllers/audienceChange';
|
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
|
|
||||||
try {
|
|
||||||
await connect();
|
|
||||||
|
|
||||||
AudienceChangeController.register();
|
|
||||||
|
|
||||||
const apiId = Number(process.env.TELEGRAM_API_ID ?? '0');
|
const apiId = Number(process.env.TELEGRAM_API_ID ?? '0');
|
||||||
const apiHash = process.env.TELEGRAM_API_HASH ?? '';
|
const apiHash = process.env.TELEGRAM_API_HASH ?? '';
|
||||||
const apiSession = process.env.TELEGRAM_API_SESSION ?? '';
|
const apiSession = process.env.TELEGRAM_API_SESSION ?? '';
|
||||||
|
|
@ -30,29 +22,19 @@ import { AudienceChangeController } from './controllers/audienceChange';
|
||||||
);
|
);
|
||||||
|
|
||||||
await bot.connect();
|
await bot.connect();
|
||||||
// await client.connect();
|
await client.connect();
|
||||||
|
|
||||||
// try {
|
const messages = await client.getChannelMessages(channelId, { statsOnly: true });
|
||||||
// const messages = await client.getChannelMessages(channelId, { statsOnly: true });
|
console.dir(messages);
|
||||||
// console.dir(messages);
|
|
||||||
|
|
||||||
// const users = await client.getChannelUsers(channelId);
|
const users = await client.getChannelUsers(channelId);
|
||||||
|
|
||||||
// console.dir(users);
|
console.dir(users);
|
||||||
// }
|
console.dir(await bot.getChannelInfo(channelId));
|
||||||
// catch (err) {
|
|
||||||
// console.error(err);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// console.dir(await bot.getChannelInfo(channelId));
|
|
||||||
|
|
||||||
// for (const message of messages)
|
// for (const message of messages)
|
||||||
// console.dir(await client.getChannelMessage(channelId, message.id));
|
// console.dir(await client.getChannelMessage(channelId, message.id));
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
})()
|
})()
|
||||||
.catch((err) => console.error);
|
.catch((err) => console.error);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,40 +0,0 @@
|
||||||
import mongoose from "mongoose";
|
|
||||||
|
|
||||||
import { IUser, UserSchema } from './user';
|
|
||||||
|
|
||||||
export type IAudienceChange = {
|
|
||||||
channelId: number,
|
|
||||||
|
|
||||||
user: IUser,
|
|
||||||
|
|
||||||
timestamp: Date,
|
|
||||||
status: string,
|
|
||||||
statusBefore: string,
|
|
||||||
invitedByLink: string | undefined,
|
|
||||||
|
|
||||||
memberCountAfter: number;
|
|
||||||
};
|
|
||||||
|
|
||||||
const AudienceChangeSchema = new mongoose.Schema<IAudienceChange>(
|
|
||||||
{
|
|
||||||
channelId: { type: Number, required: true },
|
|
||||||
|
|
||||||
user: UserSchema,
|
|
||||||
|
|
||||||
timestamp: Date,
|
|
||||||
status: { type: String },
|
|
||||||
statusBefore: { type: String },
|
|
||||||
invitedByLink: { type: String },
|
|
||||||
|
|
||||||
memberCountAfter: { type: Number, required: true },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
collection: 'audienceChange',
|
|
||||||
timestamps: true,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
export const AudienceChangeModel = mongoose.model<IAudienceChange>(
|
|
||||||
'audienceChange',
|
|
||||||
AudienceChangeSchema,
|
|
||||||
);
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
import mongoose from 'mongoose';
|
|
||||||
|
|
||||||
export type IUser = {
|
|
||||||
id: number;
|
|
||||||
username: string | undefined;
|
|
||||||
firstName: string;
|
|
||||||
lastName: string | undefined;
|
|
||||||
isBot: boolean;
|
|
||||||
isPremium: boolean;
|
|
||||||
role: string; // 'member' | 'administrator' | 'creator';
|
|
||||||
}
|
|
||||||
|
|
||||||
export const UserSchema = new mongoose.Schema<IUser>(
|
|
||||||
{
|
|
||||||
id: { type: Number, required: true },
|
|
||||||
username: { type: String, required: true },
|
|
||||||
firstName: { type: String },
|
|
||||||
lastName: { type: String },
|
|
||||||
isBot: { type: Boolean, required: true },
|
|
||||||
isPremium: { type: Boolean, required: true },
|
|
||||||
role: { type: String, required: true },
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
class IOC {
|
|
||||||
private readonly items = new Map<Symbol, any>();
|
|
||||||
|
|
||||||
public set<T>(key: Symbol, obj: T): void {
|
|
||||||
this.items.set(key, obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
public get<T>(key: Symbol): T {
|
|
||||||
return this.items.get(key) as T;
|
|
||||||
}
|
|
||||||
|
|
||||||
public create<A extends any[], T extends { new(...args: A): T; }>(
|
|
||||||
key: Symbol,
|
|
||||||
...args: A
|
|
||||||
): T {
|
|
||||||
const cls = this.get(key) as { new(...args: A): T; };
|
|
||||||
return new cls(...args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const ioc = new IOC();
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
import Log from 'debug-level';
|
|
||||||
|
|
||||||
const ns = 'tgstat';
|
|
||||||
|
|
||||||
export const log = {
|
|
||||||
namespace: ns,
|
|
||||||
bot: new Log(`${ns}:bot`),
|
|
||||||
client: new Log(`${ns}:client`),
|
|
||||||
db: new Log(`${ns}:db`),
|
|
||||||
};
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue