From dae3ee2649567c1c44e72fbf26ae3fa66e469aee Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 11 Nov 2017 18:55:13 +0100 Subject: [PATCH] coseeeeeeeeeeeeeeeeeeeeee --- db.py | 24 ----------------- discordbot.py | 64 +++++++++++++++++++++++++++++++++++--------- static/royal.css | 4 +-- telegrambot.py | 58 ++++++++++++++++++++++++++++++++++----- templates/music.html | 34 ----------------------- webserver.py | 10 +------ 6 files changed, 106 insertions(+), 88 deletions(-) delete mode 100644 templates/music.html diff --git a/db.py b/db.py index 0106772c..f2c0b70d 100644 --- a/db.py +++ b/db.py @@ -598,30 +598,6 @@ class Diario(Base): session.close() -class CVMusic(Base): - __tablename__ = "cvmusic" - - id = Column(BigInteger, primary_key=True) - url = Column(String, nullable=False) - enqueued = Column(DateTime, nullable=False) - started = Column(DateTime, nullable=False) - - user_id = Column(Integer, ForeignKey("royals.id")) - user = relationship("Royal") - - @staticmethod - def create_and_add(url: str, user: Royal, enqueued: datetime.datetime, started: datetime.datetime): - try: - session = Session() - session.add(CVMusic(url=url, - enqueued=enqueued, - started=started, - user_id=user.id)) - session.commit() - session.close() - except Exception as e: - print(f"ERRORE CVMusic: {e}") - # If run as script, create all the tables in the db if __name__ == "__main__": Base.metadata.create_all(bind=engine) \ No newline at end of file diff --git a/discordbot.py b/discordbot.py index 72a4f69c..6d250442 100644 --- a/discordbot.py +++ b/discordbot.py @@ -1,4 +1,5 @@ import datetime +import random import discord import discord.opus import functools @@ -6,7 +7,6 @@ import sys import db import errors import youtube_dl -import sqlalchemy.exc # Init the event loop import asyncio @@ -17,6 +17,18 @@ import configparser config = configparser.ConfigParser() config.read("config.ini") +# Find the latest git tag +import subprocess +import os +old_wd = os.getcwd() +try: + os.chdir(os.path.dirname(__file__)) + version = str(subprocess.check_output(["git", "describe", "--tags"]), encoding="utf8").strip() +except: + version = "v???" +finally: + os.chdir(old_wd) + # Init the discord bot client = discord.Client() discord.opus.load_opus("libopus-0.dll") @@ -26,6 +38,7 @@ voice_queue = [] voice_playing = None + class Video: def __init__(self): self.user = None @@ -51,13 +64,13 @@ class Video: def create_embed(self): embed = discord.Embed(type="rich", - title=self.info['title'] if 'title' in self.info else None, - url=self.info['webpage_url'] if 'webpage_url' in self.info else None, + title=self.info.get("title"), + url=self.info.get("webpage_url"), colour=discord.Colour(13375518)) # Uploader - if "uploader" in self.info and self.info["uploader"] is not None: + if self.info.get("uploader"): embed.set_author(name=self.info["uploader"], - url=self.info["uploader_url"] if "uploader_url" in self.info else None) + url=self.info.get("uploader_url")) # Thumbnail if "thumbnail" in self.info: embed.set_thumbnail(url=self.info["thumbnail"]) @@ -107,6 +120,7 @@ async def on_error(event, *args, **kwargs): f"```python\n" f"{repr(exception)}\n" f"```") + await voice_client.disconnect() await client.change_presence(status=discord.Status.invisible) await client.close() except Exception as e: @@ -117,7 +131,7 @@ async def on_error(event, *args, **kwargs): @client.event async def on_ready(): - await client.send_message(client.get_channel("368447084518572034"), f"ℹ Bot avviato e pronto a ricevere comandi!") + await client.send_message(client.get_channel("368447084518572034"), f"ℹ Royal Bot {version} avviato e pronto a ricevere comandi!") await client.change_presence(game=None, status=discord.Status.online) @@ -145,7 +159,7 @@ async def on_message(message: discord.Message): session.commit() session.close() await client.send_message(message.channel, "✅ Sincronizzazione completata!") - elif message.content.startswith("!cv") and discord.opus.is_loaded(): + elif message.content.startswith("!cv"): await client.send_typing(message.channel) if message.author.voice.voice_channel is None: await client.send_message(message.channel, "⚠ Non sei in nessun canale!") @@ -168,7 +182,7 @@ async def on_message(message: discord.Message): url = message.content.split(" ", 1)[1] except IndexError: await client.send_message(message.channel, "⚠️ Non hai specificato un url!\n" - "Sintassi corretta: `!madd