mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-27 13:34:28 +00:00
???
This commit is contained in:
parent
31e6b5354d
commit
cf95ed88be
2 changed files with 18 additions and 17 deletions
|
@ -24,7 +24,8 @@ import datetime
|
||||||
import sqlalchemy.exc
|
import sqlalchemy.exc
|
||||||
|
|
||||||
logging.getLogger().setLevel(level=logging.ERROR)
|
logging.getLogger().setLevel(level=logging.ERROR)
|
||||||
logging.getLogger(__name__).setLevel(level=logging.DEBUG)
|
logger = logging.getLogger(__name__)
|
||||||
|
logger.setLevel(level=logging.DEBUG)
|
||||||
|
|
||||||
# Queue emojis
|
# Queue emojis
|
||||||
queue_emojis = [":one:",
|
queue_emojis = [":one:",
|
||||||
|
@ -109,7 +110,7 @@ executor = concurrent.futures.ThreadPoolExecutor(max_workers=3)
|
||||||
# Init the Sentry client
|
# Init the Sentry client
|
||||||
sentry = raven.Client(config["Sentry"]["token"],
|
sentry = raven.Client(config["Sentry"]["token"],
|
||||||
release=version,
|
release=version,
|
||||||
install_logging_hook=False,
|
install_logger_hook=False,
|
||||||
hook_libraries=[])
|
hook_libraries=[])
|
||||||
|
|
||||||
|
|
||||||
|
@ -332,7 +333,7 @@ class RoyalDiscordBot(discord.Client):
|
||||||
|
|
||||||
async def on_error(self, event_method, *args, **kwargs):
|
async def on_error(self, event_method, *args, **kwargs):
|
||||||
ei = sys.exc_info()
|
ei = sys.exc_info()
|
||||||
logging.error(f"Critical error: {repr(ei[1])}")
|
logger.error(f"Critical error: {repr(ei[1])}")
|
||||||
try:
|
try:
|
||||||
await self.main_channel.send(f"☢️ **ERRORE CRITICO NELL'EVENTO** `{event_method}`\n"
|
await self.main_channel.send(f"☢️ **ERRORE CRITICO NELL'EVENTO** `{event_method}`\n"
|
||||||
f"Il bot si è chiuso e si dovrebbe riavviare entro qualche minuto.\n"
|
f"Il bot si è chiuso e si dovrebbe riavviare entro qualche minuto.\n"
|
||||||
|
@ -344,7 +345,7 @@ class RoyalDiscordBot(discord.Client):
|
||||||
await self.change_presence(status=discord.Status.invisible)
|
await self.change_presence(status=discord.Status.invisible)
|
||||||
await self.close()
|
await self.close()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error("Double critical error: {repr(sys.exc_info())}")
|
logger.error("Double critical error: {repr(sys.exc_info())}")
|
||||||
loop.stop()
|
loop.stop()
|
||||||
sentry.captureException(exc_info=ei)
|
sentry.captureException(exc_info=ei)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
@ -727,21 +728,20 @@ class RoyalDiscordBot(discord.Client):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def process(users_connection=None):
|
def process(users_connection=None):
|
||||||
logging.info("Initializing the bot...")
|
logger.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...")
|
logger.info("Initializing Telegram-Discord connection...")
|
||||||
asyncio.ensure_future(bot.feed_pipe(users_connection))
|
asyncio.ensure_future(bot.feed_pipe(users_connection))
|
||||||
logging.info("Logging in...")
|
logger.info("Logging in...")
|
||||||
loop.run_until_complete(bot.login(config["Discord"]["bot_token"], bot=True))
|
loop.run_until_complete(bot.login(config["Discord"]["bot_token"], bot=True))
|
||||||
logging.info("Connecting...")
|
logger.info("Connecting...")
|
||||||
try:
|
try:
|
||||||
loop.run_until_complete(bot.connect())
|
loop.run_until_complete(bot.connect())
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
logging.info("Now stopping...")
|
logger.info("Now stopping...")
|
||||||
loop.run_until_complete(self.logout())
|
loop.run_until_complete(bot.logout())
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,8 @@ except Exception:
|
||||||
model = None
|
model = None
|
||||||
|
|
||||||
logging.getLogger().setLevel(level=logging.ERROR)
|
logging.getLogger().setLevel(level=logging.ERROR)
|
||||||
logging.getLogger(__name__).setLevel(level=logging.DEBUG)
|
logger = logging.getLogger(__name__)
|
||||||
|
logger.setLevel(level=logging.DEBUG)
|
||||||
|
|
||||||
# Init the config reader
|
# Init the config reader
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
|
@ -621,7 +622,7 @@ def process(arg_discord_connection):
|
||||||
u.dispatcher.add_handler(CommandHandler("calendar", cmd_calendar))
|
u.dispatcher.add_handler(CommandHandler("calendar", cmd_calendar))
|
||||||
u.dispatcher.add_handler(CommandHandler("markov", cmd_markov))
|
u.dispatcher.add_handler(CommandHandler("markov", cmd_markov))
|
||||||
u.dispatcher.add_handler(CallbackQueryHandler(on_callback_query))
|
u.dispatcher.add_handler(CallbackQueryHandler(on_callback_query))
|
||||||
logging.info("Handlers registered.")
|
logger.info("Handlers registered.")
|
||||||
u.bot.send_message(config["Telegram"]["main_group"],
|
u.bot.send_message(config["Telegram"]["main_group"],
|
||||||
f"ℹ Royal Bot avviato e pronto a ricevere comandi!\n"
|
f"ℹ Royal Bot avviato e pronto a ricevere comandi!\n"
|
||||||
f"Ultimo aggiornamento: `{version}: {commit_msg}`",
|
f"Ultimo aggiornamento: `{version}: {commit_msg}`",
|
||||||
|
@ -629,14 +630,14 @@ def process(arg_discord_connection):
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
u.start_polling()
|
u.start_polling()
|
||||||
logging.info("Polling started.")
|
logger.info("Polling started.")
|
||||||
u.idle()
|
u.idle()
|
||||||
except telegram.error.TimedOut:
|
except telegram.error.TimedOut:
|
||||||
logging.warning("Timed out, restarting in 1 minute.")
|
logger.warning("Timed out, restarting in 1 minute.")
|
||||||
time.sleep(60)
|
time.sleep(60)
|
||||||
logging.info("Now restarting...")
|
logger.info("Now restarting...")
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
logging.info("Now stopping...")
|
logger.info("Now stopping...")
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue