|
@@ -30,50 +30,12 @@ from html2text import HTML2Text
|
|
|
import myanimebot.anilist as anilist
|
|
import myanimebot.anilist as anilist
|
|
|
import myanimebot.globals as globals
|
|
import myanimebot.globals as globals
|
|
|
import myanimebot.utils as utils
|
|
import myanimebot.utils as utils
|
|
|
|
|
+import myanimebot.myanimelist as myanimelist
|
|
|
|
|
|
|
|
if not sys.version_info[:2] >= (3, 7):
|
|
if not sys.version_info[:2] >= (3, 7):
|
|
|
print("ERROR: Requires python 3.7 or newer.")
|
|
print("ERROR: Requires python 3.7 or newer.")
|
|
|
exit(1)
|
|
exit(1)
|
|
|
|
|
|
|
|
-# TODO Create a Feed class instead of sending a lot of parameters
|
|
|
|
|
-def build_embed(user, item_title, item_link, item_description, pub_date, image, service: utils.Service):
|
|
|
|
|
- ''' Build the embed message related to the anime's status '''
|
|
|
|
|
-
|
|
|
|
|
- # Get service
|
|
|
|
|
- if service == utils.Service.MAL:
|
|
|
|
|
- service_name = 'MyAnimeList'
|
|
|
|
|
- profile_url = "{}{}".format(globals.MAL_PROFILE_URL, user)
|
|
|
|
|
- icon_url = globals.MAL_ICON_URL
|
|
|
|
|
- elif service == utils.Service.ANILIST:
|
|
|
|
|
- service_name = 'AniList'
|
|
|
|
|
- profile_url = "{}{}".format(globals.ANILIST_PROFILE_URL, user)
|
|
|
|
|
- icon_url = globals.ANILIST_ICON_URL
|
|
|
|
|
- else:
|
|
|
|
|
- raise NotImplementedError('Unknown service {}'.format(service))
|
|
|
|
|
- description = "[{}]({})\n```{}```".format(utils.filter_name(item_title), item_link, item_description)
|
|
|
|
|
- profile_url_label = "{}'s {}".format(user, service_name)
|
|
|
|
|
-
|
|
|
|
|
- try:
|
|
|
|
|
- embed = discord.Embed(colour=0xEED000, url=item_link, description=description, timestamp=pub_date.astimezone(pytz.timezone("utc")))
|
|
|
|
|
- embed.set_thumbnail(url=image)
|
|
|
|
|
- embed.set_author(name=profile_url_label, url=profile_url, icon_url=icon_url)
|
|
|
|
|
- embed.set_footer(text="MyAnimeBot", icon_url=globals.iconBot)
|
|
|
|
|
-
|
|
|
|
|
- return embed
|
|
|
|
|
- except Exception as e:
|
|
|
|
|
- globals.logger.error("Error when generating the message: " + str(e))
|
|
|
|
|
- return
|
|
|
|
|
-
|
|
|
|
|
-# Function used to send the embed
|
|
|
|
|
-async def send_embed_wrapper(asyncioloop, channelid, client, embed):
|
|
|
|
|
- channel = client.get_channel(int(channelid))
|
|
|
|
|
-
|
|
|
|
|
- try:
|
|
|
|
|
- await channel.send(embed=embed)
|
|
|
|
|
- globals.logger.info("Message sent in channel: " + channelid)
|
|
|
|
|
- except Exception as e:
|
|
|
|
|
- globals.logger.debug("Impossible to send a message on '" + channelid + "': " + str(e))
|
|
|
|
|
- return
|
|
|
|
|
|
|
|
|
|
# Main function that check the RSS feeds from MyAnimeList
|
|
# Main function that check the RSS feeds from MyAnimeList
|
|
|
async def background_check_feed(asyncioloop):
|
|
async def background_check_feed(asyncioloop):
|
|
@@ -145,7 +107,7 @@ async def background_check_feed(asyncioloop):
|
|
|
|
|
|
|
|
if data_img is None:
|
|
if data_img is None:
|
|
|
try:
|
|
try:
|
|
|
- image = utils.getThumbnail(item.link)
|
|
|
|
|
|
|
+ image = myanimelist.get_thumbnail(item.link)
|
|
|
|
|
|
|
|
globals.logger.info("First time seeing this " + media + ", adding thumbnail into database: " + image)
|
|
globals.logger.info("First time seeing this " + media + ", adding thumbnail into database: " + image)
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
@@ -167,7 +129,7 @@ async def background_check_feed(asyncioloop):
|
|
|
data_channel = db_srv.fetchone()
|
|
data_channel = db_srv.fetchone()
|
|
|
|
|
|
|
|
while data_channel is not None:
|
|
while data_channel is not None:
|
|
|
- for channel in data_channel: await send_embed_wrapper(asyncioloop, channel, globals.client, build_embed(user, item.title, item.link, item.description, pubDateRaw, image, utils.Service.MAL))
|
|
|
|
|
|
|
+ for channel in data_channel: await utils.send_embed_wrapper(asyncioloop, channel, globals.client, utils.build_embed(user, item.title, item.link, item.description, pubDateRaw, image, utils.Service.MAL))
|
|
|
|
|
|
|
|
data_channel = db_srv.fetchone()
|
|
data_channel = db_srv.fetchone()
|
|
|
if feed_type == 1:
|
|
if feed_type == 1:
|
|
@@ -576,7 +538,7 @@ async def update_thumbnail_catalog(asyncioloop):
|
|
|
|
|
|
|
|
if (reload == 1) :
|
|
if (reload == 1) :
|
|
|
try:
|
|
try:
|
|
|
- image = utils.getThumbnail(data[0])
|
|
|
|
|
|
|
+ image = myanimelist.get_thumbnail(data[0])
|
|
|
|
|
|
|
|
cursor.execute("UPDATE t_animes SET thumbnail = %s WHERE guid = %s", [image, data[0]])
|
|
cursor.execute("UPDATE t_animes SET thumbnail = %s WHERE guid = %s", [image, data[0]])
|
|
|
globals.conn.commit()
|
|
globals.conn.commit()
|