Skip to content

Commit 956a573

Browse files
committed
refactor: standardize channel ID naming convention across Telegram bot files
- Updated the `channel_id` field to `channelId` in the TelegramGroup interface and SQL queries for consistency. - Adjusted related functions in the ban, pin, and unban command files to reflect the new naming convention. - Ensured all database interactions use the updated field name for improved clarity and maintainability.
1 parent 281c56b commit 956a573

6 files changed

Lines changed: 21 additions & 21 deletions

File tree

telegrambot/docs/PRISMA_TO_SQL_REFACTORING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ This document summarizes the refactoring of the telegrambot project from Prisma
5555
- `expiresAt``expires_at` (TIMESTAMP)
5656

5757
#### Table: `telegram_groups`
58-
- `channelId` `channel_id` (VARCHAR)
58+
- `channelId` remains `"channelId"` in DB (use double quotes in raw SQL; no snake_case)
5959
- `name``name` (VARCHAR)
6060
- `link``link` (VARCHAR)
6161
- `active``active` (BOOLEAN)

telegrambot/src/commands/ban.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ function generateBanMessage(ctx: Context, args: string): string {
4848
*/
4949
async function fetchActiveGroups(): Promise<Array<{ channelId: string }>> {
5050
try {
51-
const groups = await queryMany<{ channel_id: string | null }>(
52-
`SELECT channel_id FROM telegram_groups WHERE active = true AND channel_id IS NOT NULL`
51+
const groups = await queryMany<{ channelId: string | null }>(
52+
`SELECT "channelId" FROM telegram_groups WHERE active = true AND "channelId" IS NOT NULL`
5353
);
5454
return groups
55-
.filter((g) => g.channel_id !== null)
56-
.map((g) => ({ channelId: g.channel_id! }));
55+
.filter((g) => g.channelId !== null)
56+
.map((g) => ({ channelId: g.channelId! }));
5757
} catch (error) {
5858
console.error('Error fetching active groups:', error);
5959
throw error;

telegrambot/src/commands/pin.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ function readPinIgnore(): string[] {
3535
*/
3636
async function fetchActiveGroups(): Promise<Array<{ channelId: string; name: string }>> {
3737
try {
38-
const groups = await queryMany<{ channel_id: string | null; name: string }>(
39-
`SELECT channel_id, name FROM telegram_groups WHERE active = true AND channel_id IS NOT NULL`
38+
const groups = await queryMany<{ channelId: string | null; name: string }>(
39+
`SELECT "channelId", name FROM telegram_groups WHERE active = true AND "channelId" IS NOT NULL`
4040
);
4141
return groups
42-
.filter((g) => g.channel_id !== null)
43-
.map((g) => ({ channelId: g.channel_id!, name: g.name }));
42+
.filter((g) => g.channelId !== null)
43+
.map((g) => ({ channelId: g.channelId!, name: g.name }));
4444
} catch (error) {
4545
console.error('Error fetching active groups:', error);
4646
throw error;

telegrambot/src/commands/unban.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ function generateUnbanMessage(ctx: Context, userId: string): string {
3636
*/
3737
async function fetchActiveGroups(): Promise<Array<{ channelId: string }>> {
3838
try {
39-
const groups = await queryMany<{ channel_id: string | null }>(
40-
`SELECT channel_id FROM telegram_groups WHERE active = true AND channel_id IS NOT NULL`
39+
const groups = await queryMany<{ channelId: string | null }>(
40+
`SELECT "channelId" FROM telegram_groups WHERE active = true AND "channelId" IS NOT NULL`
4141
);
4242
return groups
43-
.filter((g) => g.channel_id !== null)
44-
.map((g) => ({ channelId: g.channel_id! }));
43+
.filter((g) => g.channelId !== null)
44+
.map((g) => ({ channelId: g.channelId! }));
4545
} catch (error) {
4646
console.error('Error fetching active groups:', error);
4747
throw error;

telegrambot/src/workers/cronWorker.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const redisConnection = getRedisConnection();
1313
interface TelegramGroup {
1414
id: number;
1515
name: string;
16-
channel_id: string | null;
16+
channelId: string | null;
1717
members: number;
1818
}
1919

@@ -103,9 +103,9 @@ async function processMemberCountJob(job: Job<CronJobData>): Promise<JobResult>
103103

104104
// Get all active groups from database
105105
const allGroups = await queryMany<TelegramGroup>(
106-
`SELECT id, name, channel_id, members
106+
`SELECT id, name, "channelId", members
107107
FROM telegram_groups
108-
WHERE active = true AND channel_id IS NOT NULL
108+
WHERE active = true AND "channelId" IS NOT NULL
109109
ORDER BY "listOrder" ASC`
110110
);
111111

@@ -114,7 +114,7 @@ async function processMemberCountJob(job: Job<CronJobData>): Promise<JobResult>
114114
// Process groups sequentially with delay
115115
for (const group of allGroups) {
116116
try {
117-
const memberCount = await bot.telegram.getChatMembersCount(group.channel_id!);
117+
const memberCount = await bot.telegram.getChatMembersCount(group.channelId!);
118118

119119
console.log(group.name, memberCount + ' user');
120120
await updateMembers(group.id, memberCount);

telegrambot/telegram.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { query, queryMany } from './src/utils/db-client';
1212
interface TelegramGroup {
1313
id: number;
1414
name: string;
15-
channel_id: string | null;
15+
channelId: string | null;
1616
members: number;
1717
}
1818

@@ -46,9 +46,9 @@ cron.schedule('00 01 * * *', async () => {
4646
try {
4747
// Get all active groups from database
4848
const allGroups = await queryMany<TelegramGroup>(
49-
`SELECT id, name, channel_id, members
49+
`SELECT id, name, "channelId", members
5050
FROM telegram_groups
51-
WHERE active = true AND channel_id IS NOT NULL
51+
WHERE active = true AND "channelId" IS NOT NULL
5252
ORDER BY "listOrder" ASC`
5353
);
5454

@@ -59,7 +59,7 @@ cron.schedule('00 01 * * *', async () => {
5959
// Get group member count from Telegram and update database
6060
for (const group of allGroups) {
6161
try {
62-
const memberCount = await bot.telegram.getChatMembersCount(group.channel_id!);
62+
const memberCount = await bot.telegram.getChatMembersCount(group.channelId!);
6363

6464
console.log(group.name, memberCount + ' user');
6565
await updateMembers(group.id, memberCount);

0 commit comments

Comments
 (0)