Refactor name builder logic into its own method
This commit is contained in:
parent
15ec5592fc
commit
4a7b3a4d9c
23
src/memes.py
23
src/memes.py
@ -197,6 +197,18 @@ def getRandomMeme():
|
|||||||
recentMemes.insertMeme(choice)
|
recentMemes.insertMeme(choice)
|
||||||
return choice
|
return choice
|
||||||
|
|
||||||
|
# Build an underscored name from a string
|
||||||
|
def nameBuilder(command):
|
||||||
|
uploaded_file_name = ""
|
||||||
|
for word in command:
|
||||||
|
uploaded_file_name += word + "_"
|
||||||
|
|
||||||
|
# remove the last _ from the name
|
||||||
|
uploaded_file_name = uploaded_file_name.rstrip(uploaded_file_name[-1])
|
||||||
|
|
||||||
|
# append the file extension
|
||||||
|
return uploaded_file_name
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Calldict methods
|
# Calldict methods
|
||||||
@ -282,18 +294,11 @@ async def uploadMeme(command, message, client):
|
|||||||
file_names = []
|
file_names = []
|
||||||
|
|
||||||
for file in message.attachments:
|
for file in message.attachments:
|
||||||
|
|
||||||
# if we want to override the name
|
# if we want to override the name
|
||||||
uploaded_file_name = file.filename
|
uploaded_file_name = file.filename
|
||||||
if len(command) > 1:
|
if len(command) > 1:
|
||||||
uploaded_file_name = ""
|
uploaded_file_name = nameBuilder(command[1:])
|
||||||
for word in command[1:]:
|
# add the extension
|
||||||
uploaded_file_name += word + "_"
|
|
||||||
|
|
||||||
# remove the last _ from the name
|
|
||||||
uploaded_file_name = uploaded_file_name.rstrip(uploaded_file_name[-1])
|
|
||||||
|
|
||||||
# append the file extension
|
|
||||||
name, ext = os.path.splitext(file.filename)
|
name, ext = os.path.splitext(file.filename)
|
||||||
uploaded_file_name += ext
|
uploaded_file_name += ext
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user