Skip to content

Commit

Permalink
Fix gurland#13: validate group index and change group type selection
Browse files Browse the repository at this point in the history
  • Loading branch information
gurland committed Jul 4, 2020
1 parent a0009b1 commit 292360a
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions cleaner.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,33 @@ def get_all_dialogs():
return dialogs

def select_supergroup(self):
dialogs = self.get_all_dialogs()
group_types = {
'1': 'supergroup',
'2': 'group'
}

print('1. Supergroup\n2. (non super)Group')
group_type_n = int(input('Insert group type: '))
print('')
dialogs = self.get_all_dialogs()

if group_type_n == 1:
self.group_type = 'supergroup'
elif group_type_n == 2:
self.group_type = 'group'
else:
print('\n'.join((f'{i}. {name.capitalize()}' for i, name in group_types.items())))
try:
self.group_type = group_types[input('Insert group type number: ')]
except KeyError:
print('Invalid group type. Exiting..')
exit()
exit(-1)
print('')

groups = [x for x in dialogs if x.chat.type == self.group_type ]
groups = [x for x in dialogs if x.chat.type == self.group_type]

for i, group in enumerate(groups):
print(f'{i+1}. {group.chat.title}')

print('')

group_n = int(input('Insert group number: '))
if group_n not in range(1, len(groups)+1):
print('Invalid group number. Exiting...')
exit(-1)

selected_group = groups[group_n - 1]

selected_group_peer = app.resolve_peer(selected_group.chat.id)
Expand Down

0 comments on commit 292360a

Please sign in to comment.