Skip to content

Commit 00efbb1

Browse files
committed
Make sure the last.fm plugin doesn't ping a user with their last.fm name
1 parent 721b260 commit 00efbb1

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

plugins/lastfm.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
)
2121

2222

23+
def format_user(user):
24+
return '\u200B'.join((user[:1], user[1:]))
25+
26+
2327
def require_api_key(func):
2428
"""Marks a hook that requires an api key"""
2529

@@ -183,7 +187,7 @@ def _topartists(api_key, text, nick, period=None, limit=10):
183187

184188
artists = data["topartists"]["artist"][:limit]
185189

186-
out = "{}'s favorite artists: ".format(username)
190+
out = "{}'s favorite artists: ".format(format_user(username))
187191
for artist in artists:
188192
artist_name = artist["name"]
189193
play_count = artist["playcount"]
@@ -213,7 +217,7 @@ def lastfm(api_key, event, db, text, nick):
213217
return err
214218

215219
if "track" not in response["recenttracks"] or len(response["recenttracks"]["track"]) == 0:
216-
return 'No recent tracks for user "{}" found.'.format(user)
220+
return 'No recent tracks for user "{}" found.'.format(format_user(user))
217221

218222
tracks = response["recenttracks"]["track"]
219223

@@ -252,7 +256,7 @@ def lastfm(api_key, event, db, text, nick):
252256

253257
playcount = getusertrackplaycount(api_key, artist, title, user)
254258

255-
out = '{} {} "{}"'.format(user, status, title)
259+
out = '{} {} "{}"'.format(format_user(user), status, title)
256260
if artist:
257261
out += " by \x02{}\x0f".format(artist)
258262
if album:
@@ -296,11 +300,11 @@ def getuserartistplaycount(api_key, event, db, text, nick):
296300
return 'No such artist.'
297301

298302
if 'userplaycount' not in artist_info['artist']['stats']:
299-
return '"{}" has never listened to {}.'.format(user, text)
303+
return '"{}" has never listened to {}.'.format(format_user(user), text)
300304

301305
playcount = artist_info['artist']['stats']['userplaycount']
302306

303-
out = '"{}" has {:,} {} plays.'.format(user, int(playcount), text)
307+
out = '"{}" has {:,} {} plays.'.format(format_user(user), int(playcount), text)
304308

305309
return out
306310

@@ -352,7 +356,7 @@ def lastfmcompare(api_key, event, db, text, nick):
352356
score = float(data["comparison"]["result"]["score"])
353357
score = float("{:.3f}".format(score * 100))
354358
if score == 0:
355-
return "{} and {} have no common listening history.".format(user2, user1)
359+
return "{} and {} have no common listening history.".format(format_user(user2), format_user(user1))
356360
levels = (
357361
("Super", 95),
358362
("Very High", 80),
@@ -378,7 +382,7 @@ def lastfmcompare(api_key, event, db, text, nick):
378382
artist_string = "\x02In Common:\x02 " + ", ".join(artists) if artists else ""
379383

380384
return "Musical compatibility between \x02{}\x02 and \x02{}\x02: {} (\x02{}%\x02) {}".format(
381-
user1, user2, level, score, artist_string
385+
format_user(user1), format_user(user2), level, score, artist_string
382386
)
383387

384388

@@ -400,7 +404,7 @@ def toptrack(api_key, event, db, text, nick):
400404
return err
401405

402406
songs = data["toptracks"]["track"][:5]
403-
out = "{}'s favorite songs: ".format(username)
407+
out = "{}'s favorite songs: ".format(format_user(username))
404408
for song in songs:
405409
track_name = song["name"]
406410
artist_name = song["artist"]["name"]

0 commit comments

Comments
 (0)