diff --git a/database/models.py b/database/models.py index 69d9ebc..212a6b1 100644 --- a/database/models.py +++ b/database/models.py @@ -93,3 +93,13 @@ class DiscordInvite(db.Model): revoked = db.Column(db.Boolean, default=False) last_sync = db.Column(db.DateTime) +class YoutubeAlert(db.Model): + __tablename__ = 'youtube_alert' + id = db.Column(db.Integer, primary_key=True) + enable = db.Column(db.Boolean, default=True) + channel_id = db.Column(db.String(64), unique=True) + channel_name = db.Column(db.String(256)) + notify_channel = db.Column(db.Integer) + message = db.Column(db.String(2000)) + last_video_id = db.Column(db.String(64)) + diff --git a/database/schema.sql b/database/schema.sql index 070c277..2af931f 100644 --- a/database/schema.sql +++ b/database/schema.sql @@ -108,3 +108,13 @@ CREATE TABLE IF NOT EXISTS `discord_invite` ( `revoked` BOOLEAN NOT NULL DEFAULT FALSE, `last_sync` DATETIME NOT NULL ); + +CREATE TABLE IF NOT EXISTS `youtube_alert` ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + `enable` BOOLEAN NOT NULL DEFAULT TRUE, + `channel_id` VARCHAR(64) UNIQUE NOT NULL, + `channel_name` VARCHAR(256), + `notify_channel` INTEGER NOT NULL, + `message` VARCHAR(2000) NOT NULL, + `last_video_id` VARCHAR(64) +); diff --git a/discordbot/__init__.py b/discordbot/__init__.py index 6a6daa4..8a56124 100644 --- a/discordbot/__init__.py +++ b/discordbot/__init__.py @@ -49,6 +49,7 @@ class DiscordBot(discord.Client): self.loop.create_task(self.updateStatus()) self.loop.create_task(self.updateHumbleBundle()) self.loop.create_task(self.updateFreeGames()) + self.loop.create_task(self.updateYoutubeAlerts()) self.loop.create_task(self._periodic_stats_update()) def _update_shared_stats(self): @@ -115,6 +116,12 @@ class DiscordBot(discord.Client): await checkFreeGamesAndNotify(self) await asyncio.sleep(60*60) # Vérification toutes les heures + async def updateYoutubeAlerts(self): + from youtubebot.youtube_alert import checkNewVideos + while not self.is_closed(): + await checkNewVideos(self) + await asyncio.sleep(10*60) # Vérification toutes les 10 minutes + def getAllTextChannel(self) -> list[TextChannel]: channels = [] for channel in self.get_all_channels(): diff --git a/webapp/__init__.py b/webapp/__init__.py index 173be9b..60955f8 100644 --- a/webapp/__init__.py +++ b/webapp/__init__.py @@ -4,4 +4,4 @@ import os webapp = Flask(__name__) webapp.secret_key = os.environ.get('FLASK_SECRET_KEY', 'mamie-henriette-secret-key-change-me') -from webapp import commandes, configurations, index, humeurs, protondb, live_alert, twitch_auth, moderation, freegames +from webapp import commandes, configurations, index, humeurs, protondb, live_alert, twitch_auth, moderation, freegames, youtube_alert diff --git a/webapp/static/css/style.css b/webapp/static/css/style.css index 37f6d21..aee903d 100644 --- a/webapp/static/css/style.css +++ b/webapp/static/css/style.css @@ -543,7 +543,8 @@ table tbody tr:hover { background: var(--accent-soft); } -table.live-alert tr td:last-child { +table.live-alert tr td:last-child, +table.youtube-alert tr td:last-child { white-space: nowrap; } diff --git a/webapp/templates/template.html b/webapp/templates/template.html index a606a2b..93ca3f7 100644 --- a/webapp/templates/template.html +++ b/webapp/templates/template.html @@ -45,6 +45,12 @@
  • 📺 Alerte Live
  • +
  • + YouTube + +
  • Outils