From ab31249100587ef0baf241c20c8f11508063d83b Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 6 Nov 2018 23:11:35 +0100 Subject: [PATCH] possible new page --- discordbot.py | 21 +++++++++++++++------ query_discord_music.py | 13 ++++++++++++- templates/topsongs.html | 27 +++++++++++++++++++++++++++ webserver.py | 26 ++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 7 deletions(-) create mode 100644 templates/topsongs.html diff --git a/discordbot.py b/discordbot.py index df0cdaa3..b4a0a9d9 100644 --- a/discordbot.py +++ b/discordbot.py @@ -69,7 +69,7 @@ song_special_messages = { "updog": ":arrow_forward: What's up, dog? {song}!", "sayo-nara": ":arrow_forward: I gently open the door. {song} awaits me inside.", "monika": ":arrow_forward: Just Monika. Just Monika. Just {song}.", - "take me home": ":arrow_forward: Take me home, to {song}, the place I belong!", + "country road": ":arrow_forward: Take me home, to {song}, the place I belong!", "never gonna give you up": ":arrow_forward: Rickrolling in 2018. Enjoy {song}!", "september": ":arrow_forward: Do you remember? {song}.", "homestuck": ":arrow_forward: > Enter song name. {song}", @@ -89,10 +89,15 @@ song_special_messages = { "persona": ":arrow_forward: You'll never see {song} comiiiiing!", "flamingo": ":arrow_forward: How many {song} do you have to eat?", "linkin park": ":arrow_forward: Crawling in my {song}!", - "magicite": "⚠️ Warning: {song} contiene numerosi bug.", + "magicite": "⚠️ Warning: {song} contiene numerosi bug. E' ora in riproduzione.", "papers please": ":arrow_forward: Glory to Arstotzka! {song}!", "we are number one": ":arrow_forward: Now paying respect to Robbie Rotten: {song}", - "jump up superstar": ":arrow_forward: Is {song} the Tengen Toppa Guren Lagann opening?" + "jump up superstar": ":arrow_forward: Is {song} the Tengen Toppa Guren Lagann opening?", + "the world revolving": ":arrow_forward: CHAOS! CHAOS! I CAN DO {song}!", + "deltarune": ":arrow_forward: You hug Ralsei. A strange music starts playing: {song}", + "song of unhealing": ":arrow_forward: BEN {song}", + "police academy": ":arrow_forward: {song} - freedom.png", + "super smash bros. ultimate": ":arrow_forward: Re-awaken the undying light with {song}!" } # FFmpeg settings @@ -301,6 +306,7 @@ class RoyalDiscordBot(discord.Client): "!file": self.cmd_play, "!skip": self.cmd_skip, "!s": self.cmd_skip, + "!next": self.cmd_skip, "!remove": self.cmd_remove, "!r": self.cmd_remove, "!cancel": self.cmd_remove, @@ -453,10 +459,12 @@ class RoyalDiscordBot(discord.Client): message += f" | 🎮 {member.activity.name}" # Rich presence try: - message += f" ({member.activity.state})" + if member.activity.state is not None: + message += f" ({member.activity.state})" except AttributeError: try: - message += f" ({member.activity.details})" + if member.activity.details is not None: + message += f" ({member.activity.details})" except AttributeError: pass elif member.activity.type == discord.ActivityType.streaming: @@ -546,7 +554,7 @@ class RoyalDiscordBot(discord.Client): voice_client.play(audio_source) del self.video_queue[0] activity = discord.Activity(name=now_playing.plain_text(), - type=discord.ActivityType.playing) + type=discord.ActivityType.listening) logger.debug(f"Updated bot presence to {now_playing.plain_text()}.") await self.change_presence(status=discord.Status.online, activity=activity) if now_playing.enqueuer is not None: @@ -581,6 +589,7 @@ class RoyalDiscordBot(discord.Client): if voice_client.is_connected(): logger.info("Disconnecting due to inactivity.") await voice_client.disconnect() + await self.change_presence(status=discord.Status.online, activity=None) await self.main_channel.send("💤 Mi sono disconnesso dalla cv per inattività.") async def add_video_from_url(self, url, index: typing.Optional[int] = None, enqueuer: discord.Member = None): diff --git a/query_discord_music.py b/query_discord_music.py index a788243d..37827996 100644 --- a/query_discord_music.py +++ b/query_discord_music.py @@ -117,4 +117,15 @@ LEFT JOIN GROUP BY playedmusic.enqueuer_id ) last_play_times ON playedmusic.timestamp = last_play_times.last_play_time ) last_songs ON last_songs.discord_id = discord.discord_id -WHERE discord.royal_id = :royal;""" \ No newline at end of file +WHERE discord.royal_id = :royal;""" + +top_songs = """SELECT playedmusic.filename, COUNT(*) c +FROM playedmusic +GROUP BY playedmusic.filename +ORDER BY c DESC;""" + +single_top_songs = """SELECT playedmusic.filename, COUNT(*) c +FROM playedmusic +WHERE playedmusic.enqueuer_id = :discordid +GROUP BY playedmusic.filename +ORDER BY c DESC;""" diff --git a/templates/topsongs.html b/templates/topsongs.html new file mode 100644 index 00000000..0cd8165f --- /dev/null +++ b/templates/topsongs.html @@ -0,0 +1,27 @@ +{% extends 'base.html' %} + +{% block pagetitle %} + File più ascoltati {% if discord %}di {{ discord }}{% endif %} +{% endblock %} + +{% block body %} +

+ File più ascoltati {% if discord %}di {{ discord }}{% endif %} +

+ + + + + + + + + {% for song in songs %} + + + + + {% endfor %} + +
FileConteggio
{{ song[0] }}{{ song[1] }}
+{% endblock %} \ No newline at end of file diff --git a/webserver.py b/webserver.py index 8b5e39fb..1cf43e45 100644 --- a/webserver.py +++ b/webserver.py @@ -334,6 +334,32 @@ def page_diario(): return render_template("diario.html", g=fl_g, entries=diario_entries) +@app.route("/music") +def page_music(): + db_session = db.Session() + songs = db_session.execute(query_discord_music.top_songs) + db_session.close() + return render_template("topsongs.html", songs=songs) + + +@app.route("/music/") +def page_music_individual(name: str): + db_session = db.Session() + user = db_session.query(db.Royal).filter_by(username=name).one_or_none() + if user is None: + db_session.close() + abort(404) + return + discord = db_session.query(db.Discord).filter_by(royal=user).one_or_none() + if discord is None: + db_session.close() + abort(404) + return + songs = db_session.execute(query_discord_music.single_top_songs, {"discordid": discord.id}) + db_session.close() + return render_template("topsongs.html", songs=songs, discord=discord) + + @app.route("/api/token") def api_token(): username = request.form.get("username", "")