-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sourcery refactored master branch #1
base: master
Are you sure you want to change the base?
Conversation
data = brotli.decompress(payload) | ||
return data | ||
return brotli.decompress(payload) |
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 Wrapper.brdecompress
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
if headerModifications not in ({}, None): | ||
editedSession = copy.deepcopy(reqsession) | ||
if "update" in headerModifications: | ||
editedSession.headers.update(headerModifications["update"]) | ||
if "remove" in headerModifications: | ||
for header in headerModifications["remove"]: | ||
if header in editedSession.headers: | ||
del editedSession.headers[header] | ||
return editedSession | ||
else: | ||
if headerModifications in ({}, None): | ||
return reqsession | ||
editedSession = copy.deepcopy(reqsession) | ||
if "update" in headerModifications: | ||
editedSession.headers.update(headerModifications["update"]) | ||
if "remove" in headerModifications: | ||
for header in headerModifications["remove"]: | ||
if header in editedSession.headers: | ||
del editedSession.headers[header] | ||
return editedSession |
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 Wrapper.editedReqSession
refactored with the following changes:
- Add guard clause (
last-if-guard
)
if isinstance(body, dict): | ||
data = {'data': json.dumps(body)} | ||
else: | ||
data = {'data': body} | ||
data = {'data': json.dumps(body)} if isinstance(body, dict) else {'data': body} |
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 Wrapper.sendRequest
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
if self.Science == "": | ||
self.Science = Science(self.discord, self.s, self.log, None, "0", "") #no sequential data needed for parsing | ||
result = self.Science.UUIDobj.parse(client_uuid) | ||
self.Science = "" #reset | ||
return result | ||
else: | ||
if self.Science != "": | ||
return self.Science.UUIDobj.parse(client_uuid) | ||
self.Science = Science(self.discord, self.s, self.log, None, "0", "") #no sequential data needed for parsing | ||
result = self.Science.UUIDobj.parse(client_uuid) | ||
self.Science = "" #reset | ||
return result |
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 Client.parseClientUUID
refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
if color: | ||
string = color + text + '\033[m' | ||
else: | ||
string = text | ||
string = color + text + '\033[m' if color else text |
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 Logger.log
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
@@ -219,7 +219,6 @@ def removeCommand(self, func, exactMatch=True, allMatches=False): | |||
del self._after_message_hooks[commandsCopy.index(func)] | |||
except ValueError: | |||
Logger.log('{} not found in _after_message_hooks.'.format(func), None, self.log) | |||
pass |
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 RemoteAuth.removeCommand
refactored with the following changes:
- Remove redundant pass statement (
remove-redundant-pass
)
f = {} | ||
for i in self.relationships: #where i is a user id | ||
if self.relationships[i]['type'] == 'friend': | ||
f[i] = self.relationships[i] | ||
return f | ||
return { | ||
i: self.relationships[i] | ||
for i in self.relationships if self.relationships[i]['type'] == 'friend' | ||
} |
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 Session.friends
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
) - Convert for loop into dictionary comprehension (
dict-comprehension
)
This removes the following comments ( why? ):
#where i is a user id
b = {} | ||
for i in self.relationships: #where i is a user id | ||
if self.relationships[i]['type'] == 'blocked': | ||
b[i] = self.relationships[i] | ||
return b | ||
return { | ||
i: self.relationships[i] | ||
for i in self.relationships if self.relationships[i]['type'] == 'blocked' | ||
} |
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 Session.blocked
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
) - Convert for loop into dictionary comprehension (
dict-comprehension
)
This removes the following comments ( why? ):
#where i is a user id
ifr = {} | ||
for i in self.relationships: | ||
if self.relationships[i]['type'] == 'pending_incoming': | ||
ifr[i] = self.relationships[i] | ||
return ifr | ||
return { | ||
i: self.relationships[i] | ||
for i in self.relationships | ||
if self.relationships[i]['type'] == 'pending_incoming' | ||
} |
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 Session.incomingFriendRequests
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
) - Convert for loop into dictionary comprehension (
dict-comprehension
)
ofr = {} | ||
for i in self.relationships: | ||
if self.relationships[i]['type'] == 'pending_outgoing': | ||
ofr[i] = self.relationships[i] | ||
return ofr | ||
return { | ||
i: self.relationships[i] | ||
for i in self.relationships | ||
if self.relationships[i]['type'] == 'pending_outgoing' | ||
} |
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 Session.outgoingFriendRequests
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
) - Convert for loop into dictionary comprehension (
dict-comprehension
)
all_categories = {} | ||
for i in self.channelsAndCategories: #https://discord.com/developers/docs/resources/channel#channel-object-channel-types | ||
if self.channelsAndCategories[i]['type'] == 4: | ||
all_categories[i] = self.channelsAndCategories[i] | ||
return all_categories | ||
return { | ||
i: self.channelsAndCategories[i] | ||
for i in self.channelsAndCategories | ||
if self.channelsAndCategories[i]['type'] == 4 | ||
} |
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 guild.categories
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
) - Convert for loop into dictionary comprehension (
dict-comprehension
)
This removes the following comments ( why? ):
#https://discord.com/developers/docs/resources/channel#channel-object-channel-types
all_channels = {} | ||
for i in self.channelsAndCategories: #https://discord.com/developers/docs/resources/channel#channel-object-channel-types | ||
if self.channelsAndCategories[i]['type'] != 4: | ||
all_channels[i] = self.channelsAndCategories[i] | ||
return all_channels | ||
return { | ||
i: self.channelsAndCategories[i] | ||
for i in self.channelsAndCategories | ||
if self.channelsAndCategories[i]['type'] != 4 | ||
} |
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 guild.channels
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
) - Convert for loop into dictionary comprehension (
dict-comprehension
)
This removes the following comments ( why? ):
#https://discord.com/developers/docs/resources/channel#channel-object-channel-types
if channelData["type"] in ("dm", "group_dm"): #private_channel | ||
if "recipient_ids" not in channelData and "recipients" in channelData: #should be true, running this check just in case | ||
channelData["recipient_ids"] = [i["id"] for i in channelData["recipients"]] | ||
if (channelData["type"] in ("dm", "group_dm") | ||
and "recipient_ids" not in channelData and "recipients" in channelData): #should be true, running this check just in case | ||
channelData["recipient_ids"] = [i["id"] for i in channelData["recipients"]] |
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 ChannelParse.channel_create
refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs
)
This removes the following comments ( why? ):
#private_channel
if channelData["type"] in ("dm", "group_dm"): #private_channel | ||
if "recipient_ids" not in channelData and "recipients" in channelData: | ||
channelData["recipient_ids"] = [i["id"] for i in channelData["recipients"]] | ||
if (channelData["type"] in ("dm", "group_dm") | ||
and "recipient_ids" not in channelData and "recipients" in channelData): | ||
channelData["recipient_ids"] = [i["id"] for i in channelData["recipients"]] |
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 ChannelParse.channel_delete
refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs
)
This removes the following comments ( why? ):
#private_channel
if keep == None: | ||
if keep is None: | ||
remove = allProperties | ||
elif keep == "all": | ||
remove = [] | ||
elif isinstance(keep, list) or isinstance(keep, tuple): | ||
elif isinstance(keep, (list, tuple)): |
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 GuildCombo.reformat_member
refactored with the following changes:
- Use x is None rather than x == None (
none-compare
) - Merge isinstance calls (
merge-isinstance
)
if self.analytics_token == None: #if not logged in. ex: bot=discum.Client(token='poop') | ||
headerModifications = {"update":{"X-fingerprint": self.xfingerprint}, "remove": ["Authorization"]} | ||
return Wrapper.sendRequest(self.s, 'post', url, body, headerModifications=headerModifications, log=self.log) | ||
else: | ||
if self.analytics_token is not None: | ||
return Wrapper.sendRequest(self.s, 'post', url, body, log=self.log) | ||
headerModifications = {"update":{"X-fingerprint": self.xfingerprint}, "remove": ["Authorization"]} | ||
return Wrapper.sendRequest(self.s, 'post', url, body, headerModifications=headerModifications, log=self.log) |
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 Science.science
refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
) - Use x is None rather than x == None (
none-compare
)
This removes the following comments ( why? ):
#if not logged in. ex: bot=discum.Client(token='poop')
if result.get('mfa') == True and result.get('sms') == False: #sms login not implemented yet | ||
time.sleep(2) #2 seconds is minimal, don't want to look too automated | ||
ticket = result['ticket'] | ||
if secret != "": | ||
code = TOTP(secret).generateTOTP() | ||
code = str(code) #just in case an int is inputted | ||
totpUrl = self.discord+"auth/mfa/totp" | ||
totpBody = { | ||
"code": code, | ||
"ticket": ticket, | ||
"login_source": source, | ||
"gift_code_sku_id": gift_code_sku_id | ||
} | ||
totpResponse = Wrapper.sendRequest(self.editedS, 'post', totpUrl, totpBody, log=self.log) | ||
return totpResponse, self.xfingerprint | ||
else: | ||
if result.get('mfa') != True or result.get('sms') != False: | ||
return response, self.xfingerprint | ||
time.sleep(2) #2 seconds is minimal, don't want to look too automated | ||
ticket = result['ticket'] | ||
if secret != "": | ||
code = TOTP(secret).generateTOTP() | ||
code = str(code) #just in case an int is inputted | ||
totpUrl = self.discord+"auth/mfa/totp" | ||
totpBody = { | ||
"code": code, | ||
"ticket": ticket, | ||
"login_source": source, | ||
"gift_code_sku_id": gift_code_sku_id | ||
} | ||
totpResponse = Wrapper.sendRequest(self.editedS, 'post', totpUrl, totpBody, log=self.log) | ||
return totpResponse, self.xfingerprint |
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 Login.login
refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
This removes the following comments ( why? ):
#sms login not implemented yet
if locale == None: | ||
sp.pop("system_locale") | ||
if locale is None: | ||
sp.pop("system_locale") |
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 SuperProperties.getSuperProperties
refactored with the following changes:
- Use x is None rather than x == None (
none-compare
)
if userID == "default": | ||
userID = self.userID | ||
else: | ||
userID = int(userID) | ||
|
||
userID = self.userID if userID == "default" else int(userID) |
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 Client_UUID.calculate
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
unpacked = [] | ||
for i in range(6): | ||
unpacked.append(struct.unpack('<i', decoded_client_uuid[4*i:4*i+4])[0]) | ||
UUIDdata = {} | ||
unpacked = [ | ||
struct.unpack('<i', decoded_client_uuid[4 * i : 4 * i + 4])[0] | ||
for i in range(6) | ||
] | ||
|
||
userIDguess = (unpacked[1]<<32) + unpacked[0] | ||
UUIDdata['userID'] = repr(userIDguess if userIDguess%4294967296<=2147483647 else userIDguess+4294967296) | ||
UUIDdata['randomPrefix'] = unpacked[2] | ||
UUIDdata = { | ||
'userID': repr( | ||
userIDguess | ||
if userIDguess % 4294967296 <= 2147483647 | ||
else userIDguess + 4294967296 | ||
), | ||
'randomPrefix': unpacked[2], | ||
} | ||
|
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 Client_UUID.parse
refactored with the following changes:
- Merge dictionary assignment with declaration (
merge-dict-assign
) - Convert for loop into list comprehension (
list-comprehension
) - Move assignment closer to its usage within a block (
move-assign-in-block
)
if isinstance(c, tuple) or isinstance(c, list): | ||
if isinstance(c, (tuple, list)): |
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 Color.get
refactored with the following changes:
- Merge isinstance calls (
merge-isinstance
) - Replace if statement with if expression (
assign-if-exp
)
encodedData = base64.b64encode(binaryData).decode("utf-8") | ||
return encodedData | ||
return base64.b64encode(binaryData).decode("utf-8") |
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 ContextProperties.encodeData
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
if m['type'] == 'reply': | ||
if 'referenced_message' in m and m['referenced_message']['author']['id'] == bot.gateway.session.user['id'] and 'guild_id' not in m: | ||
time.sleep(1) #instant replies make ppl think ur running a selfbot so... | ||
channelID = m['channel_id'] | ||
baseURL = "https://discord.com/api/channels/{}/messages".format(channelID) | ||
POSTedJSON = json.dumps ({"content":"The server Gods have allowed me to grant you the server badge. You are now a server :).","nonce":None,"tts":False,"message_reference":{"guild_id":None,"channel_id":m['channel_id'],"message_id":m['id']},"allowed_mentions":{"parse":["users","roles","everyone"],"replied_user":False}}) | ||
try: | ||
bot.s.post(baseURL, data=POSTedJSON) | ||
except: | ||
bot.s.post(baseURL, data=POSTedJSON) | ||
time.sleep(2) #instant replies make ppl think ur running a selfbot so... | ||
if ( | ||
m['type'] == 'reply' | ||
and 'referenced_message' in m | ||
and m['referenced_message']['author']['id'] | ||
== bot.gateway.session.user['id'] | ||
and 'guild_id' not in m | ||
): | ||
time.sleep(1) #instant replies make ppl think ur running a selfbot so... | ||
channelID = m['channel_id'] | ||
baseURL = "https://discord.com/api/channels/{}/messages".format(channelID) | ||
POSTedJSON = json.dumps ({"content":"The server Gods have allowed me to grant you the server badge. You are now a server :).","nonce":None,"tts":False,"message_reference":{"guild_id":None,"channel_id":m['channel_id'],"message_id":m['id']},"allowed_mentions":{"parse":["users","roles","everyone"],"replied_user":False}}) | ||
try: | ||
bot.s.post(baseURL, data=POSTedJSON) | ||
except: | ||
bot.s.post(baseURL, data=POSTedJSON) | ||
time.sleep(2) #instant replies make ppl think ur running a selfbot so... |
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 helloworld
refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs
)
lastName = sorted(set([re.sub(' +', ' ', j['nick'].lower()) if (j.get('nick') and re.sub(' +', ' ', j.get('nick').lower()).startswith(''.join(bot.qList))) else re.sub(' +', ' ', j['username'].lower()) for j in data]))[-1] | ||
lastName = sorted({ | ||
re.sub(' +', ' ', j['nick'].lower()) if | ||
(j.get('nick') | ||
and re.sub(' +', ' ', | ||
j.get('nick').lower()).startswith(''.join(bot.qList))) else | ||
re.sub(' +', ' ', j['username'].lower()) | ||
for j in data | ||
})[-1] | ||
try: | ||
option = lastName[len(bot.qList)] | ||
return option | ||
return lastName[len(bot.qList)] | ||
except IndexError: | ||
return None | ||
elif action == 'replace': | ||
if bot.qList[-1] in allchars: | ||
options = allchars[allchars.index(bot.qList[-1])+1:] | ||
if ' ' in options and (len(bot.qList)==1 or (len(bot.qList)>1 and bot.qList[-2]==' ')): #cannot start with a space and cannot have duplicate spaces | ||
options.remove(' ') | ||
return options | ||
else: | ||
if bot.qList[-1] not in allchars: | ||
return None | ||
options = allchars[allchars.index(bot.qList[-1])+1:] | ||
if ' ' in options and (len(bot.qList)==1 or (len(bot.qList)>1 and bot.qList[-2]==' ')): #cannot start with a space and cannot have duplicate spaces | ||
options.remove(' ') | ||
return 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 calculateOption
refactored with the following changes:
- Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension
) - Replace unneeded comprehension with generator (
comprehension-to-generator
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
) - Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.93%.
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
master
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
master
branch, then run:Help us improve this pull request!