You've already forked JapariArchive
38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
from __future__ import annotations
|
|
import traceback
|
|
from typing import TYPE_CHECKING
|
|
|
|
import nextcord
|
|
|
|
from Discord import discordHelper
|
|
from config import Global_Config
|
|
if TYPE_CHECKING:
|
|
from runtimeBotData import RuntimeBotData
|
|
|
|
async def download_loop(botData: RuntimeBotData):
|
|
try:
|
|
db = botData.db
|
|
guild = botData.client.guilds[0]
|
|
|
|
new_posts = await botData.pixivApi.get_new_posts(botData)
|
|
new_posts.sort(key= lambda x: x.id)
|
|
|
|
for post in new_posts:
|
|
media = (await botData.pixivApi.download_illust(post, Global_Config["pixiv_download_path"]))[:4]
|
|
if post.x_restrict == 0:
|
|
channel = nextcord.utils.get(guild.channels, name="pixiv-sfw-feed")
|
|
elif post.x_restrict == 1:
|
|
channel = nextcord.utils.get(guild.channels, name="pixiv-r18-feed")
|
|
else:
|
|
channel = nextcord.utils.get(guild.channels, name="pixiv-r18g-feed")
|
|
await discordHelper.send_pixiv_post(post, media, channel)
|
|
|
|
if db.pixiv_get_user(post.user.id) == None:
|
|
db.pixiv_insert_user(post.user)
|
|
db.pixiv_insert_post(post)
|
|
|
|
except Exception as ex:
|
|
print(ex)
|
|
await discordHelper.send_error(traceback.format_exc()[0:256], botData)
|
|
print("Pixiv done")
|