Asynchronous Ripple chat bot, delta-compatible
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.6KB

  1. import importlib
  2. import logging
  3. from utils.init_hook import InitHook
  4. from utils.osuapi import OsuAPIClient
  5. try:
  6. import uvloop
  7. use_uvloop = True
  8. except ImportError:
  9. use_uvloop = False
  10. from singletons.config import Config
  11. from singletons.bot import Bot
  12. from utils.letsapi import LetsApiClient
  13. from utils.rippleapi import BanchoApiClient, RippleApiClient, CheesegullApiClient
  14. def main() -> None:
  15. # Logging
  16. logging.basicConfig(level=logging.DEBUG if Config()["DEBUG"] else logging.INFO)
  17. logging.info(
  18. """
  19. __ _
  20. / _| | |
  21. | |_ ___ | | ____ ___ _____ ___ ___
  22. | _/ _ \\| |/ / _` \\ \\ /\\ / / _ \\ / _ \\ / _ \\
  23. | || (_) | < (_| |\\ V V / (_) | (_) | (_) |
  24. |_| \\___/|_|\\_\\__,_| \\_/\\_/ \\___/ \\___/ \\___/
  25. """
  26. )
  27. # Setup Bot singleton
  28. if use_uvloop:
  29. uvloop.install()
  30. logging.info("Using uvloop")
  31. else:
  32. logging.warning("Using asyncio")
  33. Bot(
  34. wss=Config()["WSS"],
  35. nickname=Config()["BOT_NICKNAME"],
  36. commands_prefix=Config()["COMMANDS_PREFIX"],
  37. bancho_api_client=BanchoApiClient(
  38. Config()["BANCHO_API_TOKEN"],
  39. Config()["BANCHO_API_BASE"]
  40. ),
  41. ripple_api_client=RippleApiClient(
  42. Config()["RIPPLE_API_TOKEN"],
  43. Config()["RIPPLE_API_BASE"]
  44. ),
  45. lets_api_client=LetsApiClient(
  46. Config()["LETS_API_BASE"]
  47. ),
  48. cheesegull_api_client=CheesegullApiClient(
  49. Config()["CHEESEGULL_API_BASE"]
  50. ),
  51. osu_api_client=OsuAPIClient(
  52. Config()["OSU_API_TOKEN"]
  53. ),
  54. http_host=Config()["HTTP_HOST"],
  55. http_port=Config()["HTTP_PORT"],
  56. redis_host=Config()["REDIS_HOST"],
  57. redis_port=Config()["REDIS_PORT"],
  58. redis_database=Config()["REDIS_DATABASE"],
  59. redis_password=Config()["REDIS_PASSWORD"],
  60. redis_pool_size=Config()["REDIS_POOL_SIZE"],
  61. tinydb_path=Config()["TINYDB_PATH"],
  62. )
  63. # Register all events
  64. import events
  65. # Import all required plugins (register bot commands)
  66. for plugin in Config()["BOT_PLUGINS"]:
  67. imported_plugin = importlib.import_module(f"plugins.{plugin}")
  68. if hasattr(imported_plugin, "init"):
  69. logging.debug(f"Plugin {plugin} has init hook.")
  70. Bot().init_hooks.append(InitHook(plugin, getattr(imported_plugin, "init")))
  71. Bot().logger.info(f"Loaded plugin plugins.{plugin}")
  72. # Finally, run the bot
  73. Bot().run()
  74. if __name__ == '__main__':
  75. main()