Skip to content
This repository was archived by the owner on Oct 23, 2019. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions cloudbot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
import time
from functools import partial
from pathlib import Path
from typing import Type
from typing import Optional, Type

from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import scoped_session, sessionmaker
from watchdog.observers import Observer

from cloudbot.client import Client, CLIENTS
from cloudbot.client import CLIENTS, Client
from cloudbot.config import Config
from cloudbot.event import Event, CommandEvent, RegexEvent, EventType
from cloudbot.hook import Action
from cloudbot.plugin import PluginManager
from cloudbot.reloader import PluginReloader, ConfigReloader
from cloudbot.util import database, formatting, async_util
from cloudbot.event import CommandEvent, Event, EventType, RegexEvent
from cloudbot.hooks import Action
from cloudbot.plugin_manager import PluginManager
from cloudbot.reloader import ConfigReloader, PluginReloader
from cloudbot.util import async_util, database, formatting

logger = logging.getLogger("cloudbot")

Expand All @@ -30,21 +30,22 @@ class BotInstanceHolder:
def __init__(self):
self._instance = None

def get(self):
# type: () -> CloudBot
def get(self) -> Optional['CloudBot']:
return self._instance

def set(self, value):
# type: (CloudBot) -> None
def get_or_raise(self) -> 'CloudBot':
val = self.get()
if val:
return val

raise ValueError("No bot instance available")

def set(self, value: 'CloudBot') -> None:
self._instance = value

@property
def config(self):
# type: () -> Config
if not self.get():
raise ValueError("No bot instance available")

return self.get().config
def config(self) -> Config:
return self.get_or_raise().config


# Store a global instance of the bot to allow easier access to global data
Expand Down
8 changes: 4 additions & 4 deletions cloudbot/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Event:
"""
:type bot: cloudbot.bot.CloudBot
:type conn: cloudbot.client.Client
:type hook: cloudbot.plugin.Hook
:type hook: cloudbot.hooks.hook.Hook
:type type: EventType
:type content: str
:type target: str
Expand Down Expand Up @@ -72,7 +72,7 @@ def __init__(self, *, bot=None, hook=None, conn=None, base_event=None, event_typ
:param irc_ctcp_text: CTCP text if this message is a CTCP command
:type bot: cloudbot.bot.CloudBot
:type conn: cloudbot.client.Client
:type hook: cloudbot.plugin.Hook
:type hook: cloudbot.hooks.hook.Hook
:type base_event: cloudbot.event.Event
:type content: str
:type target: str
Expand Down Expand Up @@ -392,7 +392,7 @@ def __getitem__(self, item):

class CommandEvent(Event):
"""
:type hook: cloudbot.plugin.CommandHook
:type hook: cloudbot.hooks.command.CommandHook
:type text: str
:type triggered_command: str
"""
Expand Down Expand Up @@ -444,7 +444,7 @@ def notice_doc(self, target=None):

class RegexEvent(Event):
"""
:type hook: cloudbot.plugin.RegexHook
:type hook: cloudbot.hooks.regex.RegexHook
:type match: re.__Match
"""

Expand Down
Loading