Skip to content

Sourcery refactored main branch#4

Open
sourcery-ai[bot] wants to merge 1 commit intomainfrom
sourcery/main
Open

Sourcery refactored main branch#4
sourcery-ai[bot] wants to merge 1 commit intomainfrom
sourcery/main

Conversation

@sourcery-ai
Copy link

@sourcery-ai sourcery-ai bot commented Dec 11, 2021

Branch main refactored 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 main branch, then run:

git fetch origin sourcery/main
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from PR0FESS0R-99 December 11, 2021 04:42
Comment on lines -2 to +4
class Config(object):


class Config((object)):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 2-14 refactored with the following changes:

Comment on lines -85 to +125

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'])

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function broadcast_ refactored with the following changes:

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)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Database.is_user_exist refactored with the following changes:

async def get_all_users(self):
all_users = self.dcol.find({})
return all_users
return self.dcol.find({})
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Database.get_all_users refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Dec 11, 2021

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 0.36%.

Quality metrics Before After Change
Complexity 9.04 🙂 9.11 🙂 0.07 👎
Method Length 46.56 ⭐ 46.12 ⭐ -0.44 👍
Working memory 10.10 😞 10.16 😞 0.06 👎
Quality 60.15% 🙂 59.79% 🙂 -0.36% 👎
Other metrics Before After Change
Lines 190 192 2
Changed files Quality Before Quality After Quality Change
config.py 83.21% ⭐ 83.52% ⭐ 0.31% 👍
Google_Translator_Bot/Commands.py 45.98% 😞 46.00% 😞 0.02% 👍
Google_Translator_Bot/Database.py 96.01% ⭐ 96.06% ⭐ 0.05% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
Google_Translator_Bot/Commands.py broadcast_ 18 🙂 302 ⛔ 16 ⛔ 27.72% 😞 Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants