Skip to content

Commit

Permalink
Fixed update_check not working
Browse files Browse the repository at this point in the history
  • Loading branch information
MooshiMochi committed Feb 17, 2024
1 parent e90eaaa commit 1e250f4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 29 deletions.
6 changes: 4 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import asyncio
import logging
import os
import sys

from aiohttp import ClientConnectorError
from discord import Intents
Expand Down Expand Up @@ -107,11 +106,14 @@ async def main():


if __name__ == "__main__":
import sys

try:
if os.name == "nt" and sys.version_info >= (3, 8):
import tracemalloc

asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
if sys.gettrace() is None:
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
tracemalloc.start()

asyncio.run(main())
Expand Down
6 changes: 3 additions & 3 deletions src/core/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,11 @@ async def log_command_usage(self, interaction: discord.Interaction) -> None:
fmt_opts = f'\n{spc}'.join(options_list)
_author_text = f"[ Author ] > {user}"
if interaction.guild_id is not None:
_guild_text = f"[ Guild ] > {interaction.guild.name} ({interaction.guild_id})"
_guild_text = f"[ Guild ] > {interaction.guild.name} ({interaction.guild_id})"
else:
_guild_text = "[ Guild ] > DM Channel"
_guild_text = "[ Guild ] > DM Channel"
_cmd_text = f"[ Command ] > /{cmd_name}"
pretty_msg = f"```\n{_author_text}\n{_guild_text}\n{_cmd_text}```"
pretty_msg = f"```\n{_guild_text}\n{_author_text}\n{_cmd_text}```"
cmd_log_channel_id = self._config["constants"].get("command-log-channel-id")
cmd_log = f"[Command: {user}] > /{cmd_name}"
if fmt_opts:
Expand Down
2 changes: 1 addition & 1 deletion src/core/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ async def get_series_to_update(self) -> list[MangaHeader] | None:
UNION
SELECT series_id, scanlator FROM tracked_guild_series
)
AND scanlator NOT IN (SELECT scanlator FROM scanlators_config WHERE enabled = 0)
AND scanlator IN (SELECT scanlator FROM scanlators_config WHERE enabled = true)
AND lower(status) NOT IN ({completed_db_set});
"""
) as cursor:
Expand Down
26 changes: 13 additions & 13 deletions src/core/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,11 @@ def __str__(self):
return f"[{self.title}]({self._url})"

def __eq__(self, other: Manga):
return isinstance(other, (Manga, PartialManga)) and (
self.url == other.url and
self.title == other.title or
self.id == other.id and
self.scanlator == other.scanlator
)
return (
isinstance(other, (Manga, PartialManga)) and self.url == other.url and self.title == other.title
or
isinstance(other, MangaHeader)
) and self.id == other.id and self.scanlator == other.scanlator

@property
def id(self):
Expand Down Expand Up @@ -394,12 +393,11 @@ def __str__(self) -> str:
return f"[{self.title}]({self.url})"

def __eq__(self, other: Manga):
return isinstance(other, (Manga, PartialManga)) and (
self.url == other.url and
self.title == other.title or
self.id == other.id and
self.scanlator == other.scanlator
)
return (
isinstance(other, (Manga, PartialManga)) and self.url == other.url and self.title == other.title
or
isinstance(other, MangaHeader)
) and self.id == other.id and self.scanlator == other.scanlator


class Bookmark:
Expand Down Expand Up @@ -719,4 +717,6 @@ class MangaHeader:
scanlator: str

def __eq__(self, other: Manga | MangaHeader) -> bool:
return isinstance(other, MangaHeader) and self.id == other.id and self.scanlator == other.scanlator
return isinstance(
other, (MangaHeader, PartialManga, Manga)
) and self.id == other.id and self.scanlator == other.scanlator
20 changes: 10 additions & 10 deletions src/ext/update_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async def handle_exception(self, coro: callable, scanlator: AbstractScanlator, r
Parameters:
coro: The coroutine that was called.
scanlator: The scanner that was used to check for updates.
scanlator: The scanner used to check for updates.
req_url: The URL that was requested.
Returns:
Expand Down Expand Up @@ -169,7 +169,7 @@ async def check_with_front_page_scraping(
"""
Summary:
Checks for updates by scraping the front page of the scanlator's website.
If the scanlator doesn't support front page scraping, it will return back all the manga that were passed in.
If the scanlator doesn't support front page scraping, it will return all the manga passed in.
Otherwise, it may return a combination of Manga and ChapterUpdate objects.
Args:
Expand Down Expand Up @@ -317,13 +317,12 @@ async def send_notifications(self, chapter_updates: list[ChapterUpdate]) -> None
f"Failed to send update for {manga_title}| {chapter.name} to {user}", exc_info=e
)
next_update_ts = int(self.check_updates_task.next_iteration.timestamp())
await user.send(
embed=(
discord.Embed(
description=f"The next update check will be <t:{next_update_ts}:R> at <t:{next_update_ts}:T>")
).set_footer(text=self.bot.user.display_name, icon_url=self.bot.user.display_avatar.url),
delete_after=25 * 60 # 25 min
)
next_update_em = (
discord.Embed(
description=f"The next update check will be <t:{next_update_ts}:R> at <t:{next_update_ts}:T>")
).set_footer(text=self.bot.user.display_name, icon_url=self.bot.user.display_avatar.url)

await user.send(embed=next_update_em, delete_after=25 * 60) # 25 min
except discord.Forbidden: # DMs are closed
self.logger.warning(f"Failed to send update to {user} because DMs are closed!")

Expand Down Expand Up @@ -539,6 +538,7 @@ async def check_updates_task(self):
try:
# change this to grab ID|scanlator only
series_to_update: list[MangaHeader] = await self.bot.db.get_series_to_update()
print(series_to_update)
if not series_to_update:
return

Expand Down Expand Up @@ -624,7 +624,7 @@ async def check_patreon_users(self) -> None:
try:
while True:
pledge_response = await asyncio.to_thread(api_client.fetch_page_of_pledges,
CAMPAIGN_ID, 2, cursor
CAMPAIGN_ID, 2, cursor, None, None
)
all_pledges += pledge_response.data()
cursor = api_client.extract_cursor(pledge_response)
Expand Down

0 comments on commit 1e250f4

Please sign in to comment.