Created
June 21, 2016 17:26
-
-
Save matteodellamico/0c389ec14227bed6b5780434428b1d88 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
from json import loads | |
from subprocess import Popen, PIPE | |
KILL_LIST = {IDS_OF_ANNOYING_PEOPLE} # find them by running telegram-cli --json interactively, or run this and watch their ids together with their screen name | |
tg = Popen(['telegram-cli', '-C', '--json'], stdin=PIPE, stdout=PIPE) | |
for line in tg.stdout: | |
line = str(line, 'utf-8') | |
try: | |
line = line[line.index('{'):] | |
except ValueError: | |
continue | |
event = loads(line) | |
if event.get('event', None) != 'message': | |
continue | |
print(event['from']['id'], event['from'].get('print_name', None)) | |
if event['from']['id'] in KILL_LIST: | |
print(event) | |
tg.stdin.write(b'delete_msg {}\n'.format(event['id'])) | |
tg.stdin.flush() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment