1
0
mirror of https://github.com/MrDetonia/Maki.git synced 2024-11-22 03:44:18 -05:00

v0.17.1 sanitize username for last.fm command

This commit is contained in:
Zac Herd 2016-12-01 19:40:24 +00:00
parent 6737b3dddf
commit 4e735835df

7
bot.py
View File

@ -32,7 +32,7 @@ from secret import token, lfmkey
# CONFIGURATION # CONFIGURATION
# bot version # bot version
version = "v0.17.0" version = "v0.17.1"
# text shown by .help command # text shown by .help command
helptext = """I am a Discord bot written in Python helptext = """I am a Discord bot written in Python
@ -90,8 +90,11 @@ def dtfromts(ts):
# gets now playing information from last.fm # gets now playing information from last.fm
def lastfm_np(username): def lastfm_np(username):
# sanitise username
cleanusername = re.sub(r'[^a-zA-Z0-9_-]', '', username, 0)
# fetch xml from last.fm # fetch xml from last.fm
r = http.request("GET", "https://ws.audioscrobbler.com/2.0/?method=user.getRecentTracks&user=" + username + "&limit=1&api_key=" + lfmkey) r = http.request("GET", "https://ws.audioscrobbler.com/2.0/?method=user.getRecentTracks&user=" + cleanusername + "&limit=1&api_key=" + lfmkey)
if r.status != 200: if r.status != 200:
return "Couldn't get last.fm data for " + username return "Couldn't get last.fm data for " + username