import common.url from common import utils from common import space from common.config import config import lrrbot.main __all__ = ["log_chat", "clear_chat_log", "clear_chat_log_msg", "exitthread"] log = logging.getLogger('chatlog') CACHE_EXPIRY = 7 * 24 * 60 * 60 PURGE_PERIOD = datetime.timedelta(minutes=5) queue = asyncio.Queue() space.monkey_patch_urlize() def urlize(text): return real_urlize(text).replace( '<a ', '<a target="_blank" rel="noopener nofollow" ') # Chat-log handling functions live in an asyncio task, so that functions that take # a long time to run, like downloading the emote list, don't block the bot... but # one master task, with a message queue, so that things still happen in the right order. async def run_task(): while True: ev, params = await queue.get() if ev == "log_chat": await do_log_chat(*params)
if asyncio.iscoroutinefunction(view_func): if view_func not in self.__wrapped_view_funcs: @functools.wraps(view_func) def inner(*args, **kwargs): return asyncio.get_event_loop().run_until_complete(view_func(*args, **kwargs)) self.__wrapped_view_funcs[view_func] = inner func = inner if view_func in flaskext.csrf._exempt_views: flaskext.csrf.csrf_exempt(func) else: func = self.__wrapped_view_funcs[view_func] else: func = view_func return super().add_url_rule(rule, endpoint, func, **options) app = Application(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = config["postgres"] app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['SQLALCHEMY_ECHO'] = config["debug"] db = SQLAlchemy(app) db.engine.update_execution_options(autocommit=False) with warnings.catch_warnings(): # Yes, I know you can't understand FTS indexes. warnings.simplefilter("ignore", category=sqlalchemy.exc.SAWarning) db.reflect() csrf(app) space.monkey_patch_urlize() __all__ = ['app', 'db']