Skip to content

Instantly share code, notes, and snippets.

@cosven
Last active March 27, 2019 07:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cosven/7a746fa61f94a4c83cb6bf654cea6bf8 to your computer and use it in GitHub Desktop.
Save cosven/7a746fa61f94a4c83cb6bf654cea6bf8 to your computer and use it in GitHub Desktop.
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