Code Monkey home page Code Monkey logo

shieldy's Introduction

@shieldy_bot

@shieldy_bot Telegram bot code

This is the code for the anti-spam Telegram bot I've built. Enjoy and feel free to reuse!

Installation

Local launch

  1. Clone this repo: git clone https://github.com/backmeupplz/shieldy
  2. Launch the mongo database locally
  3. Create .env with the environment variables listed below
  4. Run yarn install in the root folder
  5. Run yarn distribute

And you should be good to go! Feel free to fork and submit pull requests. Thanks!

Docker

  1. Clone this repo: git clone https://github.com/backmeupplz/shieldy
  2. Replace the dummy environment variables in docker-compose.yml with the ones listed below
  3. Run docker-compose up -d

Environment variables

  • TOKEN — Telegram bot token
  • MONGO— URL of the mongo database
  • ADMIN — Telegram user ID of the bot administrator
  • REPORT_CHAT_ID — Telegram chat ID of the channel where the bot should report errors
  • PREMIUM — Whether the bot should be premium or not
  • STRIPE_SECRET_KEY — Stripe secret key
  • STRIPE_SIGNING_SECRET — Stripe signing secret
  • MONTHLY_PRICE — Monthly Stripe price id of the premium
  • YEARLY_PRICE — Yearly Stripe price id of the premium
  • LIFETIME_PRICE — Lifetime Stripe price id of the premium

Also, please, consider looking at .env.sample.

Continuous integration

Any commit pushed to master gets deployed to @shieldy_bot via CI Ninja.

License

MIT — use for any purpose. Would be great if you could leave a note about the original developers. Thanks!

shieldy's People

Contributors

0312birdzhang avatar 7rst1 avatar ali-demirtas avatar anon97945 avatar backmeupplz avatar claudio4 avatar dependabot[bot] avatar fiveboroughs avatar freesofia avatar k06a avatar kaul1k avatar krboktv avatar kworr avatar laubonghaudoi avatar masaruhoshi avatar maxuo avatar paklebah avatar peterdavehello avatar redpenguin-validator avatar salvatorecordiano avatar sams27 avatar suburbanno avatar tomerghelber avatar tomthedragon avatar tpnonthealps avatar trafim-uakraine avatar upacyxou avatar valerio-vaccaro avatar vshashkov avatar wroadd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

shieldy's Issues

Bot isnt working

Current config:

id: 852404243
language: en
captchaType: button
timeGiven: 120
adminLocked: false
restrict: false
noChannelLinks: false
deleteEntryMessages: false
greetsUsers: true
customCaptchaMessage: false
strict: true
deleteGreetingTime: 0
banUsers: false
deleteEntryOnKick: false
cas: true
underAttack: false
noAttack: true
buttonText: Not set
allowInvitingBots: false
greetingButtons:
Not set

Inline bots messages sent during captcha timewindow are not deleted

When a user joins, Shieldy will send a captcha, if the user fails the captcha, Shieldy will delete all messages the user sent and kick him.

Except when the user sends an inline bot message, like this one :
image
The captcha logic still works and the user is kicked, but the inline message is not deleted

Users doesnt blocking

Hello, when spamer adds to group and making fast message it shows to all users and captcha doesnt work.

Yes, after timeout user where kicked or banned, but before this action spamer can make a spam.

It will be great to delete all messages of spam user with kicking after failed captcha.

captchaType: button is not working (visible as Digits) no config is saved?

Hi,
Current config:

id: XXXXXXXXX
language: en
captchaType: button
timeGiven: 30
adminLocked: true
restrict: true
noChannelLinks: false
deleteEntryMessages: true
greetsUsers: true
customCaptchaMessage: true
strict: true
deleteGreetingTime: 3
banUsers: true
deleteEntryOnKick: true
cas: true
underAttack: false
noAttack: false
buttonText: I'm not a robot ✅
allowInvitingBots: false
greetingButtons:
Not set

