Kaynağa Gözat

Added status color to the embed

Penta 5 yıl önce
ebeveyn
işleme
e31183a12d
3 değiştirilmiş dosya ile 35 ekleme ve 34 silme
  1. 25 25
      myanimebot/discord.py
  2. 3 3
      myanimebot/myanimelist.py
  3. 7 6
      myanimebot/utils.py

+ 25 - 25
myanimebot/discord.py

@@ -6,33 +6,33 @@ import myanimebot.utils as utils
 
 
 def build_embed(feed : utils.Feed):
-	''' Build the embed message related to the anime's status '''
+    ''' Build the embed message related to the anime's status '''
 
-	# Get service
-	if feed.service == utils.Service.MAL:
-		service_name = 'MyAnimeList'
-		profile_url = "{}{}".format(globals.MAL_PROFILE_URL, feed.user.name)
-		icon_url = globals.MAL_ICON_URL
-	elif feed.service == utils.Service.ANILIST:
-		service_name = 'AniList'
-		profile_url = "{}{}".format(globals.ANILIST_PROFILE_URL, feed.user.name)
-		icon_url = globals.ANILIST_ICON_URL
-	else:
-		raise NotImplementedError('Unknown service {}'.format(feed.service))
-	description = utils.build_description_string(feed)
-	content = "[{}]({})\n```{}```".format(utils.filter_name(feed.media.name), feed.media.url, description)
-	profile_url_label = "{}'s {}".format(feed.user.name, service_name)
+    # Get service
+    if feed.service == utils.Service.MAL:
+        service_name = 'MyAnimeList'
+        profile_url = "{}{}".format(globals.MAL_PROFILE_URL, feed.user.name)
+        icon_url = globals.MAL_ICON_URL
+    elif feed.service == utils.Service.ANILIST:
+        service_name = 'AniList'
+        profile_url = "{}{}".format(globals.ANILIST_PROFILE_URL, feed.user.name)
+        icon_url = globals.ANILIST_ICON_URL
+    else:
+        raise NotImplementedError('Unknown service {}'.format(feed.service))
+    description = utils.build_description_string(feed)
+    content = "[{}]({})\n```{}```".format(utils.filter_name(feed.media.name), feed.media.url, description)
+    profile_url_label = "{}'s {}".format(feed.user.name, service_name)
 
-	try:	
-		embed = discord.Embed(colour=0xEED000, url=feed.media.url, description=content, timestamp=feed.date_publication.astimezone(pytz.timezone("utc")))
-		embed.set_thumbnail(url=feed.media.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
+    try:
+        embed = discord.Embed(colour=int(feed.status.value, 16), url=feed.media.url, description=content, timestamp=feed.date_publication.astimezone(pytz.timezone("utc")))
+        embed.set_thumbnail(url=feed.media.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
 
 
 async def send_embed_wrapper(asyncioloop, channelid, client, embed):

+ 3 - 3
myanimebot/myanimelist.py

@@ -11,12 +11,12 @@ def get_thumbnail(urlParam):
     ''' Returns the MAL media thumbnail from a link '''
 
     url = "/".join((urlParam).split("/")[:5])
-	
+
     websource = urllib.request.urlopen(url)
     soup = BeautifulSoup(websource.read(), "html.parser")
     image = re.search(r'(?P<url>https?://[^\s]+)', str(soup.find("img", {"itemprop": "image"}))).group("url")
     thumbnail = "".join(image.split('"')[:1]).replace('"','')
-	
+
     return thumbnail
 
 
@@ -27,7 +27,7 @@ def build_feed_from_data(data, user : utils.User, image, pubDateRaw, type : util
         if type == utils.MediaType.MANGA:
             data.description = "Re-reading " + data.description
         else:
-            data.description = "Re-watching " + data.description								
+            data.description = "Re-watching " + data.description
 
     status, progress, episodes = break_rss_description_string(data.description)
 

+ 7 - 6
myanimebot/utils.py

@@ -8,12 +8,12 @@ import myanimebot.globals as globals
 # TODO Redo all of the desc/status system
 
 # Media Status colors
-CURRENT_COLOR     = "0x00FF00"
-PLANNING_COLOR    = "0xBFBFBF"
-COMPLETED_COLOR   = "0c0000FF"
-DROPPED_COLOR     = "0xFF0000"
-PAUSED_COLOR      = "0xFFFF00"
-REPEATING_COLOR   = "0x008000"
+CURRENT_COLOR     = "00CC00"
+PLANNING_COLOR    = "BFBFBF"
+COMPLETED_COLOR   = "0000CC"
+DROPPED_COLOR     = "CC0000"
+PAUSED_COLOR      = "DDDD00"
+REPEATING_COLOR   = "007700"
 
 
 class Service(Enum):
@@ -351,6 +351,7 @@ def insert_user_into_db(user_name : str, service : Service, servers : str) -> bo
 
 def get_allowed_role(server : int) -> int:
     '''Return the allowed role for a given server'''
+
     cursor = globals.conn.cursor(buffered=True)
     cursor.execute("SELECT admin_group FROM t_servers WHERE server=%s LIMIT 1", [str(server)])
     allowedRole = cursor.fetchone()