Skip to content
This repository was archived by the owner on Jun 13, 2022. It is now read-only.

Sourcery refactored main branch #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Mar 17, 2022

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 cedliang March 17, 2022 07:55
Comment on lines -155 to +165
outstr = "Target Channel: " + str(self.ann_list[i][5]) + "\n Description: " + str(self.ann_list[i][2])
embed_list.add_field(name=str(self.ann_list[i][0]) + " - " + str(self.ann_list[i][1]), value=outstr)
outstr = (
f"Target Channel: {str(self.ann_list[i][5])}"
+ "\n Description: "
+ str(self.ann_list[i][2])
)

embed_list.add_field(
name=f'{str(self.ann_list[i][0])} - {str(self.ann_list[i][1])}',
value=outstr,
)

Copy link
Author

Choose a reason for hiding this comment

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

Function Announcements.sh_announcement refactored with the following changes:

if amount == 1:
pluralstring = 'message was'
else:
pluralstring = 'messages were'
pluralstring = 'message was' if amount == 1 else 'messages were'
Copy link
Author

Choose a reason for hiding this comment

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

Function Moderation.purge refactored with the following changes:

if oldwords[0] == '':
pass
else:
if oldwords[0] != '':
Copy link
Author

Choose a reason for hiding this comment

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

Function makestring refactored with the following changes:

Comment on lines -48 to +53
echoOptionsString = ''
for option in options:
echoOptionsString += f"{option[0]} {option[1]}\n"
echoOptionsString = ''.join(f"{option[0]} {option[1]}\n" for option in options)
await ctx.send(f"Type your poll answer.\nType the emote corresponding to the option first, then add a space, then type the answer. For example, \'👍 Yes\'.\nIf you are done with your options, type 'done'.\nCurrent options:\n{echoOptionsString}")
try:
option = await self.client.wait_for('message', check = lambda message: message.author == ctx.author, timeout = 120.0)
if option.content == 'done':
if len(options) > 0:
if options:
Copy link
Author

Choose a reason for hiding this comment

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

Function Polling.createpoll refactored with the following changes:

This removes the following comments ( why? ):

#timeout

Comment on lines -154 to +185
if payload.message_id in self.activePollMessageIDs:
channel = await self.client.fetch_channel(payload.channel_id)
message = await channel.fetch_message(payload.message_id)
pollembed = message.embeds[0]

#makes shallow copy of reaction list and ensure entries are sorted in descending order
reactionslist = sorted(message.reactions[:], key = lambda reaction: reaction.count, reverse = True)
totalreactions = 0
#remove the bot's count to get the 'true' polling numbers
for reaction in reactionslist:
reaction.count -= 1
totalreactions += reaction.count
#removes existing embed
pollembed.remove_field(-1)

#add new embed
resultsstring = ''
for reaction in reactionslist:
if totalreactions > 0:
reactPercentage = 100*(reaction.count / totalreactions)
else:
reactPercentage = 0
nearestPercentage = round(reactPercentage)
fullBlocks = nearestPercentage // 10
rem = nearestPercentage - 10*fullBlocks
if rem >= 5:
partialBlocks = 1
else:
partialBlocks = 0
totalBlocks = partialBlocks + fullBlocks
blocksString = '█' * fullBlocks + partialBlocks*'▓' + (10-totalBlocks)*'░'
resultsstring += f'{reaction.emoji} {blocksString} {round(reactPercentage,1)}% ({reaction.count})\n'
pollembed.add_field(name = 'Results', value = resultsstring, inline = True)

await message.edit(embed = pollembed)
if payload.message_id not in self.activePollMessageIDs:
return
channel = await self.client.fetch_channel(payload.channel_id)
message = await channel.fetch_message(payload.message_id)
pollembed = message.embeds[0]

#makes shallow copy of reaction list and ensure entries are sorted in descending order
reactionslist = sorted(message.reactions[:], key = lambda reaction: reaction.count, reverse = True)
totalreactions = 0
#remove the bot's count to get the 'true' polling numbers
for reaction in reactionslist:
reaction.count -= 1
totalreactions += reaction.count
#removes existing embed
pollembed.remove_field(-1)

