|
1 | 1 | import asyncio
|
2 | 2 | import collections
|
3 | 3 | import gc
|
| 4 | +import importlib |
4 | 5 | import logging
|
5 | 6 | import re
|
6 | 7 | import time
|
|
10 | 11 | from pathlib import Path
|
11 | 12 | from typing import Any, Dict, Optional, Type
|
12 | 13 |
|
13 |
| -from sqlalchemy import Table, create_engine, inspect |
| 14 | +from sqlalchemy import Table, create_engine |
| 15 | +from sqlalchemy import inspect as sa_inspect |
14 | 16 | from sqlalchemy.engine import Engine
|
15 | 17 | from sqlalchemy.orm import Session, scoped_session, sessionmaker
|
16 |
| -from venusian import Scanner |
17 | 18 | from watchdog.observers import Observer
|
18 | 19 |
|
19 |
| -from cloudbot import clients |
20 | 20 | from cloudbot.client import Client
|
21 | 21 | from cloudbot.config import Config
|
22 | 22 | from cloudbot.event import CommandEvent, Event, EventType, RegexEvent
|
@@ -315,8 +315,21 @@ def load_clients(self):
|
315 | 315 | """
|
316 | 316 | Load all clients from the "clients" directory
|
317 | 317 | """
|
318 |
| - scanner = Scanner(bot=self) |
319 |
| - scanner.scan(clients, categories=["cloudbot.client"]) |
| 318 | + for file in (Path(__file__).parent / "clients").rglob("*.py"): |
| 319 | + if file.name.startswith("_"): |
| 320 | + continue |
| 321 | + |
| 322 | + mod = importlib.import_module("cloudbot.clients." + file.stem) |
| 323 | + for _, obj in vars(mod).items(): |
| 324 | + if not isinstance(obj, type): |
| 325 | + continue |
| 326 | + |
| 327 | + try: |
| 328 | + _type = obj._cloudbot_client # type: ignore |
| 329 | + except AttributeError: |
| 330 | + continue |
| 331 | + |
| 332 | + self.register_client(_type, obj) |
320 | 333 |
|
321 | 334 | async def process(self, event):
|
322 | 335 | run_before_tasks = []
|
@@ -466,7 +479,7 @@ def migrate_db(self) -> None:
|
466 | 479 | old_session: Session = scoped_session(sessionmaker(bind=engine))()
|
467 | 480 | new_session: Session = database.Session()
|
468 | 481 | table: Table
|
469 |
| - inspector = inspect(engine) |
| 482 | + inspector = sa_inspect(engine) |
470 | 483 | for table in database.metadata.tables.values():
|
471 | 484 | logger.info("Migrating table %s", table.name)
|
472 | 485 | if not inspector.has_table(table.name):
|
|
0 commit comments