mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-27 13:34:28 +00:00
Don't crash if the session disconnects
This commit is contained in:
parent
67a947585d
commit
8a70a7b2b3
1 changed files with 19 additions and 15 deletions
|
@ -18,8 +18,9 @@ import raven
|
||||||
import logging
|
import logging
|
||||||
import errors
|
import errors
|
||||||
import datetime
|
import datetime
|
||||||
|
import sqlalchemy.exc
|
||||||
|
|
||||||
logging.basicConfig()
|
logging.getLogger().setLevel(level=20)
|
||||||
|
|
||||||
# Queue emojis
|
# Queue emojis
|
||||||
queue_emojis = [":one:",
|
queue_emojis = [":one:",
|
||||||
|
@ -419,6 +420,7 @@ class RoyalDiscordBot(discord.Client):
|
||||||
type=discord.ActivityType.playing)
|
type=discord.ActivityType.playing)
|
||||||
await self.change_presence(status=discord.Status.online, activity=activity)
|
await self.change_presence(status=discord.Status.online, activity=activity)
|
||||||
if now_playing.enqueuer is not None:
|
if now_playing.enqueuer is not None:
|
||||||
|
try:
|
||||||
session = db.Session()
|
session = db.Session()
|
||||||
enqueuer = await loop.run_in_executor(executor, session.query(db.Discord)
|
enqueuer = await loop.run_in_executor(executor, session.query(db.Discord)
|
||||||
.filter_by(discord_id=now_playing.enqueuer.id)
|
.filter_by(discord_id=now_playing.enqueuer.id)
|
||||||
|
@ -429,6 +431,8 @@ class RoyalDiscordBot(discord.Client):
|
||||||
session.add(played_music)
|
session.add(played_music)
|
||||||
await loop.run_in_executor(executor, session.commit)
|
await loop.run_in_executor(executor, session.commit)
|
||||||
await loop.run_in_executor(executor, session.close)
|
await loop.run_in_executor(executor, session.close)
|
||||||
|
except sqlalchemy.exc.OperationalError:
|
||||||
|
pass
|
||||||
for key in song_special_messages:
|
for key in song_special_messages:
|
||||||
if key in now_playing.file.lower():
|
if key in now_playing.file.lower():
|
||||||
await self.main_channel.send(song_special_messages[key].format(song=str(now_playing)))
|
await self.main_channel.send(song_special_messages[key].format(song=str(now_playing)))
|
||||||
|
@ -717,14 +721,14 @@ class RoyalDiscordBot(discord.Client):
|
||||||
|
|
||||||
|
|
||||||
def process(users_connection=None):
|
def process(users_connection=None):
|
||||||
print("[Discord] Preparing...")
|
logging.info("Initializing the bot...")
|
||||||
bot = RoyalDiscordBot()
|
bot = RoyalDiscordBot()
|
||||||
if users_connection is not None:
|
if users_connection is not None:
|
||||||
|
logging.info("Initializing Telegram-Discord connection...")
|
||||||
asyncio.ensure_future(bot.feed_pipe(users_connection))
|
asyncio.ensure_future(bot.feed_pipe(users_connection))
|
||||||
# asyncio.ensure_future(queue_predownload_videos())
|
logging.info("Logging in...")
|
||||||
# asyncio.ensure_future(queue_play_next_video())
|
|
||||||
loop.run_until_complete(bot.login(config["Discord"]["bot_token"], bot=True))
|
loop.run_until_complete(bot.login(config["Discord"]["bot_token"], bot=True))
|
||||||
print("[Discord] Logged in successfully!")
|
logging.info("Connecting...")
|
||||||
loop.run_until_complete(bot.connect())
|
loop.run_until_complete(bot.connect())
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue