Skip to content
Open
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ python:
install:
- pip3 install mypy -r requirements.txt
script:
- mypy --ignore-missing-imports src ./bitbotd modules/
- mypy --ignore-missing-imports bitbot/ modules/ ./bitbotd
2 changes: 1 addition & 1 deletion src/Cache.py → bitbot/Cache.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import hashlib, time, typing, uuid
from src import PollHook
from . import PollHook

class Cache(PollHook.PollHook):
def __init__(self):
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/Control.py → bitbot/Control.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json, os, socket, typing
from src import IRCBot, Logging, PollSource
from . import IRCBot, Logging, PollSource

class ControlClient(object):
def __init__(self, sock: socket.socket):
Expand Down
2 changes: 1 addition & 1 deletion src/Database.py → bitbot/Database.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json, os, sqlite3, threading, time, typing
from src import Logging, utils
from . import Logging, utils

sqlite3.register_converter("BOOLEAN", lambda v: bool(int(v)))

Expand Down
2 changes: 1 addition & 1 deletion src/EventManager.py → bitbot/EventManager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import itertools, time, traceback, typing
from src import Logging, utils
from . import Logging, utils

PRIORITY_URGENT = 0
PRIORITY_HIGH = 1
Expand Down
File renamed without changes.
12 changes: 7 additions & 5 deletions src/IRCBot.py → bitbot/IRCBot.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import enum, queue, os, queue, select, socket, sys, threading, time, traceback
import typing, uuid

SRC_DIR = os.path.dirname(__file__)
VERSION: str = ""
with open("VERSION", "r") as version_file:
with open(os.path.join(SRC_DIR, "VERSION"), "r") as version_file:
VERSION = "v%s" % version_file.read().strip()
SOURCE: str = "https://git.io/bitbot"
URL: str = "https://bitbot.dev"

import enum, queue, os, queue, select, socket, sys, threading, time, traceback
import typing, uuid
from src import EventManager, Exports, IRCServer, Logging, ModuleManager
from src import PollHook, PollSource, Socket, Timers, utils
from . import EventManager, Exports, IRCServer, Logging, ModuleManager
from . import PollHook, PollSource, Socket, Timers, utils

class TriggerResult(enum.Enum):
Return = 1
Expand Down
2 changes: 1 addition & 1 deletion src/IRCBuffer.py → bitbot/IRCBuffer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import collections, dataclasses, re, typing
from src import IRCBot, IRCServer, utils
from . import IRCBot, IRCServer, utils

MAX_LINES = 64

Expand Down
4 changes: 2 additions & 2 deletions src/IRCChannel.py → bitbot/IRCChannel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re, typing, uuid
from src import EventManager, IRCBot, IRCBuffer, IRCLine, IRCObject, IRCServer
from src import IRCUser, utils
from . import EventManager, IRCBot, IRCBuffer, IRCLine, IRCObject, IRCServer
from . import IRCUser, utils

RE_MODES = re.compile(r"[-+]\w+")
SETTING_CACHE_EXPIRATION = 60.0*5.0 # 5 minutes
Expand Down
2 changes: 1 addition & 1 deletion src/IRCChannels.py → bitbot/IRCChannels.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import typing
from src import EventManager, IRCBot, IRCChannel, IRCServer, utils
from . import EventManager, IRCBot, IRCChannel, IRCServer, utils

