added some commands
This commit is contained in:
parent
47ec9c91c6
commit
0143dc9abe
12 changed files with 1279 additions and 22 deletions
|
@ -5,5 +5,5 @@
|
|||
"singleQuote": false,
|
||||
"printWidth": 100,
|
||||
"trailingComma": "none",
|
||||
"vueIndentScriptAndStyle": true
|
||||
"bracketSpacing": true
|
||||
}
|
||||
|
|
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||
"editor.formatOnSave": true,
|
||||
"editor.formatOnType": true
|
||||
}
|
|
@ -2,8 +2,9 @@
|
|||
"name": "venbot-tg",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"start": "node dist/index.js",
|
||||
"build": "tsc"
|
||||
"start": "node --no-deprecation dist/index.js",
|
||||
"build": "tsc",
|
||||
"dev": "nodemon src/index.ts"
|
||||
},
|
||||
"author": "nin0dev",
|
||||
"devDependencies": {
|
||||
|
@ -11,5 +12,9 @@
|
|||
"prettier": "^3.3.3",
|
||||
"ts-node": "^10.9.2",
|
||||
"typescript": "^5.6.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"sqlite3": "^5.1.7",
|
||||
"telegraf": "^4.16.3"
|
||||
}
|
||||
}
|
||||
|
|
1100
pnpm-lock.yaml
1100
pnpm-lock.yaml
File diff suppressed because it is too large
Load diff
58
src/client.ts
Normal file
58
src/client.ts
Normal file
|
@ -0,0 +1,58 @@
|
|||
import { Telegraf } from "telegraf";
|
||||
import { message } from "telegraf/filters";
|
||||
|
||||
import config from "./config";
|
||||
import { minky } from "./commands/minky";
|
||||
import { Command } from "./utils/types";
|
||||
import { forgejoDown } from "./commands/forgejo-down";
|
||||
import { source } from "./commands/source";
|
||||
|
||||
const commands: Command[] = [forgejoDown, minky, source];
|
||||
export const bot = new Telegraf(config.token);
|
||||
|
||||
bot.on(message("text"), async (ctx) => {
|
||||
const msg = ctx.message;
|
||||
const author = await ctx.getChatMember(msg.from.id);
|
||||
config.prefixes.forEach((p) => {
|
||||
if (msg.text[0] !== p) return;
|
||||
});
|
||||
const rawArgs = msg.text.split(" ");
|
||||
let handled = false;
|
||||
try {
|
||||
commands.forEach(async (c) => {
|
||||
if (handled) return;
|
||||
if (c.name === rawArgs[0].replace("v", "") || `/${c.name}@vc_venbot` === rawArgs[0]) {
|
||||
if (
|
||||
c.modOnly &&
|
||||
author.status !== "administrator" &&
|
||||
c.modOnly &&
|
||||
author.status !== "creator"
|
||||
)
|
||||
return await ctx.reply("💢 You can't do this!");
|
||||
if (c.ownerOnly && msg.from.id !== 1911826384)
|
||||
return await ctx.reply("💢 You can't do this!");
|
||||
handled = true;
|
||||
c.handler(ctx, rawArgs.splice(0, 1));
|
||||
}
|
||||
c.aliases.forEach(async (a) => {
|
||||
if (a === rawArgs[0].replace("v", "") || `/${a}@vc_venbot` === rawArgs[0]) {
|
||||
if (
|
||||
c.modOnly &&
|
||||
author.status !== "administrator" &&
|
||||
c.modOnly &&
|
||||
author.status !== "creator"
|
||||
)
|
||||
return await ctx.reply("💢 You can't do this!");
|
||||
if (c.ownerOnly && msg.from.id !== 1911826384)
|
||||
return await ctx.reply("💢 You can't do this!");
|
||||
handled = true;
|
||||
c.handler(ctx, rawArgs.splice(0, 1));
|
||||
}
|
||||
});
|
||||
});
|
||||
} catch (c) {}
|
||||
});
|
||||
|
||||
process.on("uncaughtException", (e) => {});
|
||||
|
||||
process.on("unhandledRejection", (e) => {});
|
21
src/commands/forgejo-down.ts
Normal file
21
src/commands/forgejo-down.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import { Context } from "telegraf";
|
||||
import { Command, CommandTypes } from "../utils/types";
|
||||
|
||||
async function handler(ctx: Context, args: string[]) {
|
||||
const req = await fetch("https://git.nin0.dev");
|
||||
if (req.status === 200) {
|
||||
await ctx.reply("No");
|
||||
} else {
|
||||
await ctx.reply(`Yes (Error code ${req.status.toString()})`);
|
||||
}
|
||||
}
|
||||
|
||||
export const forgejoDown: Command = {
|
||||
name: "forgejo-down?",
|
||||
aliases: ["fj-down?", "ifd", "is-forgejo-down", "fjd?"],
|
||||
description: "Check if nin0's Forgejo is down",
|
||||
type: CommandTypes.Info,
|
||||
modOnly: false,
|
||||
ownerOnly: false,
|
||||
handler
|
||||
};
|
17
src/commands/minky.ts
Normal file
17
src/commands/minky.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
import { Context } from "telegraf";
|
||||
import { Command, CommandTypes } from "../utils/types";
|
||||
|
||||
async function handler(ctx: Context, args: string[]) {
|
||||
await ctx.sendChatAction("upload_photo");
|
||||
await ctx.replyWithPhoto(`https://minky.materii.dev?${Date.now().toString()}`);
|
||||
}
|
||||
|
||||
export const minky: Command = {
|
||||
name: "minky",
|
||||
aliases: ["mink", "minker"],
|
||||
description: "minker",
|
||||
type: CommandTypes.Fun,
|
||||
modOnly: false,
|
||||
ownerOnly: false,
|
||||
handler
|
||||
};
|
18
src/commands/source.ts
Normal file
18
src/commands/source.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
import { Context } from "telegraf";
|
||||
import { Command, CommandTypes } from "../utils/types";
|
||||
|
||||
async function handler(ctx: Context, args: string[]) {
|
||||
await ctx.reply(
|
||||
"I am free software! You can find my code at https://git.nin0.dev/nin0/venbot-tg"
|
||||
);
|
||||
}
|
||||
|
||||
export const source: Command = {
|
||||
name: "source-code",
|
||||
aliases: ["sc", "source"],
|
||||
description: "View venbot-tg's source code",
|
||||
type: CommandTypes.Info,
|
||||
modOnly: false,
|
||||
ownerOnly: false,
|
||||
handler
|
||||
};
|
|
@ -0,0 +1,6 @@
|
|||
import { bot } from "./client";
|
||||
import { Command } from "./utils/types";
|
||||
|
||||
const commands: Command[] = [];
|
||||
|
||||
bot.launch();
|
14
src/utils/database.ts
Normal file
14
src/utils/database.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
import { Database } from "sqlite3";
|
||||
|
||||
const db = new Database("database.db");
|
||||
|
||||
export async function write(query: string, args: string[]): Promise<boolean> {
|
||||
await db.run(query, args);
|
||||
}
|
||||
|
||||
export async function read(query: string, args: string[]) {
|
||||
let rt = [];
|
||||
db.each(query, args, (q) => {
|
||||
rt.
|
||||
})
|
||||
}
|
18
src/utils/types.ts
Normal file
18
src/utils/types.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
import { Context } from "telegraf";
|
||||
|
||||
export enum CommandTypes {
|
||||
Fun,
|
||||
Moderation,
|
||||
Utility,
|
||||
Info
|
||||
}
|
||||
|
||||
export type Command = {
|
||||
name: string;
|
||||
aliases: string[];
|
||||
description: string;
|
||||
type: CommandTypes;
|
||||
modOnly: boolean;
|
||||
ownerOnly: boolean;
|
||||
handler: (ctx: Context, args: string[]) => void;
|
||||
};
|
|
@ -1,16 +1,11 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
|
||||
"target": "es5",
|
||||
"module": "amd",
|
||||
"strictNullChecks": false,
|
||||
"outDir": "dist/",
|
||||
"outFile": "dist/index.js",
|
||||
"allowJs": true,
|
||||
"noImplicitAny": false,
|
||||
"strict": false
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
"exclude": ["node_modules"]
|
||||
}
|
Loading…
Reference in a new issue