added some commands

This commit is contained in:
nin0dev 2024-09-13 12:11:12 -04:00
parent 47ec9c91c6
commit 0143dc9abe
Signed by: nin0
GPG key ID: 3FA8F96ABAE04214
12 changed files with 1279 additions and 22 deletions

View file

@ -5,5 +5,5 @@
"singleQuote": false,
"printWidth": 100,
"trailingComma": "none",
"vueIndentScriptAndStyle": true
"bracketSpacing": true
}

5
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,5 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.formatOnType": true
}

View file

@ -1,15 +1,20 @@
{
"name": "venbot-tg",
"main": "dist/index.js",
"scripts": {
"start": "node dist/index.js",
"build": "tsc"
},
"author": "nin0dev",
"devDependencies": {
"nodemon": "^3.1.4",
"prettier": "^3.3.3",
"ts-node": "^10.9.2",
"typescript": "^5.6.2"
}
"name": "venbot-tg",
"main": "dist/index.js",
"scripts": {
"start": "node --no-deprecation dist/index.js",
"build": "tsc",
"dev": "nodemon src/index.ts"
},
"author": "nin0dev",
"devDependencies": {
"nodemon": "^3.1.4",
"prettier": "^3.3.3",
"ts-node": "^10.9.2",
"typescript": "^5.6.2"
},
"dependencies": {
"sqlite3": "^5.1.7",
"telegraf": "^4.16.3"
}
}

File diff suppressed because it is too large Load diff

58
src/client.ts Normal file
View 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) => {});

View 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
View 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
View 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
};

View file

@ -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
View 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
View 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;
};

View file

@ -1,16 +1,11 @@
{
"compilerOptions": {
"target": "es5",
"module": "amd",
"target": "es5",
"strictNullChecks": false,
"outDir": "dist/",
"outFile": "dist/index.js",
"allowJs": true,
"noImplicitAny": false,
"strict": false
},
"exclude": [
"node_modules"
]
"exclude": ["node_modules"]
}