Bot is of course admin in group. After new user joins group - he is forced to do Digits CAPTCHA instead of a simple button press.

Example:

(10 + 5) $username, please, send the solution to the arithmetic operation provided within the time amount specified to this group, otherwise you will be kicked. Thank you! (60 sec)

As you can see - timeGiven should be 30 seconds instead of 60, according to my bot configuration.

Or am I doing something wrong?

Also - HUGE thank you for this bot - awesome job! Keep it up, proud of You!

feature request: block usernames which are spam

If I make my spam bot with the typical click bait text + URL then it will display in each group that has joined the group. Which achieves the spamming, without needing to actually post anything.
Shield would have to ban & delete these bots before the captcha phase though.

More options for time waiting to verification

You could add buttons (like "-" and "+" and/or "sec", "min", "hour") so we can customize it in a better way. The present option is kicking users too fast before they participate. My group is a small one, so people subscribe, see that it's no active convo and go somewhere else and don't see that it's been asked them to take some action.

French language

Hello can you add french language plz?
Translation:
Digits:(Number+Number)(Name), merci d'envoyer la solution de l'équation dans le temps imparti sur ce groupe où vous serez banni.merci! (Time)
Simple: (name)merci d'envoyer un message dans le temps imparti où vous serez banni(time)
Button: (name)merci de cliquer sur le bouton dans le temps imparti où vous serez banni (time)
Thank you ;)

More human-readable wording in greeting

For example, in Russian:

@username, пожалуйста, отправьте любое сообщение в этот чат в течение указанного времени, иначе вы будете кикнуты. Спасибо! (240 сек)

@username, пожалуйста, отправьте любое сообщение в этот чат в течение 240 сек, иначе вы будете кикнуты. Спасибо!

Shieldy stopped working

The bot stopped working.
I wrote directly and it doesnt answer.
Something went wrong.
Can you check your deploy?

Feature request: Add simple internal group statistics.

My group needs to evaluate members activity periodically. So, we need some kind of members activity statistics. But we don't want to use those fancy and over-complicated stats-bot like the ones popular out there. We simply need these informations:

  1. Number of total messages sent into the group within a time period.
  2. Number of total members involved in the conversation within a time period.
  3. A few of most active members in the group within a time period.
  4. A few of most inactive members in the group within a time period.

Say, the command is /stats which would produce output like this:

Group Statistics

Within the last 30 days, there are 871 messages sent into this group by 26 members involved in the conversation of 40 registered members.

The most 10 active members are:

  1. username_1 (x messages)
  2. username_2 (x messages)
  3. username_3 (x messages)
  4. username_4 (x messages)
  5. username_5 (x messages)
  6. username_6 (x messages)
  7. username_7 (x messages)
  8. username_8 (x messages)
  9. username_9 (x messages)
  10. username_10 (x messages)

The most 10 inactive members are:

  1. @userid_1 (x messages)
  2. @userid_2 (x messages)
  3. @userid_3 (x messages)
  4. @userid_4 (x messages)
  5. @userid_5 (x messages)
  6. @userid_6 (x messages)
  7. @userid_7 (x messages)
  8. @userid_8 (x messages)
  9. @userid_9 (x messages)
  10. @userid_10 (x messages)

Any members who send less than 5 messages within last 30 days will be kicked out from this group. This group forbids silent readers. You have been warned!

Configuration:
/stat_period = 30 (days)
/stat_active = 10 (members)
/stat_inactive = 10 (members)
/stat_statement = "Any members who send less than 5 messages within last $period days will be kicked out from this group. This group forbids silent readers. You have been warned!"

Please note that the inactive members list does mention the members so they get the notification. If you like, you could set this as config as well, such as /notify_inactive.

I hope this request will be implemented. Thank you.

[Feature request] Add a /NoChannelLinks command

Most of the spam I receive is from Bots linking to other groups:
image

