Coder Social home page Coder Social logo

leishi1313 / telefire Goto Github PK

View Code? Open in Web Editor NEW
20.0 2.0 5.0 5.58 MB

A set of useful command line tools to interact with telegram using telethon and python-fire.

License: MIT License

Dockerfile 0.53% Python 99.47%
telegrem telegram-bot telegram-api telethon python-fire

telefire's Introduction

Telethon X Fire - TeleFire

A set of userful command line tools to interact with telegram.

What has inside | How | Docker

What is inside

  • ๐ŸŽget_all_chats: Fetches all the chat IDs and names.
  • ๐Ÿ“‘list_messages: List messages in a certain chat.
  • ๐Ÿ”search_messages: Search messages in a certain chat.
  • ๐Ÿ’€delete_all: Delete all the messages that you have permission to delete in a certain chat.
  • โ“plus_mode: Delete certain messages after certain time.
  • ๐Ÿ’ฌwords_to_ifttt: Send an event to IFTTT when somebody said some words you interested.
  • ๐Ÿ˜special_attention_mode: Get notified when someone in special attention mode said something.

Usage

Setup

  1. Login to your Telegram account with the phone number of the account you wish to use.
  2. Click API Development tools.
  3. A Create new application window will appear if you didn't create one. Go head and create one.
  4. Once you finish creation, get the api_id and api_hash, you will use it later.

get_all_chats

TELEGRAM_API_ID=[YOUR_API_ID] TELEGRAM_API_HASH=[YOUR_API_HASH] python telefire.py get_all_chats

-100XXXXXXXXXX: CHANNEL_NAME0
    XXXXXXXXXX: CHANNEL_NAME1

Those negative IDs start with -100 are private groups, that's the only way you can access to these groups. For public groups, you can either use id, public url, username to access to it.

list_messages

TELEGRAM_API_ID=[YOUR_API_ID] TELEGRAM_API_HASH=[YOUR_API_HASH] python telefire.py list_messages --chat [CHAT_IDENTIFIER] [Optional: --user USER_IDENTIFIER]

For CHAT_IDENTIFIER, it can be a chat ID you got from get_all_chats, or it can be something like t.me/LGTMer or LGTMer.

For USER_IDENTIFIER, it can be the user's ID or username.

search_messages

TELEGRAM_API_ID=[YOUR_API_ID] TELEGRAM_API_HASH=[YOUR_API_HASH] python telefire.py search_messages --peer [PEER_IDENTIFIER] --query [QUERY_STRING]

This command comes with some optional parameters that you can custom:

  • --slow: Whether to use telegram's search API or iterate through whole message history to do the search. The later can be comprehensive if you are searching UTF-8 characters such as Chinese.
  • --limit [INTEGER]: Set the limit of search result, default 100.
  • --from_id [USER_IDENTIFIER]: The id/username of the message sender.

delete_all

TELEGRAM_API_ID=[YOUR_API_ID] TELEGRAM_API_HASH=[YOUR_API_HASH] python telefire.py delete_all --chat [CHAT_IDENTIFIER] [Optional: --query QUERY_STRING]

For CHAT_IDENTIFIER, smiliar to CHAT_IDENTIFIER in get_all_chats, or it can be something like t.me/LGTMer or LGTMer.

You can also using the --query to specify only messages containing certain string will be deleted.

plus_mode

TELEGRAM_API_ID=[YOUR_API_ID] TELEGRAM_API_HASH=[YOUR_API_HASH] python telefire.py plus_mode

It's a command you have to keep it running in the backgroud to use it. It's my personal favorite command! It includes several functions that's interesting and useful:

  • Auto delete mode: Add \[NUMBER][s|m|h|d] before the message you want to auto delete after certain time, for example, add \10s (notice the space), then this message will be deleted automately after 10 seconds. you can also specify minutes(m), hours(h) and days(d) as the message experation time.
  • Shiny mode: just try it, add \shiny to your original message!.
  • Search mode: \search [CHAT] [USERNAME] [Optional: QUERY]

words_to_ifttt

TELEGRAM_API_ID=[YOUR_API_ID] TELEGRAM_API_HASH=[YOUR_API_HASH] python telefire.py words_to_ifttt --event [IFTTT EVENT] --key [IFTTT WEBHOOK KEY] [WORDS YOU INTERESTED]

Like auto_delete, you need to keep this command running to make it work. For the event and key, you can get it from here. For WORDS YOU INTERESTED, it can be something like telefire "telefire is so cool", then whenever anybody said telefire or telefire is so cool, an IFTTT event will be sent and you can create an applet to do whatever you like on IFTTT, such as sending notifications, turn on a light, etc.

Other commands

For all the others commands I didn't methtion or simply too lazy to add docs for it:

python telefire.py --help

to get a list of all the available commands. And:

python telefire.py COMMAND - --help

to learn how to use it.

Docker

This project also come with a Dockerfile so that you don't need to setup any python environment, just run the following command:

docker build . -t telefire
docker run -ti --rm -v $(pwd)/telefire.py:/tg/telefire.py telefire python telefire.py [COMMAND] [OPTIONS]

And that's it, enjoy!

TODO

  • โœ”๏ธ For deleting messages, add an option to delete messages based on time instead of always delete all.
  • โœ”๏ธ A long-running service that will notify user if someone said something contains some interested words.

telefire's People

Contributors

dependabot[bot] avatar kidonng avatar leishi1313 avatar

Stargazers

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

Watchers

 avatar  avatar

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.