def exists(self, titles: TitleList) -> bool: titles = titles.copy() father_titles = titles.copy() title = father_titles.pop_tail() try: father = self[father_titles] except TaskNotFound: return False if title in father.child_titles: return True else: return False
def set_task_priority(source: CommandSource, titles: str, priority: Optional[int] = None): GlobalVariables.task_manager.set_priority(TitleList(titles), priority) info_task(source, titles, headline_override=tr('priority_set')) GlobalVariables.log( f"{source_name(source)} set task {titles} priority to {priority}")
def set_task_deadline(source: CommandSource, titles: str, ddl: str) -> None: deadline = float(time.time()) + float(ddl) * 3600 * 24 GlobalVariables.task_manager.set_deadline(TitleList(titles), deadline) info_task(source, titles, headline_override=tr("ddl_set")) GlobalVariables.log( f"{source_name(source)} set task {titles} deadline to {formatted_time(deadline, locale='en_us')}" )
def __getitem__( self, titles: Union[TitleList, str]) -> Union['Task', 'TaskBase']: if isinstance(titles, str): titles = TitleList(titles) if titles.is_empty: return self next_layer_title, titles = self.next_layer(titles) if next_layer_title not in self.child_titles: raise TaskNotFound(titles.lappend(next_layer_title)) return self.child_map[next_layer_title][titles]
def add_task(source: CommandSource, titles: str, desc: str = ''): titles = TitleList(titles) titles_for_text = titles.copy() GlobalVariables.task_manager.add_task(titles, desc=desc) info_task(source, title=str(titles_for_text), headline_override=tr("new_task_created")) GlobalVariables.log( f"{source_name(source)} created new task named {str(titles_for_text)}")
def rm_work(self, player: str, task_title: Union['TitleList', str], should_save=True) -> None: task_title = str(task_title) if player not in self.player_work.keys(): self.player_work[player] = set() if task_title not in self.player_work[player]: raise TaskNotFound(TitleList(task_title)) self.player_work[player].remove(task_title) if should_save: self.save()
def rename_task(source: CommandSource, old_titles: str, new_title: str) -> None: if '.' in list(new_title): source.reply(tr("mcd_task.illegal_title_with_dot", new_title)) return GlobalVariables.task_manager.rename_task(TitleList(old_titles), new_title) new_titles = TitleList(old_titles) new_titles.pop_tail() new_titles.append(new_title) info_task(source, title=str(new_titles), headline_override=tr("mcd_task.task_renamed", old_titles)) GlobalVariables.log( f"{source_name(source)} renamed {old_titles} to {str(new_titles)}")
def set_responsible(source: CommandSource, titles: str, players: Optional[str] = None) -> None: if players is None: if isinstance(source, PlayerCommandSource): players = source.player else: illegal_call(source) return players = players.split(' ') num = GlobalVariables.task_manager.set_responsible(TitleList(titles), *players) info_task(source, titles, headline_override=tr("mcd_task.added_responsibles_title", num)) GlobalVariables.log( f"{source_name(source)} added responsibles for task {str(titles)}: {str(players)}" )
def rename_task(self, old_title: Union['TitleList', str], new_title: Union['TitleList', str], should_save=True) -> None: old_title, new_titles = str(old_title), TitleList(old_title) new_titles.pop_tail() new_titles.append(new_title) new_title = str(new_titles) new_data = {} for key, value in self.player_work.items(): for t in value: psd = parse(old_title + '{ext}', t) if psd is not None: new_data[key] = value.copy() new_data[key].remove(t) new_data[key].add(new_title + psd['ext']) self.player_work.update(new_data) if should_save: self.save()
def full_path(self, titles: TitleList = TitleList()) -> TitleList: return self._father.full_path(titles.copy().lappend(self.title))
def clear_task_deadline(source: CommandSource, titles: str): GlobalVariables.task_manager.set_deadline(TitleList(titles), 0) info_task(source, titles, headline_override=tr('ddl_cleared')) GlobalVariables.log( f"{source_name(source)} removed task {titles} deadline")
def ensure_not_exist(source: CommandSource, context: CommandContext): return not GlobalVariables.task_manager.exists( TitleList(context[title]))
def edit_desc(source: CommandSource, titles: str, desc: str) -> None: GlobalVariables.task_manager.edit_desc(TitleList(titles), desc) info_task(source, title=titles, headline_override='changed_desc_title') GlobalVariables.log( f"{source_name(source)} changed task {titles} description to {desc}")
def remove_task(source: CommandSource, titles: str): GlobalVariables.task_manager.delete_task(TitleList(titles)) source.reply(tr("mcd_task.deleted_task", "§e{}§r".format(titles))) GlobalVariables.log(f"{source_name(source)} deleted task {titles}")
def ensure_task_exist_quotable_text(title: str = 'title'): return QuotableText(title).requires( lambda src, ctx: GlobalVariables.task_manager.exists( TitleList(ctx[title])), lambda: tr("mcd_task.task_not_found"). h(tr("mcd_task.task_not_found_hover", PREFIX)).c( RAction.run_command, f'{PREFIX} list').set_color(RColor.red))
def full_path(self, titles: 'TitleList' = TitleList()) -> 'TitleList': return titles
def full_path(self, titles: 'TitleList' = TitleList()) -> 'TitleList': raise NotImplementedError( 'Not implemented method: TaskBase.full_path()')
def set_undone(source: CommandSource, titles: str) -> None: GlobalVariables.task_manager.undone_task(TitleList(titles)) info_task(source, title=titles, headline_override='undone_task_title') GlobalVariables.log( f"{source_name(source)} marked task {titles} as undone")