# Path: scheduler/message.py
# class SchedulerMessage(discord.Message):
#     """
#     Subclassed discord message with neutered coroutines.
# 
#     Extremely butchered class for a specific use case.
#     Be careful when using this in other use cases.
#     """
# 
#     def __init__(
#         self, *, content: str, author: discord.Member, channel: discord.TextChannel
#     ) -> None:
#         # auto current time
#         self.id = discord.utils.time_snowflake(datetime.utcnow())
#         # important properties for even being processed
#         self.author = author
#         self.channel = channel
#         self.content = content
#         self.guild = channel.guild  # type: ignore
#         # this attribute being in almost everything (and needing to be) is a pain
#         self._state = self.guild._state  # type: ignore
#         # sane values below, fresh messages which are commands should exhibit these.
#         self.call = None
#         self.type = discord.MessageType.default
#         self.tts = False
#         self.pinned = False
#         # suport for attachments somehow later maybe?
#         self.attachments: List[discord.Attachment] = []
#         # mentions
#         self.mention_everyone = self.channel.permissions_for(
#             self.author
#         ).mention_everyone and bool(EVERYONE_REGEX.match(self.content))
#         # pylint: disable=E1133
#         # pylint improperly detects the inherited properties here as not being iterable
#         # This should be fixed with typehint support added to upstream lib later
#         self.mentions: List[Union[discord.User, discord.Member]] = list(
#             filter(None, [self.guild.get_member(idx) for idx in self.raw_mentions])
#         )
#         self.channel_mentions: List[discord.TextChannel] = list(
#             filter(
#                 None,
#                 [
#                     self.guild.get_channel(idx)  # type: ignore
#                     for idx in self.raw_channel_mentions
#                 ],
#             )
#         )
#         self.role_mentions: List[discord.Role] = list(
#             filter(None, [self.guild.get_role(idx) for idx in self.raw_role_mentions])
#         )


import contextlib
import attr
import discord
from datetime import datetime, timedelta, timezone
from typing import Optional, cast
from redbot.core.utils.chat_formatting import humanize_timedelta
from .message import SchedulerMessage
from __future__ import annotations





@attr.s(auto_attribs=True, slots=True)
class Task:
    nicename: str
    uid: str
    author: discord.Member
    content: str
    channel: discord.TextChannel
    initial: datetime
    recur: Optional[timedelta] = None
    extern_cog: Optional[str] = None

    def __attrs_post_init__(self):
        if self.initial.tzinfo is None:
            self.initial = self.initial.replace(tzinfo=timezone.utc)

    def __hash__(self):
        return hash(self.uid)

    async def get_message(self, bot):

        pfx = (await bot.get_prefix(self.channel))[0]
        content = f"{pfx}{self.content}"

# Path: scheduler/message.py
# class SchedulerMessage(discord.Message):
#     """
#     Subclassed discord message with neutered coroutines.
# 
#     Extremely butchered class for a specific use case.
#     Be careful when using this in other use cases.
#     """
# 
#     def __init__(
#         self, *, content: str, author: discord.Member, channel: discord.TextChannel
#     ) -> None:
#         # auto current time
#         self.id = discord.utils.time_snowflake(datetime.utcnow())
#         # important properties for even being processed
#         self.author = author
#         self.channel = channel
#         self.content = content
#         self.guild = channel.guild  # type: ignore
#         # this attribute being in almost everything (and needing to be) is a pain
#         self._state = self.guild._state  # type: ignore
#         # sane values below, fresh messages which are commands should exhibit these.
#         self.call = None
#         self.type = discord.MessageType.default
#         self.tts = False
#         self.pinned = False
#         # suport for attachments somehow later maybe?
#         self.attachments: List[discord.Attachment] = []
#         # mentions
#         self.mention_everyone = self.channel.permissions_for(
#             self.author
#         ).mention_everyone and bool(EVERYONE_REGEX.match(self.content))
#         # pylint: disable=E1133
#         # pylint improperly detects the inherited properties here as not being iterable
#         # This should be fixed with typehint support added to upstream lib later
#         self.mentions: List[Union[discord.User, discord.Member]] = list(
#             filter(None, [self.guild.get_member(idx) for idx in self.raw_mentions])
#         )
#         self.channel_mentions: List[discord.TextChannel] = list(
#             filter(
#                 None,
#                 [
#                     self.guild.get_channel(idx)  # type: ignore
#                     for idx in self.raw_channel_mentions
#                 ],
#             )
#         )
#         self.role_mentions: List[discord.Role] = list(
#             filter(None, [self.guild.get_role(idx) for idx in self.raw_role_mentions])
#         )


# Path: scheduler/tasks.py
import contextlib
import attr
import discord
from datetime import datetime, timedelta, timezone
from typing import Optional, cast
from redbot.core.utils.chat_formatting import humanize_timedelta
from .message import SchedulerMessage

from __future__ import annotations





@attr.s(auto_attribs=True, slots=True)
class Task:
    nicename: str
    uid: str
    author: discord.Member
    content: str
    channel: discord.TextChannel
    initial: datetime
    recur: Optional[timedelta] = None
    extern_cog: Optional[str] = None

    def __attrs_post_init__(self):
        if self.initial.tzinfo is None:
            self.initial = self.initial.replace(tzinfo=timezone.utc)

    def __hash__(self):
        return hash(self.uid)

    async def get_message(self, bot):

        pfx = (await bot.get_prefix(self.channel))[0]
        content = f"{pfx}{self.content}"

        return SchedulerMessage(