If there was a command I could activate to delete automatically any message that contains t.me/* it would reduce the amount of spam by 90%

Bot is not deleting messages in captcha mode

Basically, Strict mode is on, Captcha is used as authentication.

  • User A joins.
  • A sends some link to a scam site
  • Bot Does not delete message until the user is kicked

Expected Behaviour:

  • Bot deletes any messags that does not have to do with the captcha until they solved the captcha.

Custom capture questions?

Would it be possible to add an option to define custom capture questions and specific questions? That way you could only let people in the group chat that know a fact only known to that specific group of people.
Thank you.

Request: Option to have kick messages deleted, as well as entry.

I appreciate the inclusion of the command to delete the entry message of beings that have been booted due to failing the captcha. I would like to be able to also auto-delete the removal messages (separate from the delete entry message option), as my channel is getting so inundated that the messages are disrupting the log. It's better with the entry messages removed, but I would like to be able to make it a non-event if you didn't notice while it was happening. Some people might like to leave them, which is why I think it should be a separate option.

Thank you very much for making Shieldy!

Bot isn't deleting entry/kick messages

I didn't comment this on #52 to avoid polluting the issue with something possibly unrelated.

Even with /deleteEntryOnKick we are still seeing both messages (joined and removed) in our channels:

We've already tried to set the bot's permissions with as much permission as possible, but without success:

Is there anything else that we need to set or try, please?

[Bug] Custom captcha message doesn't evoke a mention if the new user doesn't have a username

Using $fullname variable in a custom message won't evoke a mention. Is there a entity that doesn't care if the new user hasn't a username and mention him/her always? Some people that didn't solve the captcha said they didn't notice my group has this condition, probably cause they weren't mentioned. By the way, can you make available more variables to help further customization this message, like something related to the time that user joined the group?

Unban user after time runs out

Hello,

I just discovered that if the bot kicks out a user, the user will be unban (or unlimited) and can rejoin the group without limitations.
To simulate, it's very simple:

  • Set up the bot to kick if user doesn't solve the CAPTCHA.

  • Lets someone joins the group and manually (or with another bot) ban him from the group

  • after the time runs out wait few seconds and the user should be able to join the group again

I recreated this bug multiple times and it can cause conflict with other bot (like antistormbot) that ban immediately Arab users or userbot.

Thanks.

Adding Japanese language

Hi @backmeupplz backmeupplz !

I'm using shieldy for my community where Japanese people are majority.
Is there anyway, you can add Japanese translation in shieldy?

I am happy to do any translation but I am non-dev and have no idea where and how to make use of your open sourecode.

Thanks!

Add link support in greeting messages

Setting a greeting message with /greeting, like this one
image

Will result in this version being sent out
image

Missing the links and the markdown code formatting

[FR] Allow custom time with /restrict

That way we could also set the period we think it's best for the new user only use text in his/her message. For example, it would be nice if we could extent to a week, enough time to analyze if he/she went to spam the group or seek real help and so on.

Feature request: auto-delete greeting messages

Hi!

Because people tend to join chats just for reading, the greeting messages usually flood the chat. It would be awesome if Shieldy could remove all its greetings after a set period of time (e.g. 3 min, which is enough time for an average person to understand he/she is welcome).
Shieldy is nice, but its messages are not usually in line with actual chat topic and other discussions in the chat. It would be nicer if it could do its job under the hood as much as possible. The best technology is invisible.

Spam from bot?

Hi there,

I recently got this from the bot:

Hi there! It's Nikita, the creator of Shieldy. Over 65 000 chats added Shieldy! It is free and I sell no ads so I decided to tell you about my new project  Todorant.

Todorant is a smart todo list that uses cognitive psychology to make your brain feel pleasure by achieving goals. I created Todorant for myself — and I use it every day — but my friends asked me to give them access to Todorant. And today anyone can use Todorant:

As a website
On iOS
On Android

I outlined the main productivity rules in my post "How I launched 7 products in 1 year" and in the video-summary "How to use Todorant" (just 2 minutes long). Briefly, Todorant makes you add an exact date or month to every task, you only see one task at a time to focus on the main screen, unpleasant tasks are called frogs and should be done first thing in the morning.

I hacked my productivity with the simple rules and made the app so that you could do it as well! Todorant is completely free for the first 30 days, and you can even use mobile apps without login! No strings attached — just try Todorant as a website, on iOS or Android today. This is how you can support free Voicy that transcribes over 90 000 voice messages a day! Thank you!

— @borodutch

Why the heck would we start getting spam from the bot?

Bug: Bot not accepting custom greetings

Pretty much what it says on the tin. I used the /customCaptchaMessage command, and got the prompt to respond with my new message, but then nothing happens once I reply, and the bot continues to use the default message. If I use the command again, it says it is going back to the default. I have tried messages with and without using the variables, and of three different lengths (kept making it shorter in case that was the problem).

Minor issue with command explanation

Hi, I just installed Shieldy Bot, and I am happy with it overall- there is one command that I don't think is documented well, and might be able to use some modification, depending on how it actually works.
Does /deleteEntryMessages delete all entry messages, or only ones from the users who fail the captcha?

Add command to get the whole config as 1 string to setup Sheildy in one go, and not disturb groups

To avoid entering 10 or more commands and causing 20+ annoying notifications in a group, the user could set up Sheildy with 1 command. Using a proposed new config string, generated from an existing group or direct chat with Sheildy.

  1. Start a chat directly with Shieldy
  2. Enter all the commands as required
  3. Enter the new command like /viewConfigString
  4. Sheildy outputs a string of your config
  5. Go to your group and enter the string as a command
  6. Or if that is not directly possible, enter a new command like: /inputConfigString and wait for the response. Then enter the string when prompted.
  7. After entering the the config string by method step 5 or 7, Shieldly confirms the new config is accepted.

Also, the same command could be used to take the config from one group, and use it in another. This also saves remembering each setting that was previously used. Or for sharing with others who like your settings but are not familiar with the settings.

Kick new user after sending stickers

With /restrict option, it is said that user can send only plain text. But it's OK to send stickers, and shieldy even do not ban them, and do not delete entry message (we also set this parameter and usually it works great).

Info for viewing all current configured options

It would be nice if we can send something like /info_config and see all the options set at that moment. Cause when we try to see what is set, regularly we accidentally turn on/off/change the settings we don't want to change.

Spammers leaving messages are not deleted.

Suppose we have a spammer that joins channel and immediately leaves. If /deleteEntryOnKick is set bot shows the captcha and upon timeout removes captcha and entry message, but leaving message is still on the channel.

Example of bot usernames:
зображення

Proposal:
a) first read all pending messages in the group;
b) if /deleteEntryOnKick is set and user already left then remove both entry and part messages;
d) show captcha;
e) if user leaves without solving the captcha remove captcha immediately (and entry/part messages according to /deleteEntryOnKick).

Thanks in advance.

[Bug] customCaptchaMessage doesn't work with Digits Captcha

I had made a few tests and noticed that when I select "Digits" Captcha and then set a customCaptchaMessage, even when it's on and showing me it will use my custom message, it doesn't. It uses the default message. I have a guess on that: all the other captcha types are compound, with two messages. "Digits" is not, placing the arithmetic operation in the same message as the captcha message. Maybe forcing the operation on another message would fix that. To feel less uncomfortable for so few characters in a message, I suggest forcing them to be as big/tall as they can. By the way, this is the only option blind-friendly that also defeat bots and userbots that only click a "I'm not a bot" button, killing two birds with one stone hahaha

Feature request: Remove deleted account and last seen long time ago.

In most large groups, it's common to see lots of inactive or deleted accounts and inactive users who haven't been logged in to Telegram for a long time. These people are junks to the group and create false data of real members of the group. So, could you provide a command to remove deleted account and members who last seen is long time ago? I propose /remove_deleted_account and /remove_inactive_account accordingly.

What do you think? Is it possible to be done by a bot? Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.