mirror of
https://github.com/brandons209/Red-bot-Cogs.git
synced 2024-09-28 07:11:47 +12:00
fucking black, work already
This commit is contained in:
parent
b00d00b370
commit
6c471cff24
1 changed files with 20 additions and 60 deletions
|
@ -44,19 +44,11 @@ class Birthdays(Cog):
|
||||||
BDAY_LIST_TITLE = _("Birthday List")
|
BDAY_LIST_TITLE = _("Birthday List")
|
||||||
|
|
||||||
# Even more constants
|
# Even more constants
|
||||||
BDAY_WITH_YEAR = _(
|
BDAY_WITH_YEAR = _("<@!{}> is now **{} years old**. <:aureliahappy:548738609763713035>")
|
||||||
"<@!{}> is now **{} years old**. <:aureliahappy:548738609763713035>"
|
BDAY_WITHOUT_YEAR = _("Everypony say Happy Hirthday to <@!{}>! <:aureliahappy:548738609763713035>")
|
||||||
)
|
ROLE_SET = _("<:aureliaagree:616091883013144586> The birthday role on **{g}** has been set to: **{r}**.")
|
||||||
BDAY_WITHOUT_YEAR = _(
|
|
||||||
"Everypony say Happy Hirthday to <@!{}>! <:aureliahappy:548738609763713035>"
|
|
||||||
)
|
|
||||||
ROLE_SET = _(
|
|
||||||
"<:aureliaagree:616091883013144586> The birthday role on **{g}** has been set to: **{r}**."
|
|
||||||
)
|
|
||||||
BDAY_INVALID = _(":x: The birthday date you entered is invalid.")
|
BDAY_INVALID = _(":x: The birthday date you entered is invalid.")
|
||||||
BDAY_SET = _(
|
BDAY_SET = _("<:aureliaagree:616091883013144586> Your birthday has been set to: **{}**.")
|
||||||
"<:aureliaagree:616091883013144586> Your birthday has been set to: **{}**."
|
|
||||||
)
|
|
||||||
CHANNEL_SET = _(
|
CHANNEL_SET = _(
|
||||||
"<:aureliaagree:616091883013144586> "
|
"<:aureliaagree:616091883013144586> "
|
||||||
"The channel for announcing birthdays on **{g}** has been set to: **{c}**."
|
"The channel for announcing birthdays on **{g}** has been set to: **{c}**."
|
||||||
|
@ -68,12 +60,7 @@ class Birthdays(Cog):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.logger = logging.getLogger("aurelia.cogs.birthdays")
|
self.logger = logging.getLogger("aurelia.cogs.birthdays")
|
||||||
unique_id = int(
|
unique_id = int(hashlib.sha512((self.__author__ + "@" + self.__class__.__name__).encode()).hexdigest(), 16,)
|
||||||
hashlib.sha512(
|
|
||||||
(self.__author__ + "@" + self.__class__.__name__).encode()
|
|
||||||
).hexdigest(),
|
|
||||||
16,
|
|
||||||
)
|
|
||||||
self.config = Config.get_conf(self, identifier=unique_id)
|
self.config = Config.get_conf(self, identifier=unique_id)
|
||||||
self.config.init_custom(self.DATE_GROUP, 1)
|
self.config.init_custom(self.DATE_GROUP, 1)
|
||||||
self.config.init_custom(self.GUILD_DATE_GROUP, 2)
|
self.config.init_custom(self.GUILD_DATE_GROUP, 2)
|
||||||
|
@ -87,9 +74,7 @@ class Birthdays(Cog):
|
||||||
with contextlib.suppress(RuntimeError):
|
with contextlib.suppress(RuntimeError):
|
||||||
while self == self.bot.get_cog(self.__class__.__name__):
|
while self == self.bot.get_cog(self.__class__.__name__):
|
||||||
now = datetime.datetime.utcnow()
|
now = datetime.datetime.utcnow()
|
||||||
tomorrow = (now + datetime.timedelta(days=1)).replace(
|
tomorrow = (now + datetime.timedelta(days=1)).replace(hour=0, minute=0, second=0, microsecond=0)
|
||||||
hour=0, minute=0, second=0, microsecond=0
|
|
||||||
)
|
|
||||||
await self.clean_yesterday_bdays()
|
await self.clean_yesterday_bdays()
|
||||||
await self.do_today_bdays()
|
await self.do_today_bdays()
|
||||||
await asyncio.sleep((tomorrow - now).total_seconds())
|
await asyncio.sleep((tomorrow - now).total_seconds())
|
||||||
|
@ -150,9 +135,7 @@ class Birthdays(Cog):
|
||||||
year = birthday.year
|
year = birthday.year
|
||||||
birthday = datetime.date(1, birthday.month, birthday.day)
|
birthday = datetime.date(1, birthday.month, birthday.day)
|
||||||
await self.remove_user_bday(message.guild.id, author.id)
|
await self.remove_user_bday(message.guild.id, author.id)
|
||||||
await self.get_date_config(message.guild.id, birthday.toordinal()).get_attr(
|
await self.get_date_config(message.guild.id, birthday.toordinal()).get_attr(author.id).set(year)
|
||||||
author.id
|
|
||||||
).set(year)
|
|
||||||
bday_month_str = birthday.strftime("%B")
|
bday_month_str = birthday.strftime("%B")
|
||||||
bday_day_str = birthday.strftime("%d").lstrip("0")
|
bday_day_str = birthday.strftime("%d").lstrip("0")
|
||||||
|
|
||||||
|
@ -167,20 +150,16 @@ class Birthdays(Cog):
|
||||||
await self.clean_bdays()
|
await self.clean_bdays()
|
||||||
bdays = await self.get_guild_date_configs(message.guild.id)
|
bdays = await self.get_guild_date_configs(message.guild.id)
|
||||||
this_year = datetime.date.today().year
|
this_year = datetime.date.today().year
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(title=self.BDAY_LIST_TITLE(), color=discord.Colour.lighter_grey())
|
||||||
title=self.BDAY_LIST_TITLE(), color=discord.Colour.lighter_grey()
|
|
||||||
)
|
|
||||||
for k, g in itertools.groupby(
|
for k, g in itertools.groupby(
|
||||||
sorted(datetime.datetime.fromordinal(int(o)) for o in bdays.keys()),
|
sorted(datetime.datetime.fromordinal(int(o)) for o in bdays.keys()), lambda i: i.month,
|
||||||
lambda i: i.month,
|
|
||||||
):
|
):
|
||||||
|
|
||||||
value = "\n".join(
|
value = "\n".join(
|
||||||
date.strftime("%d").lstrip("0")
|
date.strftime("%d").lstrip("0")
|
||||||
+ ": "
|
+ ": "
|
||||||
+ ", ".join(
|
+ ", ".join(
|
||||||
"<@!{}>".format(u_id)
|
"<@!{}>".format(u_id) + ("" if year is None else " ({})".format(this_year - int(year)))
|
||||||
+ ("" if year is None else " ({})".format(this_year - int(year)))
|
|
||||||
for u_id, year in bdays.get(str(date.toordinal()), {}).items()
|
for u_id, year in bdays.get(str(date.toordinal()), {}).items()
|
||||||
)
|
)
|
||||||
for date in g
|
for date in g
|
||||||
|
@ -188,8 +167,7 @@ class Birthdays(Cog):
|
||||||
)
|
)
|
||||||
if not value.isspace():
|
if not value.isspace():
|
||||||
embed.add_field(
|
embed.add_field(
|
||||||
name=datetime.datetime(year=1, month=k, day=1).strftime("%B"),
|
name=datetime.datetime(year=1, month=k, day=1).strftime("%B"), value=value,
|
||||||
value=value,
|
|
||||||
)
|
)
|
||||||
await message.channel.send(embed=embed)
|
await message.channel.send(embed=embed)
|
||||||
|
|
||||||
|
@ -226,9 +204,7 @@ class Birthdays(Cog):
|
||||||
except (discord.Forbidden, discord.HTTPException):
|
except (discord.Forbidden, discord.HTTPException):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
async with self.config.guild(
|
async with self.config.guild(guild).yesterdays() as yesterdays:
|
||||||
guild
|
|
||||||
).yesterdays() as yesterdays:
|
|
||||||
yesterdays.append(member.id)
|
yesterdays.append(member.id)
|
||||||
channel = guild.get_channel(guild_config.get("channel"))
|
channel = guild.get_channel(guild_config.get("channel"))
|
||||||
if channel is not None:
|
if channel is not None:
|
||||||
|
@ -240,12 +216,8 @@ class Birthdays(Cog):
|
||||||
for guild_id, guild_bdays in birthdays.items():
|
for guild_id, guild_bdays in birthdays.items():
|
||||||
for date, bdays in guild_bdays.items():
|
for date, bdays in guild_bdays.items():
|
||||||
for user_id, year in bdays.items():
|
for user_id, year in bdays.items():
|
||||||
if not any(
|
if not any(g.get_member(int(user_id)) is not None for g in self.bot.guilds):
|
||||||
g.get_member(int(user_id)) is not None for g in self.bot.guilds
|
async with self.get_date_config(guild_id, date)() as config_bdays:
|
||||||
):
|
|
||||||
async with self.get_date_config(
|
|
||||||
guild_id, date
|
|
||||||
)() as config_bdays:
|
|
||||||
del config_bdays[user_id]
|
del config_bdays[user_id]
|
||||||
config_bdays = await self.get_date_config(guild_id, date)()
|
config_bdays = await self.get_date_config(guild_id, date)()
|
||||||
if len(config_bdays) == 0:
|
if len(config_bdays) == 0:
|
||||||
|
@ -263,9 +235,7 @@ class Birthdays(Cog):
|
||||||
for guild_id, guild_config in all_guild_configs.items():
|
for guild_id, guild_config in all_guild_configs.items():
|
||||||
for user_id in guild_config.get("yesterdays", []):
|
for user_id in guild_config.get("yesterdays", []):
|
||||||
asyncio.ensure_future(self.clean_bday(guild_id, guild_config, user_id))
|
asyncio.ensure_future(self.clean_bday(guild_id, guild_config, user_id))
|
||||||
await self.config.guild(
|
await self.config.guild(discord.Guild(data={"id": guild_id}, state=None)).yesterdays.clear()
|
||||||
discord.Guild(data={"id": guild_id}, state=None)
|
|
||||||
).yesterdays.clear()
|
|
||||||
|
|
||||||
async def do_today_bdays(self):
|
async def do_today_bdays(self):
|
||||||
guild_configs = await self.get_all_date_configs()
|
guild_configs = await self.get_all_date_configs()
|
||||||
|
@ -295,19 +265,11 @@ class Birthdays(Cog):
|
||||||
await self.config.custom(self.DATE_GROUP).clear()
|
await self.config.custom(self.DATE_GROUP).clear()
|
||||||
owner = self.bot.get_user(self.bot.owner_id)
|
owner = self.bot.get_user(self.bot.owner_id)
|
||||||
if len(self.bot.guilds) == 1:
|
if len(self.bot.guilds) == 1:
|
||||||
await self.get_guild_date_config(self.bot.guilds[0].id).set_raw(
|
await self.get_guild_date_config(self.bot.guilds[0].id).set_raw(value=previous)
|
||||||
value=previous
|
self.logger.info("Birthdays are now per-guild. Previous birthdays have been copied.")
|
||||||
)
|
|
||||||
self.logger.info(
|
|
||||||
"Birthdays are now per-guild. Previous birthdays have been copied."
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
await self.config.custom(self.GUILD_DATE_GROUP, "backup").set_raw(
|
await self.config.custom(self.GUILD_DATE_GROUP, "backup").set_raw(value=previous)
|
||||||
value=previous
|
self.logger.info("Previous birthdays have been backed up in the config file.")
|
||||||
)
|
|
||||||
self.logger.info(
|
|
||||||
"Previous birthdays have been backed up in the config file."
|
|
||||||
)
|
|
||||||
|
|
||||||
def get_date_config(self, guild_id: int, date: int):
|
def get_date_config(self, guild_id: int, date: int):
|
||||||
return self.config.custom(self.GUILD_DATE_GROUP, str(guild_id), str(date))
|
return self.config.custom(self.GUILD_DATE_GROUP, str(guild_id), str(date))
|
||||||
|
@ -315,9 +277,7 @@ class Birthdays(Cog):
|
||||||
def get_guild_date_config(self, guild_id: int):
|
def get_guild_date_config(self, guild_id: int):
|
||||||
return self.config.custom(self.GUILD_DATE_GROUP, str(guild_id))
|
return self.config.custom(self.GUILD_DATE_GROUP, str(guild_id))
|
||||||
|
|
||||||
async def get_guild_date_configs(
|
async def get_guild_date_configs(self, guild_id: int) -> _ValueCtxManager[Dict[str, Any]]:
|
||||||
self, guild_id: int
|
|
||||||
) -> _ValueCtxManager[Dict[str, Any]]:
|
|
||||||
return await self.get_guild_date_config(guild_id).all()
|
return await self.get_guild_date_config(guild_id).all()
|
||||||
|
|
||||||
def get_all_date_configs(self):
|
def get_all_date_configs(self):
|
||||||
|
|
Loading…
Reference in a new issue