Skip to content

Commit

Permalink
Merge pull request #68 from MSD-Incorporated/recode
Browse files Browse the repository at this point in the history
A little recode
  • Loading branch information
MasedMSD authored Nov 12, 2024
2 parents 3eb3ab9 + b917bd5 commit 7a6ae86
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 123 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ This bot was created for channel and chat management.

### Bun

- Install [Bun](https://bun.sh/)
- Install all dependencies: `bun install`
- Use command `bun bun:start`

### NodeJS

- Install [NodeJS](https://nodejs.org)
- Install all dependencies: `npm install`
- Build the bot: `node run build`
- Use command `node run start`
Binary file modified bun.lockb
Binary file not shown.
17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "msdbot_telegram",
"version": "0.2.4",
"version": "0.3.0",
"author": "MasedMSD",
"module": "./src/index.ts",
"main": "./dist/index.js",
Expand All @@ -25,20 +25,19 @@
},
"dependencies": {
"@roziscoding/grammy-autoquote": "^2.0.6",
"dotenv": "^16.4.5",
"drizzle-orm": "^0.36.1",
"grammy": "^1.24.0",
"grammy": "^1.31.2",
"moment": "^2.30.1",
"pg": "^8.12.0",
"sagiri": "^4.2.0",
"pg": "^8.13.1",
"sagiri": "^4.2.3",
"telegra.ph": "^1.0.1",
"tslib": "^2.6.2"
"tslib": "^2.8.1"
},
"devDependencies": {
"@types/bun": "^1.1.11",
"@types/node": "^22.7.5",
"@types/bun": "^1.1.13",
"@types/node": "^22.9.0",
"@types/pg": "^8.11.6",
"drizzle-kit": "^0.26.2",
"drizzle-kit": "^0.28.0",
"prettier": "^3.3.0",
"typegram": "^5.2.0",
"typescript": "^5.6.3"
Expand Down
24 changes: 24 additions & 0 deletions src/handlers/autocaching.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { Context, NextFunction } from "grammy";
import { Database } from "../structures/database";

export const autoCaching = async (ctx: Context & { database: Database }, database: Database, next: NextFunction) => {
ctx.database = database;
await next();

const user = ctx.from;
if (!user || user.is_bot || user.id == 777000) return await next();

const dbuser = await database.resolveUser(user!, true);

if (
user?.first_name !== dbuser?.first_name ||
user?.last_name !== dbuser?.last_name ||
user?.username !== dbuser?.username
) {
await database.updateUser(user!, {
first_name: user?.first_name,
last_name: user?.last_name,
username: user?.username,
});
}
};
8 changes: 3 additions & 5 deletions src/handlers/dick.composer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ const random = (min: number, max: number, includeMax?: boolean) =>

export const dickComposer: Composer<Context & { database: Database }> = new Composer();

dickComposer.command("dick", async ctx => {
dickComposer.command(["dick", "cock", "dck"], async ctx => {
const user = ctx.msg.from!;
const db_user_dick = (await ctx.database.resolveDick(user, true))!;

const size = db_user_dick.size;
const { size, timestamp } = (await ctx.database.resolveDick(user, true))!;

const now = moment().unix();
const lastUsed = now - db_user_dick.timestamp.getTime();
const lastUsed = now - timestamp.getTime();

if (lastUsed < timeout) {
const timeLeft = moment((timeout - lastUsed) * 1000)
Expand Down
42 changes: 0 additions & 42 deletions src/handlers/eval.command.ts

This file was deleted.

5 changes: 3 additions & 2 deletions src/handlers/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
export * from "./autocaching";

export * from "./dick.composer";
export * from "./githubLink.composer";
export * from "./msdincorporated.composer";
export * from "./randomEmoji.compose";
export * from "./randomShit.composer";
export * from "./telegraph.composer";

export * from "./eval.command";
export * from "./exec.command";
export * from "./start.command";
13 changes: 10 additions & 3 deletions src/handlers/msdincorporated.composer.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Composer } from "grammy";
import { Composer, InputFile } from "grammy";
import { resolve } from "path";
import { cwd } from "process";
import sagiri from "sagiri";
import type { Message, MessageEntity } from "typegram";

const channelID = -1001528929804;
const chatChannelID = -1001528929804;
const chatChannelID = -1001705068191;

const urlParser = (urls: string[]) => {
const sortedURLs: [string, string][] = [];
Expand Down Expand Up @@ -60,7 +62,7 @@ msdIncorporatedComposer.on(["channel_post::hashtag", "edited_channel_post::hasht
});

msdIncorporatedComposer.on(":photo").on(":is_automatic_forward", async ctx => {
if (chatChannelID !== (ctx.message?.forward_origin! as Message).chat.id) return;
if (channelID !== (ctx.message?.forward_origin! as Message).chat.id) return;
if (!ctx.message?.caption?.includes("#Hentai")) return;
if (ctx.message?.caption?.includes("#RealLife") || ctx.message?.caption?.includes("#Video")) return;
if (ctx.message?.media_group_id) return;
Expand Down Expand Up @@ -94,3 +96,8 @@ msdIncorporatedComposer.on(":photo").on(":is_automatic_forward", async ctx => {
}
);
});

msdIncorporatedComposer.on(":new_chat_members", async ctx => {
if (ctx.chat.id !== chatChannelID) return;
ctx.replyWithAnimation(new InputFile(resolve(cwd(), "src", "media", "welcome.gif")));
});
10 changes: 0 additions & 10 deletions src/handlers/randomEmoji.compose.ts

This file was deleted.

14 changes: 14 additions & 0 deletions src/handlers/randomShit.composer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Composer } from "grammy";

export const randomShitComposer = new Composer();

randomShitComposer.on("message:text", async (ctx, next) => {
await next();

if (ctx.message.from.is_bot) return;
if (Math.random() < 0.01) return ctx.react("👀");
});

randomShitComposer.on("::mention", ctx => {
if (ctx.message?.text == `@${ctx.me.username}`) return ctx.reply("Я тут!");
});
7 changes: 1 addition & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import { config } from "dotenv";
import { resolve } from "path";
import { Client } from "./structures/client";

config({ path: resolve(process.cwd(), ".env") });
const client = new Client();

client.init();
new Client().init();
53 changes: 8 additions & 45 deletions src/structures/client.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { autoQuote } from "@roziscoding/grammy-autoquote";
import { Bot, InputFile, type Context } from "grammy";
import { resolve } from "path";
import { cwd } from "process";
import type { UserFromGetMe } from "typegram";
import { Bot, type Context } from "grammy";
import {
autoCaching,
dickComposer,
evalCommand,
execCommand,
githubLinkComposer,
msdIncorporatedComposer,
randomEmojiComposer,
randomShitComposer,
startCommand,
telegraphComposer,
} from "../handlers";
} from "handlers";
import type { UserFromGetMe } from "typegram";
import { Database } from "./database";

const onStart = ({ id, username }: UserFromGetMe) => console.log(`${username} [${id}] started!`);
Expand All @@ -32,53 +30,18 @@ export class Client {
await this.database.connect();

this.bot.use(autoQuote());
this.bot.use(async (ctx, next) => {
ctx.database = this.database;

await next();
});

this.bot.use(async (ctx, next) => {
const user = ctx.from;
if (!user || user.is_bot || user.id == 777000) return await next();

const dbuser = await this.database.resolveUser(user!, true);

if (
user?.first_name !== dbuser?.first_name ||
user?.last_name !== dbuser?.last_name ||
user?.username !== dbuser?.username
) {
await this.database.updateUser(user!, {
first_name: user?.first_name,
last_name: user?.last_name,
username: user?.username,
});
}

await next();
});

this.bot.use(async (ctx, next) => autoCaching(ctx, this.database, next));
this.bot.use(dickComposer);
this.bot.use(githubLinkComposer);
this.bot.use(msdIncorporatedComposer);
this.bot.use(randomEmojiComposer);
this.bot.use(randomShitComposer);
this.bot.use(telegraphComposer);

this.bot.command("eval", evalCommand);
this.bot.command("exec", execCommand);
this.bot.command("start", startCommand);

this.bot.on("::mention", ctx => {
if (ctx.message?.text == `@${this.bot.botInfo.username}`) return ctx.reply("Я тут!");
});

this.bot.on(":new_chat_members", async ctx => {
if (ctx.chat.id !== -1001705068191) return;
ctx.replyWithAnimation(new InputFile(resolve(cwd(), "src", "media", "welcome.gif")));
});

this.bot.catch(console.error);

await this.bot.init();
await this.bot.start({ drop_pending_updates: true, onStart });
};
Expand Down
2 changes: 1 addition & 1 deletion src/structures/database.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { and, eq, type DBQueryConfig, type ExtractTablesWithRelations } from "drizzle-orm";
import { drizzle, NodePgDatabase } from "drizzle-orm/node-postgres";
import { drizzle, type NodePgDatabase } from "drizzle-orm/node-postgres";
import { Client } from "pg";
import type { User as TelegramUser } from "typegram";
import * as schema from "../drizzle/index";
Expand Down

0 comments on commit 7a6ae86

Please sign in to comment.