Skip to content

Commit

Permalink
1st commit
Browse files Browse the repository at this point in the history
  • Loading branch information
doorbash committed Oct 10, 2022
0 parents commit e426ced
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 0 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: CI to Docker Hub

on:
release:
types: [published]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: ./
file: ./Dockerfile
platforms: linux/amd64
builder: ${{ steps.buildx.outputs.name }}
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/telegram-no-sticker-gif:${{ github.event.release.name }}
ghcr.io/${{ github.repository_owner }}/telegram-no-sticker-gif:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.session
docker/db/db
run.sh
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM python:3.10.7-alpine3.16
ADD script.py .
RUN pip install telethon==1.25.2 pysocks
CMD ["python", "./script.py"]
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## Run:

### With socks5 proxy:
```
docker run -it --name no-sticker-gif --restart always -v $(pwd)/docker/db:/db -e API_ID=XXXXX -e API_HASH=XXXXXXXXXXXXXXXXXXXXXXXXXXXX -e PROXY=true -e PROXY_IP=XXX.XXX.XXX.XXX -e PROXY_PORT=XXXXX ghcr.io/doorbash/telegram-no-sticker-gif:latest
```

### Without proxy:
```
docker run -it --name no-sticker-gif --restart always -v $(pwd)/docker/db:/db -e API_ID=XXXXX -e API_HASH=XXXXXXXXXXXXXXXXXXXXXXXXXXXX ghcr.io/doorbash/telegram-no-sticker-gif:latest
```

## Usage:
Send any sticker/gif you have problem with to yourself to add it to database. Send again to remove.
Empty file added docker/db/.keep
Empty file.
46 changes: 46 additions & 0 deletions script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from telethon import TelegramClient, events, sync
from telethon.types import PeerUser
import logging, os, socks, dbm

logging.basicConfig(format='[%(levelname) 5s/%(asctime)s] %(name)s: %(message)s',level=logging.WARNING)

db = dbm.open('db/db', 'c')

if os.environ.get('PROXY'):
host = os.environ['PROXY_IP']
port = int(os.environ['PROXY_PORT'])
proxy = (socks.SOCKS5, host, port)
else:
proxy = None

client = TelegramClient('default', os.environ['API_ID'], os.environ['API_HASH'], proxy=proxy)
client.start()

media_set = set()

@client.on(events.NewMessage)
async def my_event_handler(event):
if type(event.message.peer_id) != PeerUser:
return
is_media = event.message.media != None and event.message.document != None
is_sticker = is_media and (event.message.document.mime_type in ("image/webp", "application/x-tgsticker", 'video/webm'))
is_gif = is_media and event.message.document.mime_type in ("video/mp4") and event.message.document.size < 1024 * 1024
is_from_myself = event.message.peer_id.user_id == me.id
if is_sticker or is_gif:
document_id = str(event.message.media.document.id)
if is_from_myself:
if db.get(document_id):
del db[document_id]
await event.reply('removed from `no sticker/gif` list! send again to add it')
else:
db[document_id] = "."
await event.reply('added to `no sticker/gif` list! send again to remove it')
else:
if db.get(document_id):
await event.delete()

me = client.get_me()
print(me.stringify())

with client:
client.run_until_disconnected()

0 comments on commit e426ced

Please sign in to comment.