-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored main branch #4
base: main
Are you sure you want to change the base?
Conversation
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, | ||
) | ||
|
There was a problem hiding this comment.
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:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
if amount == 1: | ||
pluralstring = 'message was' | ||
else: | ||
pluralstring = 'messages were' | ||
pluralstring = 'message was' if amount == 1 else 'messages were' |
There was a problem hiding this comment.
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:
- Replace if statement with if expression (
assign-if-exp
)
if oldwords[0] == '': | ||
pass | ||
else: | ||
if oldwords[0] != '': |
There was a problem hiding this comment.
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:
- Simplify accessing last index of list (
simplify-negative-index
) - Swap if/else to remove empty if body (
remove-pass-body
) - Replace unused for index with underscore (
for-index-underscore
) - Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] (
remove-redundant-slice-index
)
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: |
There was a problem hiding this comment.
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:
- Use str.join() instead of for loop (
use-join
) - Simplify sequence comparison (
simplify-len-comparison
) - Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
This removes the following comments ( why? ):
#timeout
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) |
There was a problem hiding this comment.
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:
- Add guard clause (
last-if-guard
) - Replace if statement with if expression (
assign-if-exp
)
print(str(self.activePollMessageIDs)) | ||
print(self.activePollMessageIDs) |
There was a problem hiding this comment.
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:
- Remove unnecessary call to
str()
withinprint()
(remove-str-from-print
)
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} |
There was a problem hiding this comment.
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:
- Convert for loop into list comprehension (
list-comprehension
) - Convert for loop into dictionary comprehension (
dict-comprehension
)
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}") |
There was a problem hiding this comment.
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:
- Swap if/else branches (
swap-if-else-branches
) - Merge else clause's nested if statement into elif (
merge-else-if-into-elif
)
await ctx.send(f"Role associations have been cleared. {str(self.roleassocdict)}") | ||
await ctx.send(f"Role associations have been cleared. {self.roleassocdict}") |
There was a problem hiding this comment.
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:
- Remove unnecessary calls to
str()
from formatted values in f-strings (remove-str-from-fstring
)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 2.25%.
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
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:Help us improve this pull request!