本文整理汇总了Python中telegram.ext.Updater.signal_handler方法的典型用法代码示例。如果您正苦于以下问题:Python Updater.signal_handler方法的具体用法?Python Updater.signal_handler怎么用?Python Updater.signal_handler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类telegram.ext.Updater
的用法示例。
在下文中一共展示了Updater.signal_handler方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MPDDJ
# 需要导入模块: from telegram.ext import Updater [as 别名]
# 或者: from telegram.ext.Updater import signal_handler [as 别名]
#.........这里部分代码省略.........
except musicpd.CommandError as e:
self.send_text(_('Failed to order {0}').format(e))
else:
self.send_text(_("Quota used up."))
@command_handler()
@string_arg_checker('')
def order(self, path):
if path == '' and self.cached_songs:
path = random.choice(self.cached_songs)
self.order_song(path)
@command_handler()
def history(self):
history = []
print(self.quota)
for quota in self.quota.values():
for hist in quota.history:
history.append((quota.username, hist))
print(history)
# sort by time, top 10
recent = sorted(history, key=lambda hist: -hist[1][1])[0:10]
print(recent)
if recent:
self.send_text('\n'.join('@{0}: {1}'.format(username, basename_noext(song)) for username, (song, time) in reversed(recent)))
else:
self.send_text(_('No history yet.'))
@command_handler()
def help(self):
help_text = [
_("start - Description"),
_("add - Add song"),
_("sample - Randomly list some songs"),
_("status - DJ Status"),
_("stats - DJ stats"),
_("order - Order a song"),
_("searchorder - Search and order first match song"),
_("history - Order history"),
_("search - Search song"),
_("searchadd - Search and add first match song"),
_("playlist - Show current playlist"),
_("list - List files"),
_("stream - Get stream address"),
_("help - Show this help"),
]
self.send_text("\n".join(help_text))
def rebuild_state(self):
pass
watch = ('database', 'playlist')
def fill_song(self):
playlist = self.client.playlistinfo()
if len(playlist) <= 1 and self.cached_songs:
song = random.choice(self.cached_songs)
self.client.add(song)
self.client.play()
@access_mpd()
def idle_callback(self, source, condition):
changes = self.idle_client.fetch_idle()
print(changes)
for c in changes:
if c == 'database':
self.refresh_cache()
elif c == 'playlist':
self.fill_song()
self.idle_client.send_idle(*self.watch)
return True
def refresh_quota(self):
logging.log(logging.DEBUG, 'refresh_Quota')
for quota in self.quota.values():
quota.refresh()
def run(self):
for sig in [SIGINT, SIGTERM, SIGABRT]:
signal(sig, self.signal_handler)
self.connect()
self.updater.start_polling()
gobject.timeout_add(6000, self.refresh_quota)
try:
gobject.MainLoop().run()
except (KeyboardInterrupt, SystemExit):
logging.log(logging.DEBUG, "Exit")
gobject.MainLoop().quit()
self.updater.stop()
with open('history.pickle', 'wb') as handle:
pickle.dump(self.quota, handle)
def signal_handler(self, signum, frame):
gobject.MainLoop().quit()
self.updater.signal_handler(signum, frame)