Skip to content
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

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

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Jul 13, 2022

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:

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

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from smcclennon July 13, 2022 10:35
def noisy(filePath):
def noisy(self):
Copy link
Author

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:

def hum(filePath):
def hum(self):
Copy link
Author

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:

Comment on lines -22 to +25
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'
)

Copy link
Author

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:

Comment on lines -60 to -63
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
Copy link
Author

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:

Comment on lines -111 to +112
if processed == None:
if processed is None:
Copy link
Author

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:

Comment on lines -219 to +244
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}']
Copy link
Author

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:

Comment on lines -243 to +308
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)',
)
Copy link
Author

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:

Comment on lines -284 to +332
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]
Copy link
Author

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:

Comment on lines -311 to +339
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):
Copy link
Author

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:

if environment_variables['current_env_var'][variable_name] == None:
if environment_variables['current_env_var'][variable_name] is None:
Copy link
Author

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:

@lgtm-com
Copy link

lgtm-com bot commented Jul 13, 2022

This pull request introduces 1 alert and fixes 13 when merging 5721e2a into 1178c99 - view on LGTM.com

new alerts:

  • 1 for Unreachable code

fixed alerts:

  • 7 for First parameter of a method is not named 'self'
  • 3 for Testing equality to None
  • 2 for Unnecessary pass
  • 1 for Unreachable code

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