-
Notifications
You must be signed in to change notification settings - Fork 20
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 #8
base: master
Are you sure you want to change the base?
Conversation
def noisy(filePath): | ||
def noisy(self): |
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 ACRAPI.noisy
refactored with the following changes:
- The first argument to instance methods should be
self
(instance-method-first-arg-name
)
def hum(filePath): | ||
def hum(self): |
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 ACRAPI.hum
refactored with the following changes:
- The first argument to instance methods should be
self
(instance-method-first-arg-name
)
logger.warning('ACR Cloud ping error code: '+str(ACR_PING_CODE)+', retrying in 20 seconds') | ||
logger.warning( | ||
f'ACR Cloud ping error code: {str(ACR_PING_CODE)}, retrying in 20 seconds' | ||
) | ||
|
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.
Lines 22-22
refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation
)
pass | ||
elif '[WinError 32] The process cannot access the file because it is being used by another process' in str(context.error): | ||
logger.info('File cannot be accessed (likely deleted), being used by another process, pass') | ||
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 error
refactored with the following changes:
- Remove redundant pass statement [×2] (
remove-redundant-pass
)
if processed == None: | ||
if processed is None: |
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 sendMsg
refactored with the following changes:
- Use x is None rather than x == None (
none-compare
)
def getUserData(update): | ||
def getUserData(self): | ||
#update = json.loads(update) | ||
logger.debug('getUserData(0/2)') | ||
|
||
# May be completely unnecessary, just in case | ||
if hasattr(update, 'effective_chat'): | ||
if hasattr(self, 'effective_chat'): | ||
# Get users Telegram ID | ||
userID=str(update.effective_chat.id) | ||
userID = str(self.effective_chat.id) | ||
# Add user to userdata in case they did not initially send /start | ||
# to prevent AttributeErrors occurring from their key not being | ||
# present in the database | ||
# (https://github.com/smcclennon/SongID/issues/6#issuecomment-1021517621) | ||
if userID not in userdata: | ||
SIDProcessor.addUserData(update, '0', '0') | ||
SIDProcessor.addUserData(self, '0', '0') | ||
logger.debug('getUserData(1/2)') | ||
|
||
data = userdata[f'{update.effective_user.id}'] | ||
data = userdata[f'{self.effective_user.id}'] |
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 SIDProcessor.getUserData
refactored with the following changes:
- The first argument to instance methods should be
self
(instance-method-first-arg-name
)
def fileProcess(update, context, processor): | ||
logusr(update) | ||
for attempt in range(0,10): | ||
def fileProcess(self, context, processor): | ||
logusr(self) | ||
for _ in range(10): | ||
try: | ||
logger.info('fileProcess: Attempting to send ChatAction.TYPING') | ||
context.bot.sendChatAction(chat_id=update.effective_chat.id, action=telegram.ChatAction.TYPING, timeout=10) | ||
context.bot.sendChatAction( | ||
chat_id=self.effective_chat.id, | ||
action=telegram.ChatAction.TYPING, | ||
timeout=10, | ||
) | ||
|
||
logger.info('fileProcess: Successfully sent ChatAction.TYPING') | ||
except: | ||
logger.info('fileProcess: Failed to send ChatAction.TYPING') | ||
continue | ||
logger.info('fileProcess: Breaking from ChatAction loop') | ||
break | ||
if authorised(update): | ||
context.bot.sendChatAction(chat_id=update.effective_chat.id, action=telegram.ChatAction.RECORD_AUDIO, timeout=20) | ||
fileName = fileDownload(update, context) | ||
if authorised(self): | ||
context.bot.sendChatAction( | ||
chat_id=self.effective_chat.id, | ||
action=telegram.ChatAction.RECORD_AUDIO, | ||
timeout=20, | ||
) | ||
|
||
fileName = fileDownload(self, context) | ||
if fileName != 'FILE_TOO_BIG': | ||
deleteSuccess = 0 | ||
while deleteSuccess != 5: | ||
try: | ||
if processor == 'noisy': | ||
dataProcess(update, context, ACRAPI.noisy(f'{downloadDIR}/{fileName}')) | ||
dataProcess(self, context, ACRAPI.noisy(f'{downloadDIR}/{fileName}')) | ||
os.remove(f'{downloadDIR}/{fileName}') | ||
elif processor == 'clear': | ||
dataProcess(update, context, ACRAPI.clear(f'{downloadDIR}/{fileName}')) | ||
dataProcess(self, context, ACRAPI.clear(f'{downloadDIR}/{fileName}')) | ||
os.remove(f'{downloadDIR}/{fileName}') | ||
elif processor == 'hum': | ||
dataProcess(update, context, ACRAPI.hum(f'{downloadDIR}/{fileName}')) | ||
dataProcess(self, context, ACRAPI.hum(f'{downloadDIR}/{fileName}')) | ||
os.remove(f'{downloadDIR}/{fileName}') | ||
deleteSuccess = 5 | ||
except: | ||
deleteSuccess+=1 | ||
continue | ||
else: | ||
timeLeft_int = timeLeft(update) | ||
timeLeft_int = timeLeft(self) | ||
if timeLeft_int == 1: | ||
time_msg = f'{timeLeft_int} second' | ||
else: | ||
time_msg = f'{timeLeft_int} seconds' | ||
logbotsend(update, context, f'Due to an increased volume of requests, a 20 second cooldown has been put in place to benefit the user.\n\nPlease wait {time_msg} before making another request') | ||
context.bot.send_message(devid, f'User @{update.effective_user.username} ({update.effective_chat.id}) hit the cooldown ({time_msg} left)') | ||
logbotsend( | ||
self, | ||
context, | ||
f'Due to an increased volume of requests, a 20 second cooldown has been put in place to benefit the user.\n\nPlease wait {time_msg} before making another request', | ||
) | ||
|
||
context.bot.send_message( | ||
devid, | ||
f'User @{self.effective_user.username} ({self.effective_chat.id}) hit the cooldown ({time_msg} left)', | ||
) |
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 SIDProcessor.fileProcess
refactored with the following changes:
- The first argument to instance methods should be
self
(instance-method-first-arg-name
) - Replace unused for index with underscore (
for-index-underscore
) - Replace range(0, x) with range(x) (
remove-zero-from-range
) - Remove redundant continue statement (
remove-redundant-continue
)
def commandArgs(update, context): | ||
def commandArgs(self, context): | ||
whitespace=[] | ||
keysplit=1 | ||
msgsplit=2 | ||
command = update.message.text | ||
command = self.message.text | ||
split = command.split(' ') # Split the message with each space | ||
if len(split) < 3: | ||
return None | ||
if len(split) >= 3: | ||
key = split[1] | ||
while key == "": # If the user used irregular spacing | ||
keysplit+=1 | ||
whitespace.append(keysplit-1) | ||
key = split[keysplit] | ||
key = split[1] | ||
while key == "": # If the user used irregular spacing | ||
keysplit+=1 | ||
whitespace.append(keysplit-1) | ||
key = split[keysplit] | ||
|
||
message = command | ||
for space in whitespace: | ||
message = message.replace(split[space], '', 1) | ||
message = message.replace(split[0]+' ', '', 1) | ||
message = message.replace(split[keysplit]+' ', '', 1) | ||
message = command | ||
for space in whitespace: | ||
message = message.replace(split[space], '', 1) | ||
message = message.replace(f'{split[0]} ', '', 1) | ||
message = message.replace(f'{split[keysplit]} ', '', 1) | ||
|
||
if len(message) > 5000: | ||
return ['too_long', len(message)-5000] | ||
return [key, message] | ||
if len(message) > 5000: | ||
return ['too_long', len(message)-5000] | ||
return [key, message] |
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 SIDProcessor.commandArgs
refactored with the following changes:
- The first argument to instance methods should be
self
(instance-method-first-arg-name
) - Remove redundant conditional (
remove-redundant-if
) - Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation
)
def find_key(d, value): # https://stackoverflow.com/a/15210253 | ||
for k,v in d.items(): | ||
def find_key(self, value): # https://stackoverflow.com/a/15210253 | ||
for k,v in self.items(): | ||
if isinstance(v, dict): | ||
p = SIDProcessor.find_key(v, value) | ||
if p: | ||
if p := SIDProcessor.find_key(v, value): |
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 SIDProcessor.find_key
refactored with the following changes:
- The first argument to instance methods should be
self
(instance-method-first-arg-name
) - Use named expression to simplify assignment and conditional (
use-named-expression
)
if environment_variables['current_env_var'][variable_name] == None: | ||
if environment_variables['current_env_var'][variable_name] is None: |
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.
Lines 61-94
refactored with the following changes:
- Use x is None rather than x == None (
none-compare
) - Use f-string instead of string concatenation [×4] (
use-fstring-for-concatenation
) - Use set when checking membership of a collection of literals (
collection-into-set
)
This pull request introduces 1 alert and fixes 13 when merging 5721e2a into 1178c99 - view on LGTM.com new alerts:
fixed alerts:
|
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!