aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Leon Sandøy <[email protected]>2019-06-29 00:25:36 +0200
committerGravatar GitHub <[email protected]>2019-06-29 00:25:36 +0200
commitf968fd30ebf2d9f3b54a936c226b72c75f42ce23 (patch)
tree2082eb7f5badc934e599816846c0d8c99071ab2c
parentEmpty commit to trigger redeployment (diff)
parentRemove str vs Sequence checking (diff)
Merge pull request #230 from Suhail6inkling/icon_rotate
Cycle Evergreen Animated Server Icons
-rw-r--r--bot/seasons/christmas/__init__.py4
-rw-r--r--bot/seasons/easter/__init__.py4
-rw-r--r--bot/seasons/evergreen/__init__.py6
-rw-r--r--bot/seasons/halloween/__init__.py4
-rw-r--r--bot/seasons/pride/__init__.py4
-rw-r--r--bot/seasons/season.py60
-rw-r--r--bot/seasons/valentines/__init__.py4
7 files changed, 64 insertions, 22 deletions
diff --git a/bot/seasons/christmas/__init__.py b/bot/seasons/christmas/__init__.py
index f0a7c2c6..239181f4 100644
--- a/bot/seasons/christmas/__init__.py
+++ b/bot/seasons/christmas/__init__.py
@@ -21,4 +21,6 @@ class Christmas(SeasonBase):
end_date = "31/12"
colour = Colours.dark_green
- icon = "/logos/logo_seasonal/christmas/festive.png"
+ icon = (
+ "/logos/logo_seasonal/christmas/festive.png",
+ )
diff --git a/bot/seasons/easter/__init__.py b/bot/seasons/easter/__init__.py
index 83d12ead..1d77b6a6 100644
--- a/bot/seasons/easter/__init__.py
+++ b/bot/seasons/easter/__init__.py
@@ -30,4 +30,6 @@ class Easter(SeasonBase):
end_date = "30/04"
colour = Colours.pink
- icon = "/logos/logo_seasonal/easter/easter.png"
+ icon = (
+ "/logos/logo_seasonal/easter/easter.png",
+ )
diff --git a/bot/seasons/evergreen/__init__.py b/bot/seasons/evergreen/__init__.py
index ac32c199..b95f3528 100644
--- a/bot/seasons/evergreen/__init__.py
+++ b/bot/seasons/evergreen/__init__.py
@@ -5,3 +5,9 @@ class Evergreen(SeasonBase):
"""Evergreen Seasonal event attributes."""
bot_icon = "/logos/logo_seasonal/evergreen/logo_evergreen.png"
+ icon = (
+ "/logos/logo_animated/heartbeat/heartbeat.gif",
+ "/logos/logo_animated/spinner/spinner.gif",
+ "/logos/logo_animated/tongues/tongues.gif",
+ "/logos/logo_animated/winky/winky.gif",
+ )
diff --git a/bot/seasons/halloween/__init__.py b/bot/seasons/halloween/__init__.py
index 74c962ed..aff51423 100644
--- a/bot/seasons/halloween/__init__.py
+++ b/bot/seasons/halloween/__init__.py
@@ -13,4 +13,6 @@ class Halloween(SeasonBase):
end_date = "31/10"
colour = Colours.orange
- icon = "/logos/logo_seasonal/halloween/spooky.png"
+ icon = (
+ "/logos/logo_seasonal/halloween/spooky.png",
+ )
diff --git a/bot/seasons/pride/__init__.py b/bot/seasons/pride/__init__.py
index 434e3409..b1897eca 100644
--- a/bot/seasons/pride/__init__.py
+++ b/bot/seasons/pride/__init__.py
@@ -31,4 +31,6 @@ class Pride(SeasonBase):
# Season logo
colour = Colours.soft_red
- icon = "/logos/logo_seasonal/pride/logo_pride.png"
+ icon = (
+ "/logos/logo_seasonal/pride/logo_pride.png",
+ )
diff --git a/bot/seasons/season.py b/bot/seasons/season.py
index cd2306a6..71324127 100644
--- a/bot/seasons/season.py
+++ b/bot/seasons/season.py
@@ -6,7 +6,7 @@ import inspect
import logging
import pkgutil
from pathlib import Path
-from typing import List, Optional, Type, Union
+from typing import List, Optional, Tuple, Type, Union
import async_timeout
import discord
@@ -80,11 +80,13 @@ class SeasonBase:
end_date: Optional[str] = None
colour: Optional[int] = None
- icon: str = "/logos/logo_full/logo_full.png"
+ icon: Tuple[str, ...] = ("/logos/logo_full/logo_full.png",)
bot_icon: Optional[str] = None
date_format: str = "%d/%m/%Y"
+ index: int = 0
+
@staticmethod
def current_year() -> int:
"""Returns the current year."""
@@ -132,24 +134,26 @@ class SeasonBase:
"""
return f"New Season, {self.name_clean}!"
- async def get_icon(self, avatar: bool = False) -> bytes:
+ async def get_icon(self, avatar: bool = False, index: int = 0) -> Tuple[bytes, str]:
"""
Retrieve the season's icon from the branding repository using the Season's icon attribute.
+ This also returns the relative URL path for logging purposes
If `avatar` is True, uses optional bot-only avatar icon if present.
+ Returns the data for the given `index`, defaulting to the first item.
The icon attribute must provide the url path, starting from the master branch base url,
including the starting slash.
e.g. `/logos/logo_seasonal/valentines/loved_up.png`
"""
- if avatar:
- icon = self.bot_icon or self.icon
- else:
- icon = self.icon
+ icon = self.icon[index]
+ if avatar and self.bot_icon:
+ icon = self.bot_icon
+
full_url = ICON_BASE_URL + icon
log.debug(f"Getting icon from: {full_url}")
async with bot.http_session.get(full_url) as resp:
- return await resp.read()
+ return (await resp.read(), icon)
async def apply_username(self, *, debug: bool = False) -> Union[bool, None]:
"""
@@ -202,17 +206,17 @@ class SeasonBase:
old_avatar = bot.user.avatar
# Attempt the change
- log.debug(f"Changing avatar to {self.bot_icon or self.icon}")
- icon = await self.get_icon(avatar=True)
+ icon, name = await self.get_icon(avatar=True)
+ log.debug(f"Changing avatar to {name}")
with contextlib.suppress(discord.HTTPException, asyncio.TimeoutError):
async with async_timeout.timeout(5):
await bot.user.edit(avatar=icon)
if bot.user.avatar != old_avatar:
- log.debug(f"Avatar changed to {self.bot_icon or self.icon}")
+ log.debug(f"Avatar changed to {name}")
return True
- log.warning(f"Changing avatar failed: {self.bot_icon or self.icon}")
+ log.warning(f"Changing avatar failed: {name}")
return False
async def apply_server_icon(self) -> bool:
@@ -227,20 +231,38 @@ class SeasonBase:
old_icon = guild.icon
# Attempt the change
- log.debug(f"Changing server icon to {self.icon}")
- icon = await self.get_icon()
+
+ icon, name = await self.get_icon(index=self.index)
+
+ log.debug(f"Changing server icon to {name}")
+
with contextlib.suppress(discord.HTTPException, asyncio.TimeoutError):
async with async_timeout.timeout(5):
await guild.edit(icon=icon, reason=f"Seasonbot Season Change: {self.name}")
new_icon = bot.get_guild(Client.guild).icon
if new_icon != old_icon:
- log.debug(f"Server icon changed to {self.icon}")
+ log.debug(f"Server icon changed to {name}")
return True
- log.warning(f"Changing server icon failed: {self.icon}")
+ log.warning(f"Changing server icon failed: {name}")
return False
+ async def change_server_icon(self) -> bool:
+ """
+ Changes the server icon.
+
+ This only has an effect when the Season's icon attribute is a list, in which it cycles through.
+ Returns True if was successful.
+ """
+ if len(self.icon) == 1:
+ return
+
+ self.index += 1
+ self.index %= len(self.icon)
+
+ return await self.apply_server_icon()
+
async def announce_season(self):
"""
Announces a change in season in the announcement channel.
@@ -268,7 +290,7 @@ class SeasonBase:
embed.set_author(name=self.greeting)
if self.icon:
- embed.set_image(url=ICON_BASE_URL+self.icon)
+ embed.set_image(url=ICON_BASE_URL+self.icon[0])
# Find any seasonal commands
cogs = []
@@ -303,6 +325,7 @@ class SeasonBase:
If in debug mode, the avatar, server icon, and announcement will be skipped.
"""
+ self.index = 0
# Prepare all the seasonal cogs, and then the evergreen ones.
extensions = []
for ext_folder in {self.name, "evergreen"}:
@@ -366,7 +389,10 @@ class SeasonManager(commands.Cog):
# If the season has changed, load it.
new_season = get_season(date=datetime.datetime.utcnow())
if new_season.name != self.season.name:
+ self.season = new_season
await self.season.load()
+ else:
+ await self.season.change_server_icon()
@with_role(Roles.moderator, Roles.admin, Roles.owner)
@commands.command(name="season")
diff --git a/bot/seasons/valentines/__init__.py b/bot/seasons/valentines/__init__.py
index e3e04421..6e5d16f7 100644
--- a/bot/seasons/valentines/__init__.py
+++ b/bot/seasons/valentines/__init__.py
@@ -17,4 +17,6 @@ class Valentines(SeasonBase):
end_date = "01/03"
colour = Colours.pink
- icon = "/logos/logo_seasonal/valentines/loved_up.png"
+ icon = (
+ "/logos/logo_seasonal/valentines/loved_up.png",
+ )