First build
This commit is contained in:
@@ -1,21 +1,21 @@
|
||||
import type { Context } from '#root/bot/context.js'
|
||||
import { isAdmin } from '#root/bot/filters/is-admin.js'
|
||||
import { setCommandsHandler } from '#root/bot/handlers/commands/setcommands.js'
|
||||
import { logHandle } from '#root/bot/helpers/logging.js'
|
||||
import { chatAction } from '@grammyjs/auto-chat-action'
|
||||
import { Composer } from 'grammy'
|
||||
import { chatAction } from "@grammyjs/auto-chat-action";
|
||||
import { Composer } from "grammy";
|
||||
import type { Context } from "#root/bot/context.js";
|
||||
import { isAdmin } from "#root/bot/filters/is-admin.js";
|
||||
import { setCommandsHandler } from "#root/bot/handlers/commands/setcommands.js";
|
||||
import { logHandle } from "#root/bot/helpers/logging.js";
|
||||
|
||||
const composer = new Composer<Context>()
|
||||
const composer = new Composer<Context>();
|
||||
|
||||
const feature = composer
|
||||
.chatType('private')
|
||||
.filter(isAdmin)
|
||||
.chatType("private")
|
||||
.filter(ctx => isAdmin(ctx.config.botAdmins)(ctx));
|
||||
|
||||
feature.command(
|
||||
'setcommands',
|
||||
logHandle('command-setcommands'),
|
||||
chatAction('typing'),
|
||||
setCommandsHandler,
|
||||
)
|
||||
"setcommands",
|
||||
logHandle("command-setcommands"),
|
||||
chatAction("typing"),
|
||||
setCommandsHandler
|
||||
);
|
||||
|
||||
export { composer as adminFeature }
|
||||
export { composer as adminFeature };
|
||||
|
||||
49
src/bot/features/blacklistDelete.ts
Normal file
49
src/bot/features/blacklistDelete.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { Composer } from "grammy";
|
||||
import type { Context } from "#root/bot/context.js";
|
||||
import { logHandle } from "#root/bot/helpers/logging.js";
|
||||
|
||||
const composer = new Composer<Context>();
|
||||
|
||||
const feature = composer.chatType(["group", "supergroup"]);
|
||||
|
||||
const GROUP_IDS = process.env.GROUP_IDS
|
||||
? process.env.GROUP_IDS.split(",")
|
||||
: undefined;
|
||||
|
||||
feature.hears(
|
||||
/(x.com|twitter.com)/g,
|
||||
logHandle("blacklist-detection"),
|
||||
async (ctx: Context) => {
|
||||
if (ctx.chat && ctx.msg) {
|
||||
if (GROUP_IDS !== undefined) {
|
||||
const groupID = ctx.chat.id;
|
||||
const flag = GROUP_IDS.includes(`${groupID}`);
|
||||
const username = ctx.msg.from?.username;
|
||||
|
||||
if (flag) {
|
||||
ctx.msg.delete();
|
||||
await ctx.reply(
|
||||
ctx.t(
|
||||
`@${username} Twitter and X links are not allowed here\\. Please consider sharing the media directly or from other social media sources or websites\\. No administration action was taken against you other than the message being deleted\\.`
|
||||
),
|
||||
{ parse_mode: "MarkdownV2" }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!GROUP_IDS) {
|
||||
await ctx.reply(
|
||||
ctx.t(
|
||||
`There was a problem retrieving the whitelist. Check the env variables and try again\\.`
|
||||
),
|
||||
{
|
||||
parse_mode: "MarkdownV2",
|
||||
reply_parameters: { message_id: ctx.msg.message_id }
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
export { composer as blacklistDetection };
|
||||
32
src/bot/features/botInfoCommand.ts
Normal file
32
src/bot/features/botInfoCommand.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { Composer } from "grammy";
|
||||
import type { Context } from "#root/bot/context.js";
|
||||
import { logHandle } from "#root/bot/helpers/logging.js";
|
||||
|
||||
const composer = new Composer<Context>();
|
||||
|
||||
const feature = composer.chatType(["group", "supergroup", "private"]);
|
||||
|
||||
// const GROUP_IDS = process.env.GROUP_IDS
|
||||
// ? process.env.GROUP_IDS.split(",")
|
||||
// : undefined;
|
||||
|
||||
feature.hears(
|
||||
"/botInfo",
|
||||
logHandle("bot-info-command"),
|
||||
async (ctx: Context) => {
|
||||
console.info(
|
||||
"BOT INFO! BOT INFO! BOT INFO! BOT INFO! BOT INFO! BOT INFO! BOT INFO! BOT INFO!"
|
||||
);
|
||||
if (ctx.chat && ctx.msg) {
|
||||
await ctx.reply(
|
||||
`I am a bot designed to delete any Twitter/X links and reformatting services within groups\\. By default I only work with whitelisted group IDs\\.\n\nYou can fork me from this link: https://github\\.com/LucidCreationsMedia/No\\-Twitter\\-Bot and deploy me for use in your own groups\\!`,
|
||||
{
|
||||
parse_mode: "MarkdownV2",
|
||||
reply_parameters: { message_id: ctx.msg.message_id }
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
export { composer as botInfoCommand };
|
||||
32
src/bot/features/getGroupIDCommand.ts
Normal file
32
src/bot/features/getGroupIDCommand.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { Composer } from "grammy";
|
||||
import type { Context } from "#root/bot/context.js";
|
||||
import { logHandle } from "#root/bot/helpers/logging.js";
|
||||
|
||||
const composer = new Composer<Context>();
|
||||
|
||||
const feature = composer.chatType(["group", "supergroup"]);
|
||||
|
||||
const GROUP_IDS = process.env.GROUP_IDS
|
||||
? process.env.GROUP_IDS.split(",")
|
||||
: undefined;
|
||||
|
||||
feature.hears(
|
||||
"/getGroupID",
|
||||
logHandle("get-group-id"),
|
||||
async (ctx: Context) => {
|
||||
if (ctx.chat && ctx.msg) {
|
||||
if (GROUP_IDS !== undefined) {
|
||||
const groupID = ctx.chat.id;
|
||||
const flag = GROUP_IDS.includes(`${groupID}`);
|
||||
if (flag) {
|
||||
await ctx.reply(`The group id is: \`${groupID}\``, {
|
||||
parse_mode: "MarkdownV2",
|
||||
reply_parameters: { message_id: ctx.msg.message_id }
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
export { composer as getGroupIDCommand };
|
||||
64
src/bot/features/helpCommand.ts
Normal file
64
src/bot/features/helpCommand.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import { Composer } from "grammy";
|
||||
import type { Context } from "#root/bot/context.js";
|
||||
import { logHandle } from "#root/bot/helpers/logging.js";
|
||||
|
||||
const composer = new Composer<Context>();
|
||||
|
||||
const feature = composer.chatType(["group", "supergroup"]);
|
||||
|
||||
const GROUP_IDS = process.env.GROUP_IDS
|
||||
? process.env.GROUP_IDS.split(",")
|
||||
: undefined;
|
||||
|
||||
feature.hears(
|
||||
"/help",
|
||||
logHandle("blacklist-detection"),
|
||||
async (ctx: Context) => {
|
||||
if (ctx.chat && ctx.msg) {
|
||||
if (GROUP_IDS !== undefined) {
|
||||
const groupID = ctx.chat.id;
|
||||
const flag = GROUP_IDS.includes(`${groupID}`);
|
||||
// const username = ctx.msg.from?.username;
|
||||
|
||||
if (flag) {
|
||||
await ctx.reply(
|
||||
`**Here are the availible commands you can use:**\n\n/getGroupID \\- replied with the ID of the group I am in\\.\n\n/isLCMGRoup \\- Checks if this group's ID is on the whitelist and responds accordingly\\.\n\n/botInfo \\- Info about me and how to fork me to deploy for your own use\\.\n\n/help \\- Displays this help message\\.`,
|
||||
{
|
||||
parse_mode: "MarkdownV2",
|
||||
reply_parameters: { message_id: ctx.msg.message_id }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (!flag) {
|
||||
await ctx.reply(
|
||||
`**Since this is not a whitelisted group the features are limited\\!\\!**\n\nHere are the availible commands you can use:\n\n/isLCMGRoup \\- Checks if this group's ID is on the whitelist and responds accordingly\\.\n\n/botInfo \\- Info about me and how to fork me to deploy for your own use\\.\n\n/help \\- Displays this help message\\.`,
|
||||
{
|
||||
parse_mode: "MarkdownV2",
|
||||
reply_parameters: { message_id: ctx.msg.message_id }
|
||||
}
|
||||
);
|
||||
await ctx.reply(
|
||||
`This group is NOT in the whitelisted and is NOT a part of the LCM Telegram groups/communities\\. I am a bot designed to delete any Twitter/X links and reformatting services within groups\\. You can fork me from this link: https://github\\.com/LucidCreationsMedia/No\\-Twitter\\-Bot and deploy me for use in your own groups\\!`,
|
||||
{
|
||||
parse_mode: "MarkdownV2",
|
||||
reply_parameters: { message_id: ctx.msg.message_id }
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!GROUP_IDS) {
|
||||
await ctx.reply(
|
||||
`There was a problem retrieving the whitelist. Check the env variables and try again\\.`,
|
||||
{
|
||||
parse_mode: "MarkdownV2",
|
||||
reply_parameters: { message_id: ctx.msg.message_id }
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
export { composer as helpCommand };
|
||||
57
src/bot/features/isLCMGroup.ts
Normal file
57
src/bot/features/isLCMGroup.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import { Composer } from "grammy";
|
||||
import type { Context } from "#root/bot/context.js";
|
||||
import { logHandle } from "#root/bot/helpers/logging.js";
|
||||
|
||||
const composer = new Composer<Context>();
|
||||
|
||||
const feature = composer.chatType(["group", "supergroup"]);
|
||||
|
||||
const GROUP_IDS = process.env.GROUP_IDS
|
||||
? process.env.GROUP_IDS.split(",")
|
||||
: undefined;
|
||||
|
||||
feature.hears(
|
||||
"/isLCMGroup",
|
||||
logHandle("is-LCM-group"),
|
||||
async (ctx: Context) => {
|
||||
if (ctx.chat && ctx.msg) {
|
||||
const groupID = ctx.chat.id;
|
||||
|
||||
if (GROUP_IDS !== undefined) {
|
||||
const flag = GROUP_IDS.includes(`${groupID}`);
|
||||
|
||||
if (flag) {
|
||||
await ctx.reply(
|
||||
`This group is in the whitelisted and is a part of the LCM Telegram groups/communities\\. I should be deleting any Twitter/X links and reformatting services within this group\\.`,
|
||||
{
|
||||
parse_mode: "MarkdownV2",
|
||||
reply_parameters: { message_id: ctx.msg.message_id }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (!flag) {
|
||||
await ctx.reply(
|
||||
`This group is NOT in the whitelisted and is NOT a part of the LCM Telegram groups/communities\\. I am a bot designed to delete any Twitter/X links and reformatting services within groups\\. You can fork me from this link: https://github.com/LucidCreationsMedia/No-Twitter-Bot and deploy me for use in your own groups!`,
|
||||
{
|
||||
parse_mode: "MarkdownV2",
|
||||
reply_parameters: { message_id: ctx.msg.message_id }
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!GROUP_IDS) {
|
||||
await ctx.reply(
|
||||
`There was a problem retrieving the whitelist. Check the env variables and try again\\.`,
|
||||
{
|
||||
parse_mode: "MarkdownV2",
|
||||
reply_parameters: { message_id: ctx.msg.message_id }
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
export { composer as isLCMGroup };
|
||||
@@ -1,36 +1,36 @@
|
||||
import type { Context } from '#root/bot/context.js'
|
||||
import { changeLanguageData } from '#root/bot/callback-data/change-language.js'
|
||||
import { logHandle } from '#root/bot/helpers/logging.js'
|
||||
import { i18n } from '#root/bot/i18n.js'
|
||||
import { createChangeLanguageKeyboard } from '#root/bot/keyboards/change-language.js'
|
||||
import { Composer } from 'grammy'
|
||||
import { Composer } from "grammy";
|
||||
import { changeLanguageData } from "#root/bot/callback-data/change-language.js";
|
||||
import type { Context } from "#root/bot/context.js";
|
||||
import { logHandle } from "#root/bot/helpers/logging.js";
|
||||
import { i18n } from "#root/bot/i18n.js";
|
||||
import { createChangeLanguageKeyboard } from "#root/bot/keyboards/change-language.js";
|
||||
|
||||
const composer = new Composer<Context>()
|
||||
const composer = new Composer<Context>();
|
||||
|
||||
const feature = composer.chatType('private')
|
||||
const feature = composer.chatType("private");
|
||||
|
||||
feature.command('language', logHandle('command-language'), async (ctx) => {
|
||||
return ctx.reply(ctx.t('language-select'), {
|
||||
reply_markup: await createChangeLanguageKeyboard(ctx),
|
||||
})
|
||||
})
|
||||
feature.command("language", logHandle("command-language"), async ctx => {
|
||||
return ctx.reply(ctx.t("language-select"), {
|
||||
reply_markup: await createChangeLanguageKeyboard(ctx)
|
||||
});
|
||||
});
|
||||
|
||||
feature.callbackQuery(
|
||||
changeLanguageData.filter(),
|
||||
logHandle('keyboard-language-select'),
|
||||
async (ctx) => {
|
||||
logHandle("keyboard-language-select"),
|
||||
async ctx => {
|
||||
const { code: languageCode } = changeLanguageData.unpack(
|
||||
ctx.callbackQuery.data,
|
||||
)
|
||||
ctx.callbackQuery.data
|
||||
);
|
||||
|
||||
if (i18n.locales.includes(languageCode)) {
|
||||
await ctx.i18n.setLocale(languageCode)
|
||||
await ctx.i18n.setLocale(languageCode);
|
||||
|
||||
return ctx.editMessageText(ctx.t('language-changed'), {
|
||||
reply_markup: await createChangeLanguageKeyboard(ctx),
|
||||
})
|
||||
return ctx.editMessageText(ctx.t("language-changed"), {
|
||||
reply_markup: await createChangeLanguageKeyboard(ctx)
|
||||
});
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
);
|
||||
|
||||
export { composer as languageFeature }
|
||||
export { composer as languageFeature };
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import type { Context } from '#root/bot/context.js'
|
||||
import { logHandle } from '#root/bot/helpers/logging.js'
|
||||
import { Composer } from 'grammy'
|
||||
import { Composer } from "grammy";
|
||||
import type { Context } from "#root/bot/context.js";
|
||||
import { logHandle } from "#root/bot/helpers/logging.js";
|
||||
|
||||
const composer = new Composer<Context>()
|
||||
const composer = new Composer<Context>();
|
||||
|
||||
const feature = composer.chatType('private')
|
||||
const feature = composer.chatType("private");
|
||||
|
||||
feature.on('message', logHandle('unhandled-message'), (ctx) => {
|
||||
return ctx.reply(ctx.t('unhandled'))
|
||||
})
|
||||
feature.on("message", logHandle("unhandled-message"), ctx => {
|
||||
return ctx.reply(ctx.t("unhandled"));
|
||||
});
|
||||
|
||||
feature.on('callback_query', logHandle('unhandled-callback-query'), (ctx) => {
|
||||
return ctx.answerCallbackQuery()
|
||||
})
|
||||
feature.on("callback_query", logHandle("unhandled-callback-query"), ctx => {
|
||||
return ctx.answerCallbackQuery();
|
||||
});
|
||||
|
||||
export { composer as unhandledFeature }
|
||||
export { composer as unhandledFeature };
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
import type { Context } from '#root/bot/context.js'
|
||||
import { logHandle } from '#root/bot/helpers/logging.js'
|
||||
import { Composer } from 'grammy'
|
||||
import { Composer } from "grammy";
|
||||
import type { Context } from "#root/bot/context.js";
|
||||
import { logHandle } from "#root/bot/helpers/logging.js";
|
||||
|
||||
const composer = new Composer<Context>()
|
||||
const composer = new Composer<Context>();
|
||||
|
||||
const feature = composer.chatType('private')
|
||||
const feature = composer.chatType("private");
|
||||
|
||||
feature.command('start', logHandle('command-start'), (ctx) => {
|
||||
return ctx.reply(ctx.t('welcome'))
|
||||
})
|
||||
feature.command("start", logHandle("command-start"), ctx => {
|
||||
return ctx.reply(
|
||||
ctx.t(
|
||||
"Welcome! I am a bot created by Lucid for Lucid Creations media groups. I am designed to delete any Twitter/X links and reformatting services within groups. By default I only work with whitelisted group IDs. You can fork me from this link: https://github.com/LucidCreationsMedia/No-Twitter-Bot and deploy me for use in your own groups!"
|
||||
),
|
||||
{ parse_mode: "MarkdownV2" }
|
||||
);
|
||||
});
|
||||
|
||||
export { composer as welcomeFeature }
|
||||
export { composer as welcomeFeature };
|
||||
|
||||
Reference in New Issue
Block a user