Conversation
| class Config(object): | ||
|
|
||
|
|
||
| class Config((object)): |
There was a problem hiding this comment.
Lines 2-14 refactored with the following changes:
- Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension)
|
|
||
| while True: | ||
| broadcast_id = ''.join([random.choice(string.ascii_letters) for i in range(3)]) | ||
| if not broadcast_ids.get(broadcast_id): | ||
| break | ||
|
|
||
| out = await m.reply_text( | ||
| text = f"Broadcast initiated! You will be notified with log file when all the users are notified." | ||
| text='Broadcast initiated! You will be notified with log file when all the users are notified.' | ||
| ) | ||
|
|
||
| start_time = time.time() | ||
| total_users = await db.total_users_count() | ||
| done = 0 | ||
| failed = 0 | ||
| success = 0 | ||
|
|
||
| broadcast_ids[broadcast_id] = dict( | ||
| total = total_users, | ||
| current = done, | ||
| failed = failed, | ||
| success = success | ||
| ) | ||
|
|
||
| async with aiofiles.open('broadcast.txt', 'w') as broadcast_log_file: | ||
| async for user in all_users: | ||
|
|
||
| sts, msg = await send_msg( | ||
| user_id = int(user['id']), | ||
| message = broadcast_msg | ||
| ) | ||
| if msg is not None: | ||
| await broadcast_log_file.write(msg) | ||
|
|
||
| if sts == 200: | ||
| success += 1 | ||
| else: | ||
| failed += 1 | ||
|
|
||
| if sts == 400: | ||
| await db.delete_user(user['id']) | ||
|
|
There was a problem hiding this comment.
Function broadcast_ refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring)
| async def is_user_exist(self, id): | ||
| user = await self.dcol.find_one({'id':int(id)}) | ||
| return True if user else False | ||
| return bool(user) |
There was a problem hiding this comment.
Function Database.is_user_exist refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity)
| async def get_all_users(self): | ||
| all_users = self.dcol.find({}) | ||
| return all_users | ||
| return self.dcol.find({}) |
There was a problem hiding this comment.
Function Database.get_all_users refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
Sourcery Code Quality Report❌ Merging this PR will decrease code quality in the affected files by 0.36%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request. Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! Help us improve this quality report! |
Branch
mainrefactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
mainbranch, then run:Help us improve this pull request!