Skip to content

Instantly share code, notes, and snippets.

@matteodellamico
Created June 21, 2016 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matteodellamico/0c389ec14227bed6b5780434428b1d88 to your computer and use it in GitHub Desktop.
Save matteodellamico/0c389ec14227bed6b5780434428b1d88 to your computer and use it in GitHub Desktop.
#!/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