def timer_goto(self, ctx: commands.Context, period_idx):
""" Skips to the n-th period, assuming the periods' indexes go
from 1 to the amount of them.
:param period_idx: The index of the period to start from, from 1 to n.
:type period_idx: 'next' or int such that 1 <= period_idx <= n,
n being the amount of periods set.
"""
channel = self.bot.spoof(ctx.message.author, lib.get_channel(ctx))
interface = self.bot.get_interface(channel)
if period_idx == "next":
idx = interface.timer.get_period(True) + 1
else:
try:
idx = int(period_idx)
except TypeError:
raise commands.BadArgument
label = interface.timer.goto(idx)
if label is not None:
log = send = "Moved to period number {!s} ({})".format(idx, label)
if interface.timer.get_state() != State.STOPPED:
await self.bot.edit_message(interface.list_message,
interface.timer.list_periods())
if interface.timer.get_state() == State.PAUSED:
await self.bot.edit_message(interface.time_message,
interface.timer.time())
else:
log = "Invalid period number entered when trying goto command."
send = "Invalid period number."
lib.log(log, channel_id=channel.id)
await self.bot.say(send, delete_after=self.bot.ans_lifespan)
评论列表
文章目录