@@ -42,7 +42,7 @@ def get_account(nick):
4242 return last_account
4343
4444
45- @hook .command ("lastfm" , "np" , "l" , autohelp = False )
45+ @hook .command ("lastfm" , "last" , " np" , "l" , autohelp = False )
4646def lastfm (text , nick , db , bot , notice ):
4747 """[user] [dontsave] - displays the now playing (or last played) track of LastFM user [user]"""
4848 api_key = bot .config .get ("api_keys" , {}).get ("lastfm" )
@@ -255,116 +255,3 @@ def topartists(text, nick, db, bot, notice):
255255 play_count = data ["topartists" ]["artist" ][r ]["playcount" ]
256256 out = out + "{} listened to {} times. " .format (artist_name , play_count )
257257 return out
258-
259-
260- @hook .command ("lt" , "ltrack" , autohelp = False )
261- def lastfm_track (text , nick , db , bot , notice ):
262- """Grabs a list of the top tracks for a last.fm username"""
263- api_key = bot .config .get ("api_keys" , {}).get ("lastfm" )
264- if not api_key :
265- return "error: no api key set"
266- artist = ""
267- track = ""
268- if text :
269- params = text .split (',' )
270- if len (params ) < 2 :
271- notice (
272- "Please specify an artist and track title in the form artist name, track name." , nick )
273- return
274- else :
275- artist = params [0 ]
276- track = params [1 ]
277- else :
278- notice (
279- "Please specify an artist and track title in the form artist name, track name." , nick )
280- return
281- username = get_account (nick )
282- if username :
283- params = {
284- 'api_key' : api_key ,
285- 'method' : 'track.getInfo' ,
286- 'artist' : artist ,
287- 'track' : track ,
288- 'username' : username ,
289- 'autocorrect' : 1
290- }
291- else :
292- params = {
293- 'api_key' : api_key ,
294- 'method' : 'track.getInfo' ,
295- 'artist' : artist ,
296- 'track' : track ,
297- 'autocorrect' : 1
298- }
299- request = requests .get (api_url , params = params )
300-
301- if request .status_code != requests .codes .ok :
302- return "Failed to fetch info ({})" .format (request .status_code )
303-
304- response = request .json ()
305- if 'error' in response :
306- return "Error: {}." .format (response ["message" ])
307-
308- track_name = response ["track" ]["name" ]
309- artist_name = response ["track" ]["artist" ]["name" ]
310- album_name = response ["track" ]["album" ]["title" ]
311- url = web .try_shorten (response ["track" ]["url" ])
312- listeners = response ["track" ]["listeners" ]
313- playcount = response ["track" ]["playcount" ]
314- out = out = "'{}' from the album {} by {} has been played {} times by {} listeners. {}" .format (
315- track_name , album_name , artist_name , playcount , listeners , url )
316- if 'userplaycount' in response ["track" ]:
317- userplaycount = response ["track" ]["userplaycount" ]
318- out = "'{}' from the album {} by {} has been played {} times by {} listeners. {} has listened {} times. {}" .format (
319- track_name , album_name , artist_name , playcount , listeners , username , userplaycount , url )
320- return out
321-
322-
323- @hook .command ("la" , "lartist" , autohelp = False )
324- def lastfm_artist (text , nick , db , bot , notice ):
325- """<artist> prints information about the specified artist"""
326- api_key = bot .config .get ("api_keys" , {}).get ("lastfm" )
327- if not api_key :
328- return "error: no api key set"
329- artist = text
330- params = ""
331- if text :
332- pass
333- else :
334- notice ("Please specify an artist." , nick )
335- username = get_account (nick )
336- if username :
337- params = {
338- 'api_key' : api_key ,
339- 'method' : 'artist.getInfo' ,
340- 'artist' : artist ,
341- 'username' : username ,
342- 'autocorrect' : 1
343- }
344- else :
345- params = {
346- 'api_key' : api_key ,
347- 'method' : 'artist.getInfo' ,
348- 'artist' : artist ,
349- 'autocorrect' : 1
350- }
351-
352- request = requests .get (api_url , params = params )
353-
354- if request .status_code != requests .codes .ok :
355- return "Failed to fetch info ({})" .format (request .status_code )
356-
357- response = request .json ()
358- if 'error' in response :
359- return "Error: {}." .format (response ["message" ])
360- artist_name = response ["artist" ]["name" ]
361- url = web .try_shorten (response ["artist" ]["url" ])
362- listeners = response ["artist" ]["stats" ]["listeners" ]
363- playcount = response ["artist" ]["stats" ]["playcount" ]
364- out = out = "{} has been played {} times by {} listeners. {}" .format (
365- artist_name , playcount , listeners , url )
366- if 'userplaycount' in response ["artist" ]["stats" ]:
367- userplaycount = response ["artist" ]["stats" ]["userplaycount" ]
368- out = "'{}' has been played {} times by {} listeners. {} has listened {} times. {}" .format (
369- artist_name , playcount , listeners , username , userplaycount , url )
370- return out
0 commit comments