Last active
March 27, 2019 07:04
-
-
Save cosven/7a746fa61f94a4c83cb6bf654cea6bf8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
from functools import partial | |
from slacker import Slacker | |
__alias__ = 'Slack 状态同步' | |
__version__ = '0.1' | |
__desc__ = 'Slack 状态同步' | |
slack = Slacker('xx') | |
def sync_status(song): | |
if song is None: | |
return | |
status_text = (song.title_display or 'unknown') + \ | |
' - ' + \ | |
(song.artists_name_display or 'unknown') | |
profile = u'{"status_text": "正在听:%s", "status_emoji": ":headphones:"}' % \ | |
status_text | |
loop = asyncio.get_event_loop() | |
loop.run_in_executor(None, partial(slack.users.profile.set, profile=profile)) | |
def enable(app): | |
app.player.playlist.song_changed.connect(sync_status, aioqueue=True) | |
def disable(app): | |
app.player.playlist.song_changed.disconnect(sync_status) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment