Skip to content
This repository was archived by the owner on Mar 9, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TeleInviter
Invite members, from (many) `source_groups` to (one) `destination_group`
And avoid repetition from `destination_group`
and avoid repetition from `destination_group`

# ENV
- python3
Expand All @@ -10,11 +10,12 @@ And avoid repetition from `destination_group`
- `pip3 install peewee`
- `pip3 install colorama`
- `pip3 install pprint`
- maybe some packages i forgot..
- maybe some packages I forgot...

# RUN
- make a configuration file named `conf.py`
- run `py main.py`
- init database `python3 db_init.py`
- two confirmation during the processing

# Developing
Expand Down
19 changes: 19 additions & 0 deletions db.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,22 @@ def save_invite(u):
invite.save()

return invite


class KeyPosition(BaseModel):
pause_position = CharField(unique=True)


def get_create_or_update_pause_position(position=None):
# create
if position is None:
position = 0

key_position, created = KeyPosition.get_or_create(pause_position=position)

# update
if position is not None and (position >= key_position.pause_position):
key_position.pause_position = position
key_position.save()

return key_position.pause_position
2 changes: 1 addition & 1 deletion db_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@


db.connect()
db.create_tables([Invite])
db.create_tables([Invite, KeyPosition])

print('Database: initialization complete!')
12 changes: 7 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,10 @@ def invite_user(u):
except errors.rpcerrorlist.PeerFloodError as e:
sys.stdout.write(colorama.Fore.LIGHTRED_EX + '\n error#9. PeerFloodError > ')
sys.stdout.write(colorama.Fore.LIGHTMAGENTA_EX + '%s ' % e.message)
print('... Retry after 2 Mins ...')
time.sleep(120)
invite_user(u)
# Prepare to exit: record the position of job failed
db.get_create_or_update_pause_position(i)
# When PeerFloodError occurs, it should better not to use this client any more
sys.exit(0)
else:
print(colorama.Fore.GREEN + 'skipped')

Expand Down Expand Up @@ -317,8 +318,9 @@ def is_user_status_offline_passed(t):

# Start inviting
print(colorama.Fore.LIGHTCYAN_EX + '\n\nStarting inviting:')
i = 0
for u in participants[client_sessions[0]]:
# leave back or use the position you want to start from
i = db.get_create_or_update_pause_position()
for u in participants[client_sessions[0]][i:]:
if u.bot is False:
# skip bots
if len(get_user_display_name(u)) > conf.filter_user_display_name_too_much_words_limit:
Expand Down
6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Telethon==1.1.1
Telethon-sync==1.0.4
PySocks==1.6.8
peewee==3.6.4
colorama==0.3.9
pprint==0.1