class Channels(object):
def __init__(self, server: "IRCServer.Server", bot: "IRCBot.Bot",
Expand Down
2 changes: 1 addition & 1 deletion src/IRCLine.py → bitbot/IRCLine.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import datetime, typing, uuid
from src import EventManager, IRCObject, utils
from . import EventManager, IRCObject, utils

# this should be 510 (RFC1459, 512 with \r\n) but a server BitBot uses is broken
LINE_MAX = 470
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/IRCServer.py → bitbot/IRCServer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import collections, datetime, sys, textwrap, time, typing
from src import EventManager, IRCBot, IRCChannel, IRCChannels, IRCLine
from src import IRCObject, IRCSocket, IRCUser, utils
from . import EventManager, IRCBot, IRCChannel, IRCChannels, IRCLine
from . import IRCObject, IRCSocket, IRCUser, utils

READ_TIMEOUT_SECONDS = 120
PING_INTERVAL_SECONDS = 30
Expand Down
2 changes: 1 addition & 1 deletion src/IRCSocket.py → bitbot/IRCSocket.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import datetime, socket, ssl, time, threading, typing
from src import IRCLine, Logging, IRCObject, utils
from . import IRCLine, Logging, IRCObject, utils

THROTTLE_LINES = 4
THROTTLE_SECONDS = 1
Expand Down
2 changes: 1 addition & 1 deletion src/IRCUser.py → bitbot/IRCUser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import typing, uuid
from src import IRCBot, IRCChannel, IRCBuffer, IRCObject, IRCServer, utils
from . import IRCBot, IRCChannel, IRCBuffer, IRCObject, IRCServer, utils

class User(IRCObject.Object):
def __init__(self, nickname: str, id: int, server: "IRCServer.Server",
Expand Down
2 changes: 1 addition & 1 deletion src/LockFile.py → bitbot/LockFile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import datetime, os
from src import PollHook, utils
from . import PollHook, utils

EXPIRATION = 60 # 1 minute

Expand Down
2 changes: 1 addition & 1 deletion src/Logging.py → bitbot/Logging.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import datetime, logging, logging.handlers, os, queue, sys, time, typing
from src import utils
from . import utils

LEVELS = {
"trace": logging.DEBUG-1,
Expand Down
64 changes: 59 additions & 5 deletions src/ModuleManager.py → bitbot/ModuleManager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import enum, gc, glob, importlib, importlib.util, io, inspect, os, sys
import enum, gc, glob, importlib, importlib.util, itertools, io, inspect, os
import sys
from pkg_resources import iter_entry_points
import typing, uuid
from src import Config, EventManager, Exports, IRCBot, Logging, Timers, utils
from . import Config, EventManager, Exports, IRCBot, Logging, Timers, utils

class ModuleException(Exception):
pass
Expand Down Expand Up @@ -117,19 +119,62 @@ def __init__(self,
def _list_modules(self, directory: str
) -> typing.Dict[str, ModuleDefinition]:
modules = []

for file_module in glob.glob(os.path.join(directory, "*.py")):
modules.append(self.define_module(ModuleType.FILE, file_module))
# Excluse __init__.py, etc.
if not file_module.rsplit(os.path.sep)[-1].startswith('_'):
modules.append(self.define_module(ModuleType.FILE, file_module))

for directory_module in glob.glob(os.path.join(
directory, "*", "__init__.py")):
modules.append(self.define_module(ModuleType.DIRECTORY,
directory_module))
return {definition.name: definition for definition in modules}

def _list_installed_modules(self, entry_point_group
) -> typing.Dict[str, ModuleDefinition]:
"""Finds modules installed using a pkg_resources EntryPoint.

They are installed by `setuptools` by using:

```
setup(
# ...
entry_points={
'bitbot.extra_modules': [
'module_name = your_package_name.your_module_name:Module',
# ...
}
}
)
```

(replace only `module_name`, `your_package_name`, and
`your_module_name` on the example above)
"""
modules = {}

for entry_point in iter_entry_points(entry_point_group):
module_class = entry_point.load()
path = sys.modules[module_class.__module__].__file__
if path.rsplit(os.path.sep, 1)[-1] == '__init__.py':
type = ModuleType.DIRECTORY
else:
type = ModuleType.FILE
modules[entry_point.name] = self.define_module(type, path)

return modules

def list_modules(self, whitelist: typing.List[str],
blacklist: typing.List[str]) -> typing.Dict[str, ModuleDefinition]:
core_modules = self._list_modules(self._core_modules)
extra_modules: typing.Dict[str, ModuleDefinition] = {}
"""Discovers modules that are either installed or in one of the
directories listed by `[self._core_modules] + self._extra_modules`."""

core_modules = self._list_installed_modules('bitbot.core_modules')
extra_modules = self._list_installed_modules('bitbot.extra_modules')

for name, module in self._list_modules(self._core_modules).items():
core_modules[name] = module

for directory in self._extra_modules:
for name, module in self._list_modules(directory).items():
Expand Down Expand Up @@ -179,6 +224,15 @@ def _module_name(self, path: str) -> str:
return os.path.basename(path).rsplit(".py", 1)[0].lower()
def _module_paths(self, name: str) -> typing.List[str]:
paths = []

entry_points = itertools.chain(
iter_entry_points('bitbot.core_modules', name),
iter_entry_points('bitbot.extra_modules', name))

for entry_point in entry_points:
module_class = entry_point.load()
paths.append(sys.modules[module_class.__module__].__path__) # type: ignore

for directory in [self._core_modules]+self._extra_modules:
paths.append(os.path.join(directory, name))
return paths
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/Timers.py → bitbot/Timers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import time, typing, uuid
from src import Database, EventManager, Logging, PollHook
from . import Database, EventManager, Logging, PollHook

T_CALLBACK = typing.Callable[["Timer"], None]

Expand Down
File renamed without changes.
File renamed without changes.
Empty file added bitbot/core_modules/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion src/core_modules/admin.py → bitbot/core_modules/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#--depends-on commands
#--depends-on permissions

from src import IRCLine, ModuleManager, utils
from bitbot import IRCLine, ModuleManager, utils

class Module(ModuleManager.BaseModule):
@utils.hook("received.command.nick", min_args=1)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#--depends-on commands
import re
from src import EventManager, ModuleManager, utils
from bitbot import EventManager, ModuleManager, utils

REGEX_ARG_NUMBER = re.compile(r"\$(?:(\d+)(-?)|(-))")
SETTING_PREFIX = "command-alias-"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#--depends-on commands
#--depends-on permissions

from src import ModuleManager, utils
from bitbot import ModuleManager, utils

class Module(ModuleManager.BaseModule):
_name = "ChanAccess"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from src import EventManager, ModuleManager, utils
from bitbot import EventManager, ModuleManager, utils

@utils.export("channelset", utils.BoolSetting("blacklist",
"Refuse to join a given channel"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from src import ModuleManager, utils
from bitbot import ModuleManager, utils

@utils.export("channelset", utils.Setting("key", "Channel key (password)",
example="hunter2"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#--depends-on commands

from src import ModuleManager, utils
from bitbot import ModuleManager, utils

LOWHIGH = {
"low": "v",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#--depends-on permissions

import enum, re, shlex, string, traceback, typing
from src import EventManager, IRCLine, ModuleManager, utils
from bitbot import EventManager, IRCLine, ModuleManager, utils
from . import outs

COMMAND_METHOD = "command-method"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import re
from src import IRCLine, utils
from bitbot import IRCLine, utils

class StdOut(object):
def __init__(self, prefix):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#--depends-on permissions

import enum
from src import ModuleManager, utils
from bitbot import ModuleManager, utils

class ConfigInvalidValue(Exception):
def __init__(self, message: str=None):
Expand Down
2 changes: 1 addition & 1 deletion src/core_modules/cron.py → bitbot/core_modules/cron.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import datetime, time
from src import ModuleManager, utils
from bitbot import ModuleManager, utils

class Module(ModuleManager.BaseModule):
def on_load(self):
Expand Down
2 changes: 1 addition & 1 deletion src/core_modules/ctcp.py → bitbot/core_modules/ctcp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#--depends-on config

import datetime
from src import IRCBot, ModuleManager, utils
from bitbot import IRCBot, ModuleManager, utils


@utils.export("serverset", utils.BoolSetting("ctcp-responses",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from src import EventManager, ModuleManager, utils
from bitbot import EventManager, ModuleManager, utils

# postpone parsing SOME lines until after 001

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from src import EventManager, IRCLine, ModuleManager, utils
from bitbot import EventManager, IRCLine, ModuleManager, utils

class Module(ModuleManager.BaseModule):
@utils.hook("raw.send.privmsg", priority=EventManager.PRIORITY_MONITOR)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import datetime
from src import EventManager, ModuleManager, utils
from bitbot import EventManager, ModuleManager, utils

class Module(ModuleManager.BaseModule):
def _color(self, nickname):
Expand Down
2 changes: 1 addition & 1 deletion src/core_modules/help.py → bitbot/core_modules/help.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#--depends-on commands
from src import IRCBot, ModuleManager, utils
from bitbot import IRCBot, ModuleManager, utils

class Module(ModuleManager.BaseModule):
def _get_help(self, hook):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#--depends-on commands
#--depends-on permissions

from src import EventManager, ModuleManager, utils
from bitbot import EventManager, ModuleManager, utils

class Module(ModuleManager.BaseModule):
def _user_ignored(self, user):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#--depends-on ircv3_msgid

from src import ModuleManager, utils
from bitbot import ModuleManager, utils

TAG = utils.irc.MessageTag("msgid", "draft/msgid")
CHATHISTORY_BATCH = utils.irc.BatchType("chathistory")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from src import EventManager, ModuleManager, utils
from bitbot import EventManager, ModuleManager, utils

CAP = utils.irc.Capability("echo-message", depends_on=["labeled-response"])

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import uuid
from src import ModuleManager, utils
from bitbot import ModuleManager, utils

CAP = utils.irc.Capability(None, "draft/labeled-response-0.2",
alias="labeled-response", depends_on=["batch"])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from src import ModuleManager, utils
from bitbot import ModuleManager, utils

MSGID_TAG = "draft/msgid"
READ_TAG = "+draft/read"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from src import IRCBot, ModuleManager, utils
from bitbot import IRCBot, ModuleManager, utils

CAP = utils.irc.Capability(None, "draft/metadata", alias="metadata")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from src import ModuleManager, utils
from bitbot import ModuleManager, utils

TAG = utils.irc.MessageTag("msgid", "draft/msgid")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#--depends-on config

import base64, hashlib, hmac, typing, uuid
from src import ModuleManager, utils
from bitbot import ModuleManager, utils
from . import scram

CAP = utils.irc.Capability("sasl")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from src import ModuleManager, utils
from bitbot import ModuleManager, utils

CAP = utils.irc.Capability("server-time")
TAG = utils.irc.MessageTag("time")
Expand Down
Loading