#add new embed
resultsstring = ''
for reaction in reactionslist:
if totalreactions > 0:
reactPercentage = 100*(reaction.count / totalreactions)
else:
reactPercentage = 0
nearestPercentage = round(reactPercentage)
fullBlocks = nearestPercentage // 10
rem = nearestPercentage - 10*fullBlocks
partialBlocks = 1 if rem >= 5 else 0
totalBlocks = partialBlocks + fullBlocks
blocksString = '█' * fullBlocks + partialBlocks*'▓' + (10-totalBlocks)*'░'
resultsstring += f'{reaction.emoji} {blocksString} {round(reactPercentage,1)}% ({reaction.count})\n'
pollembed.add_field(name = 'Results', value = resultsstring, inline = True)

await message.edit(embed = pollembed)
Copy link
Author

Choose a reason for hiding this comment

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

Function Polling.updatePollResults refactored with the following changes:

Comment on lines -208 to +205
print(str(self.activePollMessageIDs))
print(self.activePollMessageIDs)
Copy link
Author

Choose a reason for hiding this comment

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

Function Polling.checkactivepolls refactored with the following changes:

Comment on lines -37 to +38
splitassoclist = []
for element in assoclist:
splitassoclist.append(element.split(' ', 1))
appenddict = {}
for element in splitassoclist:
appenddict[element[0]] = element[1]
splitassoclist = [element.split(' ', 1) for element in assoclist]
appenddict = {element[0]: element[1] for element in splitassoclist}
Copy link
Author

Choose a reason for hiding this comment

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

Function RoleAssignment.createroleassignment refactored with the following changes:

Comment on lines -80 to +83
if member is not None:
if addRoleBool:
await member.add_roles(role)
print(f"{member.name}#{member.discriminator} was assigned the role {role.name}")
else:
await member.remove_roles(role)
print(f"{member.name}#{member.discriminator} was unassigned the role {role.name}")
else:
if member is None:
print("Member not found")
elif addRoleBool:
await member.add_roles(role)
print(f"{member.name}#{member.discriminator} was assigned the role {role.name}")
else:
await member.remove_roles(role)
print(f"{member.name}#{member.discriminator} was unassigned the role {role.name}")
Copy link
Author

Choose a reason for hiding this comment

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

Function RoleAssignment.updateRoles refactored with the following changes:

Comment on lines -101 to +96
await ctx.send(f"Role associations have been cleared. {str(self.roleassocdict)}")
await ctx.send(f"Role associations have been cleared. {self.roleassocdict}")
Copy link
Author

Choose a reason for hiding this comment

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

Function RoleAssignment.clearroleassignments refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Mar 17, 2022

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 2.25%.

Quality metrics Before After Change
Complexity 14.40 🙂 12.20 🙂 -2.20 👍
Method Length 61.06 ⭐ 60.62 ⭐ -0.44 👍
Working memory 11.52 😞 11.14 😞 -0.38 👍
Quality 52.12% 🙂 54.37% 🙂 2.25% 👍
Other metrics Before After Change
Lines 596 592 -4
Changed files Quality Before Quality After Quality Change
cogs/announcements.py 67.34% 🙂 67.32% 🙂 -0.02% 👎
cogs/moderation.py 91.05% ⭐ 92.85% ⭐ 1.80% 👍
cogs/neil.py 53.68% 🙂 54.70% 🙂 1.02% 👍
cogs/polling.py 30.42% 😞 34.02% 😞 3.60% 👍
cogs/roleassignment.py 58.29% 🙂 62.45% 🙂 4.16% 👍

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

File Function Complexity Length Working Memory Quality Recommendation
cogs/polling.py Polling.createpoll 33 ⛔ 601 ⛔ 18 ⛔ 13.81% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
cogs/neil.py makestring 22 😞 226 ⛔ 12 😞 33.72% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
cogs/announcements.py Announcements.submit_announcement 12 🙂 239 ⛔ 15 😞 36.48% 😞 Try splitting into smaller methods. Extract out complex expressions
cogs/roleassignment.py RoleAssignment.createroleassignment 16 🙂 184 😞 15 😞 36.94% 😞 Try splitting into smaller methods. Extract out complex expressions
cogs/polling.py Polling.updatePollResults 8 ⭐ 174 😞 14 😞 46.10% 😞 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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants