def create_project(self, owner: int, member: int, name: str, channel: int, message: int) -> dict: """This creates a project.""" project = { "name": name, "tasks": [], "owner": str(owner), "members": [str(member)], "channel": str(channel), "message": str(message), "number": None } guild_db = flux.db("guilds").find(self.guild) if not guild_db: project["number"] = 0 flux.db("guilds").insert(self.guild, {"projects": [project]}) elif not guild_db.get("projects"): project["number"] = 0 flux.db("guilds").update(self.guild, {"projects": [project]}) else: if self.find_project(name): return None project["number"] = len(guild_db.get("projects")) guild_db.get("projects").append(project) flux.db("guilds").update(self.guild, guild_db) flux.dispatch("project_created", name) return project
def update_task_status(self, project: str, task: str, status: bool) -> dict: """This marks a task as completed.""" task = self.find_task(project, task) if task.get("completed") == status: return task if not task: return project = self.find_project(task.get("project")) if not project: return guild_db = flux.db("guilds").find(self.guild) i = 0 for iteration in guild_db['projects']: i += 1 if iteration['name'] == project['name']: print(iteration) break j = 0 for iteration in project['tasks']: j += 1 if iteration['name'] == task['name']: print(iteration) break print(f"i: {i} j: {j}") guild_db["projects"][i - 1]["tasks"][j - 1]["completed"] = status flux.db("guilds").update(self.guild, guild_db) if status is True: flux.dispatch("task_complete", self.guild, task) if status is False: print("Do you even get here?") flux.dispatch("task_revoke", self.guild, task) return task
def update_task_members(self, project: str, task: str, member: list) -> dict: """This assigns a member to a task.""" task = self.find_task(project, task) member = [str(x) for x in member] project = self.find_project(task.get("project")) guild_db = flux.db("guilds").find(self.guild) guild_db["projects"][project.get("number")]["tasks"][task.get( "number")]["assigned"].extend(member) flux.db("guilds").update(self.guild, guild_db) flux.dispatch("task_member_update", task, int(self.guild), member) return task
def add_project_members(self, project: str, members: list) -> dict: """This adds a project member to the member list.""" guild_db = flux.db("guilds").find(self.guild) members = [str(member) for member in members] project = self.find_project(project) current_owners = project.get('members') current_owners.extend(members) guild_db["projects"][project.get("number")]["members"] = current_owners flux.db("guilds").update(self.guild, guild_db) flux.dispatch("project_member_add", self.guild, project, members) return project
def create_task(self, project: str, name: str, value: int, due: datetime.datetime) -> dict: """This creates a task within a project.""" start_ = (datetime.datetime.now() + datetime.timedelta(minutes=0)) task = { "name": name, "start_timestamp": start_, "end_timestamp": due, "completed": False, "assigned": [], "value": value, "project": project, "number": None } project = self.find_project(project) project.get("tasks").append(task) guild_db = flux.db("guilds").find(self.guild) number = len(guild_db["projects"][project.get("number")]["tasks"]) task["number"] = number guild_db["projects"][project.get("number")]["tasks"].append(task) flux.db("guilds").update(self.guild, guild_db) flux.dispatch("task_create", self.guild, task) return task