Last active
September 21, 2018 08:50
-
-
Save dshvedchenko/406ace06f270b94bc9b23b59f01c7bb9 to your computer and use it in GitHub Desktop.
telegraf spam bot remover
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Telegraf = require('telegraf') | |
const bot = new Telegraf(process.env.BOT_TOKEN) | |
const spam_suspect = new Map(); | |
bot.on('message', async (ctx) => { | |
let chat_id = ctx.update.message.chat.id; | |
let msg = ctx.update.message.text; | |
let msg_id = ctx.update.message.message_id | |
console.log(ctx.update.message.from) | |
console.log(await ctx.getChatAdministrators()) | |
if (msg.match(/t\.me\/joinchat/i)) { | |
ctx.telegram.deleteMessage(chat_id, msg_id) | |
console.log(`DELETED: ${chat_id} - ${msg_id}`) | |
// ban message author | |
} | |
if (msg.match(/porno/i)) { | |
ctx.telegram.deleteMessage(chat_id, msg_id) | |
console.log(`DELETED: ${chat_id} - ${msg_id}`) | |
// ban message author | |
} | |
if (ctx.update.message.reply_to_message !== undefined) { | |
let comment_is_spam = ctx.update.message.text.match(/spam/i) | |
if (comment_is_spam) { | |
let msg_id = ctx.update.message.reply_to_message.message_id | |
let vote_counter = spam_suspect.get(msg_id) || 0; | |
if (vote_counter < 1) { | |
vote_counter++; | |
spam_suspect.set(msg_id, vote_counter) | |
} else { | |
spam_suspect.delete(msg_id) | |
ctx.telegram.deleteMessage(chat_id, msg_id); | |
console.log(`DELETED: ${chat_id} - ${msg_id}`) | |
// ban message author | |
} | |
} | |
} | |
}) | |
bot.startPolling() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment