コード例 #1
0
    async def on_task_complete(self, guild_id: int, task: dict) -> None:
        """This event is fired on the completion of a task."""
        pointhandler = Points()
        projects = ProjectHandler(guild_id)
        project = projects.find_project(task.get("project"))
        value = self.bot.db("guilds").find(guild_id).get("projects")[
            project.get('number')].get("tasks")[task.get("number")]["value"]
        # start_timestamp = (datetime.datetime.now() -
        #                 task.get("start_timestamp")).total_seconds()
        # end_timestamp = (task.get("end_timestamp") -
        #                datetime.datetime.now()).total_seconds()
        pointhandler.add_points(guild_id, task, value)

        channel = await self.bot.fetch_channel(int(project.get("channel")))
        task_name = task.get("name")
        value = self.bot.db("guilds").find(guild_id).get("projects")[
            project.get('number')].get("tasks")[task.get("number")]["value"]
        message = await channel.fetch_message(
            int(projects.find_project(task.get("project")).get("message")))
        await message.edit(
            content=projects.project_progress_bar(task.get("project")))
        return await channel.send(f"**> Task completion:** The task "
                                  f"`{task_name}` was completed and "
                                  f" the bounty of `{value}` "
                                  "points has been claimed!")
コード例 #2
0
    async def on_task_revoke(self, guild_id: int, task: dict) -> None:
        """This is fired when someone marks a task as incomplete."""
        projects = ProjectHandler(guild_id)
        pointhandler = Points()
        all_logs = list(self.bot.db("logs").find_all())
        for member in task.get("assigned"):
            task_name = task.get("name")
            logs = list(
                filter(
                    lambda all_logs: all_logs['name'] ==
                    f"point_addition_{member}_{task_name}", all_logs))
            points_gained = [log.get("amount") for log in logs]
            for points in points_gained:
                pointhandler.remove_points(guild_id, task, points)

        project = projects.find_project(task.get("project"))
        channel = await self.bot.fetch_channel(int(project.get("channel")))
        task_name = task.get("name")
        task_reward = self.bot.db("guilds").find(guild_id).get("projects")[
            project.get('number')].get("tasks")[task.get("number")]["value"]
        message = await channel.fetch_message(
            int(projects.find_project(task.get("project")).get("message")))
        await message.edit(
            content=projects.project_progress_bar(task.get("project")))
        return await channel.send(f"**> Task revoked:** The task `{task_name}`"
                                  " was marked as incomplete. "
                                  f"The bounty of `{task_reward}` "
                                  "points is back up.")
コード例 #3
0
 async def on_task_create(self, guild_id: int, task: dict) -> None:
     """Sends a message on the creation of a task to the project channel."""
     projects = ProjectHandler(guild_id)
     project = projects.find_project(task.get("project"))
     channel = await self.bot.fetch_channel(int(project.get("channel")))
     task_name = task.get("name")
     task_reward = task.get("value")
     message = await channel.fetch_message(
         int(projects.find_project(task.get("project")).get("message")))
     await message.edit(
         content=projects.project_progress_bar(task.get("project")))
     await channel.send(f"**> Task creation:** The task `{task_name}` "
                        "was created. Bounty for completion: "
                        f"`{task_reward}` points!")