aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar jesopo2018-09-24 15:13:27 +0100
committerGravatar jesopo2018-09-24 15:13:27 +0100
commitecb9d7cb3f4435457560e03201bbed57a469d548 (patch)
tree5a010f97c209558cdd2d40327d41e6806aedde94
parentRemove empty spaces in coins.py (diff)
signature
Move most code in root directory to src/
-rw-r--r--modules/8ball.py2
-rw-r--r--modules/accept_invite.py2
-rw-r--r--modules/auto_mode.py2
-rw-r--r--modules/bitcoin.py2
-rw-r--r--modules/books.py2
-rw-r--r--modules/channel_op.py2
-rw-r--r--modules/check_urls.py2
-rw-r--r--modules/coins.py2
-rw-r--r--modules/commands.py2
-rw-r--r--modules/ctcp.py2
-rw-r--r--modules/define.py2
-rw-r--r--modules/dice.py2
-rw-r--r--modules/ducks.py4
-rw-r--r--modules/eval.py2
-rw-r--r--modules/geoip.py2
-rw-r--r--modules/google.py2
-rw-r--r--modules/haveibeenpwned.py2
-rw-r--r--modules/imdb.py2
-rw-r--r--modules/in.py2
-rw-r--r--modules/isgd.py2
-rw-r--r--modules/karma.py2
-rw-r--r--modules/lastfm.py2
-rw-r--r--modules/modules.py2
-rw-r--r--modules/nickserv.py2
-rw-r--r--modules/nr.py2
-rw-r--r--modules/perform.py2
-rw-r--r--modules/pong.py2
-rw-r--r--modules/print_activity.py2
-rw-r--r--modules/sed.py2
-rw-r--r--modules/seen.py2
-rw-r--r--modules/shakespeare.py2
-rw-r--r--modules/signals.py2
-rw-r--r--modules/soundcloud.py2
-rw-r--r--modules/spotify.py2
-rw-r--r--modules/stats.py2
-rw-r--r--modules/tfl.py2
-rw-r--r--modules/thesaurus.py2
-rw-r--r--modules/title.py2
-rw-r--r--modules/to.py2
-rw-r--r--modules/trakt.py2
-rw-r--r--modules/translate.py2
-rw-r--r--modules/tweets.py2
-rw-r--r--modules/upc.py2
-rw-r--r--modules/urbandictionary.py2
-rw-r--r--modules/weather.py2
-rw-r--r--modules/wikipedia.py2
-rw-r--r--modules/wolframalpha.py2
-rw-r--r--modules/words.py2
-rw-r--r--modules/youtube.py2
-rw-r--r--src/Config.py (renamed from Config.py)7
-rw-r--r--src/Database.py (renamed from Database.py)7
-rw-r--r--src/EventManager.py (renamed from EventManager.py)0
-rw-r--r--src/Exports.py (renamed from Exports.py)0
-rw-r--r--src/IRCBot.py (renamed from IRCBot.py)19
-rw-r--r--src/IRCBuffer.py (renamed from IRCBuffer.py)2
-rw-r--r--src/IRCChannel.py (renamed from IRCChannel.py)2
-rw-r--r--src/IRCLineHandler.py (renamed from IRCLineHandler.py)2
-rw-r--r--src/IRCServer.py (renamed from IRCServer.py)2
-rw-r--r--src/IRCUser.py (renamed from IRCUser.py)2
-rw-r--r--src/Logging.py (renamed from Logging.py)6
-rw-r--r--src/ModuleManager.py (renamed from ModuleManager.py)4
-rw-r--r--src/Timer.py (renamed from Timer.py)0
-rw-r--r--src/Utils.py (renamed from Utils.py)2
-rwxr-xr-xstart.py26
64 files changed, 92 insertions, 89 deletions
diff --git a/modules/8ball.py b/modules/8ball.py
index 710ab448..37d38743 100644
--- a/modules/8ball.py
+++ b/modules/8ball.py
@@ -1,5 +1,5 @@
import random
-import Utils
+from src import Utils
CHOICES = [
"Definitely",
diff --git a/modules/accept_invite.py b/modules/accept_invite.py
index e79cbfe9..40888f8a 100644
--- a/modules/accept_invite.py
+++ b/modules/accept_invite.py
@@ -1,4 +1,4 @@
-import Utils
+from src import Utils
class Module(object):
def __init__(self, bot, events, exports):
diff --git a/modules/auto_mode.py b/modules/auto_mode.py
index cfb7af94..af6dc606 100644
--- a/modules/auto_mode.py
+++ b/modules/auto_mode.py
@@ -1,4 +1,4 @@
-import Utils
+from src import Utils
class Module(object):
_name = "AutoMode"
diff --git a/modules/bitcoin.py b/modules/bitcoin.py
index 5be8bb96..c85e6bf1 100644
--- a/modules/bitcoin.py
+++ b/modules/bitcoin.py
@@ -1,4 +1,4 @@
-import Utils
+from src import Utils
class Module(object):
_name = "BTC"
diff --git a/modules/books.py b/modules/books.py
index 409c8613..e0569a76 100644
--- a/modules/books.py
+++ b/modules/books.py
@@ -1,5 +1,5 @@
import json, re
-import Utils
+from src import Utils
URL_GOOGLEBOOKS = "https://www.googleapis.com/books/v1/volumes"
URL_BOOKINFO = "https://books.google.co.uk/books?id=%s"
diff --git a/modules/channel_op.py b/modules/channel_op.py
index 1cdc4e15..ad2233d9 100644
--- a/modules/channel_op.py
+++ b/modules/channel_op.py
@@ -1,4 +1,4 @@
-import Utils
+from src import Utils
class Module(object):
_name = "Channel Op"
diff --git a/modules/check_urls.py b/modules/check_urls.py
index 221f548d..fa05695e 100644
--- a/modules/check_urls.py
+++ b/modules/check_urls.py
@@ -1,7 +1,7 @@
#--require-config virustotal-api-key
import re
-import Utils
+from src import Utils
URL_VIRUSTOTAL = "https://www.virustotal.com/vtapi/v2/url/report"
RE_URL = re.compile(r"https?://\S+", re.I)
diff --git a/modules/coins.py b/modules/coins.py
index fef48258..e66aff6c 100644
--- a/modules/coins.py
+++ b/modules/coins.py
@@ -1,5 +1,5 @@
import datetime, decimal, math, random, re, time
-import Utils
+from src import Utils
SIDES = {"heads": 0, "tails": 1}
DEFAULT_REDEEM_DELAY = 600 # 600 seconds, 10 minutes
diff --git a/modules/commands.py b/modules/commands.py
index 9df70ffc..02787791 100644
--- a/modules/commands.py
+++ b/modules/commands.py
@@ -1,5 +1,5 @@
import re
-import EventManager, Utils
+from src import EventManager, Utils
STR_MORE = "%s (more...)" % Utils.FONT_RESET
STR_CONTINUED = "(...continued) "
diff --git a/modules/ctcp.py b/modules/ctcp.py
index 70bb4d25..a9144974 100644
--- a/modules/ctcp.py
+++ b/modules/ctcp.py
@@ -1,5 +1,5 @@
import datetime
-import Utils
+from src import Utils
class Module(object):
def __init__(self, bot, events, exports):
diff --git a/modules/define.py b/modules/define.py
index bbc37f70..1b88e83b 100644
--- a/modules/define.py
+++ b/modules/define.py
@@ -1,7 +1,7 @@
#--require-config wordnik-api-key
-import Utils
import time
+from src import Utils
URL_WORDNIK = "https://api.wordnik.com/v4/word.json/%s/definitions"
URL_WORDNIK_RANDOM = "https://api.wordnik.com/v4/words.json/randomWord"
diff --git a/modules/dice.py b/modules/dice.py
index 1b1fc0ab..30e4f319 100644
--- a/modules/dice.py
+++ b/modules/dice.py
@@ -1,5 +1,5 @@
import random
-import Utils
+from src import Utils
class Module(object):
def __init__(self, bot, events, exports):
diff --git a/modules/ducks.py b/modules/ducks.py
index c2ae696c..a9c4f6b5 100644
--- a/modules/ducks.py
+++ b/modules/ducks.py
@@ -1,9 +1,7 @@
import random
from operator import itemgetter
from time import time
-import EventManager
-
-import Utils
+from src import EventManager, Utils
DUCK_TAIL = "・゜゜・。。・゜゜"
DUCK_HEAD = ["\_o< ", "\_O< ", "\_0< ", "\_\u00f6< ", "\_\u00f8< ",
diff --git a/modules/eval.py b/modules/eval.py
index f63c0297..ab68a368 100644
--- a/modules/eval.py
+++ b/modules/eval.py
@@ -1,5 +1,5 @@
import socket
-import Utils
+from src import Utils
EVAL_URL = "https://eval.appspot.com/eval"
diff --git a/modules/geoip.py b/modules/geoip.py
index 5eb6f017..5bc464b1 100644
--- a/modules/geoip.py
+++ b/modules/geoip.py
@@ -1,4 +1,4 @@
-import Utils
+from src import Utils
URL_GEOIP = "http://ip-api.com/json/%s"
diff --git a/modules/google.py b/modules/google.py
index 986a7073..42acf954 100644
--- a/modules/google.py
+++ b/modules/google.py
@@ -1,7 +1,7 @@
#--require-config google-api-key
#--require-config google-search-id
-import Utils
+from src import Utils
URL_GOOGLESEARCH = "https://www.googleapis.com/customsearch/v1"
diff --git a/modules/haveibeenpwned.py b/modules/haveibeenpwned.py
index ce2b788d..79662913 100644
--- a/modules/haveibeenpwned.py
+++ b/modules/haveibeenpwned.py
@@ -1,4 +1,4 @@
-import Utils
+from src import Utils
URL_HAVEIBEENPWNEDAPI = "https://haveibeenpwned.com/api/v2/breachedaccount/%s"
URL_HAVEIBEENPWNED = "https://haveibeenpwned.com/"
diff --git a/modules/imdb.py b/modules/imdb.py
index 1e668523..741b2955 100644
--- a/modules/imdb.py
+++ b/modules/imdb.py
@@ -1,7 +1,7 @@
#--require-config omdbapi-api-key
import json
-import Utils
+from src import Utils
URL_OMDB = "http://www.omdbapi.com/"
URL_IMDBTITLE = "http://imdb.com/title/%s"
diff --git a/modules/in.py b/modules/in.py
index 3a1ddb87..2351fb11 100644
--- a/modules/in.py
+++ b/modules/in.py
@@ -1,5 +1,5 @@
import time
-import Utils
+from src import Utils
SECONDS_MAX = Utils.SECONDS_WEEKS*8
SECONDS_MAX_DESCRIPTION = "8 weeks"
diff --git a/modules/isgd.py b/modules/isgd.py
index 86af7447..3ceacaff 100644
--- a/modules/isgd.py
+++ b/modules/isgd.py
@@ -1,5 +1,5 @@
import re
-import Utils
+from src import Utils
ISGD_API_URL = "https://is.gd/create.php"
REGEX_URL = re.compile("https?://", re.I)
diff --git a/modules/karma.py b/modules/karma.py
index 6f6dc8a3..897f0ea2 100644
--- a/modules/karma.py
+++ b/modules/karma.py
@@ -1,5 +1,5 @@
import re, time
-import EventManager, Utils
+from src import EventManager, Utils
REGEX_KARMA = re.compile("^(.*[^-+])[-+]*(\+{2,}|\-{2,})$")
KARMA_DELAY_SECONDS = 3
diff --git a/modules/lastfm.py b/modules/lastfm.py
index 68b6249b..d46bc50b 100644
--- a/modules/lastfm.py
+++ b/modules/lastfm.py
@@ -1,7 +1,7 @@
#--require-config lastfm-api-key
-import Utils
from datetime import datetime, timezone
+from src import Utils
URL_SCROBBLER = "http://ws.audioscrobbler.com/2.0/"
diff --git a/modules/modules.py b/modules/modules.py
index 0d4844e9..91bc02a7 100644
--- a/modules/modules.py
+++ b/modules/modules.py
@@ -1,4 +1,4 @@
-import ModuleManager
+from src import ModuleManager
class Module(object):
def __init__(self, bot, events, exports):
diff --git a/modules/nickserv.py b/modules/nickserv.py
index 031c81d9..5ba2a992 100644
--- a/modules/nickserv.py
+++ b/modules/nickserv.py
@@ -1,5 +1,5 @@
import base64
-import EventManager
+from src import EventManager
class Module(object):
def __init__(self, bot, events, exports):
diff --git a/modules/nr.py b/modules/nr.py
index 0958967d..e1b605cd 100644
--- a/modules/nr.py
+++ b/modules/nr.py
@@ -2,7 +2,7 @@ import collections, re, time
from datetime import datetime, date
from collections import Counter
-import Utils
+from src import Utils
from suds.client import Client
from suds import WebFault
diff --git a/modules/perform.py b/modules/perform.py
index 5245cadf..f5572fdc 100644
--- a/modules/perform.py
+++ b/modules/perform.py
@@ -1,4 +1,4 @@
-import EventManager
+from src import EventManager
class Module(object):
def __init__(self, bot, events, exports):
diff --git a/modules/pong.py b/modules/pong.py
index fc12d0c2..c45e3aef 100644
--- a/modules/pong.py
+++ b/modules/pong.py
@@ -1,4 +1,4 @@
-import ModuleManager, Utils
+from src import ModuleManager, Utils
class Module(ModuleManager.BaseModule):
@Utils.hook("received.command.ping", help="Ping pong!")
diff --git a/modules/print_activity.py b/modules/print_activity.py
index 4d2b90a2..69c8d1b3 100644
--- a/modules/print_activity.py
+++ b/modules/print_activity.py
@@ -1,5 +1,5 @@
import datetime
-import EventManager
+from src import EventManager
class Module(object):
def __init__(self, bot, events, exports):
diff --git a/modules/sed.py b/modules/sed.py
index e4a61c70..c9ef778d 100644
--- a/modules/sed.py
+++ b/modules/sed.py
@@ -1,5 +1,5 @@
import re, traceback
-import Utils
+from src import Utils
REGEX_SPLIT = re.compile("(?<!\\\\)/")
REGEX_SED = re.compile("^s/")
diff --git a/modules/seen.py b/modules/seen.py
index 48525bd5..89e59e18 100644
--- a/modules/seen.py
+++ b/modules/seen.py
@@ -1,5 +1,5 @@
import time
-import Utils
+from src import Utils
class Module(object):
def __init__(self, bot, events, exports):
diff --git a/modules/shakespeare.py b/modules/shakespeare.py
index 9c9a20f4..bc4a9900 100644
--- a/modules/shakespeare.py
+++ b/modules/shakespeare.py
@@ -1,5 +1,5 @@
import random
-import Utils
+from src import Utils
INSULT_INTRO = ["Thou art a", "Ye", "Thou", "Thy", "Thee"]
diff --git a/modules/signals.py b/modules/signals.py
index 2be385a9..5c2c1fbb 100644
--- a/modules/signals.py
+++ b/modules/signals.py
@@ -1,5 +1,5 @@
import signal
-import Config
+from src import Config
class Module(object):
def __init__(self, bot, events, exports):
diff --git a/modules/soundcloud.py b/modules/soundcloud.py
index 952c9938..70e75423 100644
--- a/modules/soundcloud.py
+++ b/modules/soundcloud.py
@@ -1,7 +1,7 @@
#--require-config soundcloud-api-key
import json, re, time
-import Utils
+from src import Utils
URL_SOUNDCLOUD_TRACK = "http://api.soundcloud.com/tracks"
URL_SOUNDCLOUD_RESOLVE = "http://api.soundcloud.com/resolve"
diff --git a/modules/spotify.py b/modules/spotify.py
index 79ffc85f..eef89b15 100644
--- a/modules/spotify.py
+++ b/modules/spotify.py
@@ -1,5 +1,5 @@
import json
-import Utils
+from src import Utils
URL_SPOTIFY = "https://api.spotify.com/v1/search"
diff --git a/modules/stats.py b/modules/stats.py
index af6393c5..867d7577 100644
--- a/modules/stats.py
+++ b/modules/stats.py
@@ -1,5 +1,5 @@
import time
-import Utils
+from src import Utils
class Module(object):
def __init__(self, bot, events, exports):
diff --git a/modules/tfl.py b/modules/tfl.py
index 1f9a9897..3efb85b9 100644
--- a/modules/tfl.py
+++ b/modules/tfl.py
@@ -1,5 +1,5 @@
import collections, datetime, re
-import Utils
+from src import Utils
URL_BUS = "https://api.tfl.gov.uk/StopPoint/%s/Arrivals"
URL_BUS_SEARCH = "https://api.tfl.gov.uk/StopPoint/Search/%s"
diff --git a/modules/thesaurus.py b/modules/thesaurus.py
index e0f5f009..9328a330 100644
--- a/modules/thesaurus.py
+++ b/modules/thesaurus.py
@@ -1,6 +1,6 @@
#--require-config bighugethesaurus-api-key
-import Utils
+from src import Utils
URL_THESAURUS = "http://words.bighugelabs.com/api/2/%s/%s/json"
diff --git a/modules/title.py b/modules/title.py
index 6684c936..6dc4cc4e 100644
--- a/modules/title.py
+++ b/modules/title.py
@@ -1,5 +1,5 @@
import re
-import Utils
+from src import Utils
REGEX_URL = re.compile("https?://\S+", re.I)
diff --git a/modules/to.py b/modules/to.py
index 22b9c7ac..8ff51ffe 100644
--- a/modules/to.py
+++ b/modules/to.py
@@ -1,4 +1,4 @@
-import EventManager
+from src import EventManager
class Module(object):
def __init__(self, bot, events, exports):
diff --git a/modules/trakt.py b/modules/trakt.py
index 203cfae8..57f4bce1 100644
--- a/modules/trakt.py
+++ b/modules/trakt.py
@@ -1,6 +1,6 @@
#--require-config trakt-api-key
-import Utils
+from src import Utils
URL_TRAKT = "https://api-v2launch.trakt.tv/users/%s/watching"
URL_TRAKTSLUG = "https://trakt.tv/%s/%s"
diff --git a/modules/translate.py b/modules/translate.py
index 55ba6d65..fd2c2c07 100644
--- a/modules/translate.py
+++ b/modules/translate.py
@@ -1,5 +1,5 @@
import json, re
-import Utils
+from src import Utils
URL_TRANSLATE = "http://translate.googleapis.com/translate_a/single"
URL_LANGUAGES = "https://cloud.google.com/translate/docs/languages"
diff --git a/modules/tweets.py b/modules/tweets.py
index 7b8a69fc..9995293a 100644
--- a/modules/tweets.py
+++ b/modules/tweets.py
@@ -5,7 +5,7 @@
import datetime, re, time, traceback
import twitter
-import Utils
+from src import Utils
REGEX_TWITTERURL = re.compile(
"https?://(?:www\.)?twitter.com/[^/]+/status/(\d+)", re.I)
diff --git a/modules/upc.py b/modules/upc.py
index 53266896..0e47801f 100644
--- a/modules/upc.py
+++ b/modules/upc.py
@@ -1,4 +1,4 @@
-import Utils
+from src import Utils
UPCITEMDB_URL = "https://api.upcitemdb.com/prod/trial/lookup"
diff --git a/modules/urbandictionary.py b/modules/urbandictionary.py
index a937dc9b..bb0f7918 100644
--- a/modules/urbandictionary.py
+++ b/modules/urbandictionary.py
@@ -1,5 +1,5 @@
import json, re
-import Utils
+from src import Utils
URL_URBANDICTIONARY = "http://api.urbandictionary.com/v0/define"
REGEX_DEFNUMBER = re.compile("-n(\d+) \S+")
diff --git a/modules/weather.py b/modules/weather.py
index db06956c..e79d1ad8 100644
--- a/modules/weather.py
+++ b/modules/weather.py
@@ -1,6 +1,6 @@
#--require-config openweathermap-api-key
-import Utils
+from src import Utils
URL_WEATHER = "http://api.openweathermap.org/data/2.5/weather"
diff --git a/modules/wikipedia.py b/modules/wikipedia.py
index 98dcab28..ffe9473d 100644
--- a/modules/wikipedia.py
+++ b/modules/wikipedia.py
@@ -1,4 +1,4 @@
-import Utils
+from src import Utils
URL_WIKIPEDIA = "https://en.wikipedia.org/w/api.php"
diff --git a/modules/wolframalpha.py b/modules/wolframalpha.py
index e1a995a2..90bff060 100644
--- a/modules/wolframalpha.py
+++ b/modules/wolframalpha.py
@@ -1,6 +1,6 @@
#--require-config wolframalpha-api-key
import json
-import Utils
+from src import Utils
URL_WA = "https://api.wolframalpha.com/v1/result"
diff --git a/modules/words.py b/modules/words.py
index 42ac3634..55f2fd9d 100644
--- a/modules/words.py
+++ b/modules/words.py
@@ -1,5 +1,5 @@
import time
-import Utils
+from src import Utils
class Module(object):
def __init__(self, bot, events, exports):
diff --git a/modules/youtube.py b/modules/youtube.py
index c70e9ef8..1cd0f675 100644
--- a/modules/youtube.py
+++ b/modules/youtube.py
@@ -1,7 +1,7 @@
#--require-config google-api-key
import re
-import Utils
+from src import Utils
REGEX_YOUTUBE = re.compile(
"https?://(?:www.)?(?:youtu.be/|youtube.com/watch\?[\S]*v=)([\w\-]{11})",
diff --git a/Config.py b/src/Config.py
index 894c9eb0..71e01871 100644
--- a/Config.py
+++ b/src/Config.py
@@ -1,11 +1,10 @@
import configparser, os
class Config(object):
- def __init__(self, bot, location="bot.conf"):
+ def __init__(self, bot, directory, filename="bot.conf"):
self.bot = bot
- self.location = location
- self.full_location = os.path.join(bot.bot_directory,
- self.location)
+ self.filename = filename
+ self.full_location = os.path.join(directory, filename)
self.bot.config = {}
self.load_config()
diff --git a/Database.py b/src/Database.py
index 1e186025..dc87b004 100644
--- a/Database.py
+++ b/src/Database.py
@@ -239,11 +239,10 @@ class UserChannelSettings(Table):
[user_id, channel_id, setting.lower()])
class Database(object):
- def __init__(self, bot, location="bot.db"):
+ def __init__(self, bot, directory, filename="bot.db"):
self.bot = bot
- self.location = location
- self.full_location = os.path.join(bot.bot_directory,
- self.location)
+ self.filename = filename
+ self.full_location = os.path.join(directory, filename)
self.database = sqlite3.connect(self.full_location,
check_same_thread=False, isolation_level=None)
self.database.execute("PRAGMA foreign_keys = ON")
diff --git a/EventManager.py b/src/EventManager.py
index 604ae337..604ae337 100644
--- a/EventManager.py
+++ b/src/EventManager.py
diff --git a/Exports.py b/src/Exports.py
index 8baca50d..8baca50d 100644
--- a/Exports.py
+++ b/src/Exports.py
diff --git a/IRCBot.py b/src/IRCBot.py
index 536e01ee..b94d31d5 100644
--- a/IRCBot.py
+++ b/src/IRCBot.py
@@ -1,7 +1,6 @@
import os, select, sys, threading, time, traceback, uuid
-
-import EventManager, Exports, IRCLineHandler, IRCServer, Logging
-import ModuleManager, Timer
+from . import EventManager, Exports, IRCLineHandler, IRCServer, Logging
+from . import ModuleManager, Timer
class Bot(object):
def __init__(self):
@@ -14,15 +13,13 @@ class Bot(object):
self.servers = {}
self.running = True
self.poll = select.epoll()
- self._events = EventManager.EventHook(self)
- self._exports = Exports.Exports()
- self.modules = ModuleManager.ModuleManager(self, self._events,
- self._exports)
- self.log = Logging.Log(self)
- self.line_handler = IRCLineHandler.LineHandler(self, self._events)
self.timers = []
- self._events.on("timer.reconnect").hook(self.reconnect)
- self._events.on("boot.done").hook(self.setup_timers)
+
+ self._events = None
+ self._exports = None
+ self.modules = None
+ self.log = None
+ self.line_handler = None
def add_server(self, server_id, connect=True):
(_, alias, hostname, port, password, ipv4, tls, nickname,
diff --git a/IRCBuffer.py b/src/IRCBuffer.py
index e6bd24f9..12a82ada 100644
--- a/IRCBuffer.py
+++ b/src/IRCBuffer.py
@@ -1,5 +1,5 @@
import re
-import Utils
+from . import Utils
class BufferLine(object):
def __init__(self, sender, message, action, from_self):
diff --git a/IRCChannel.py b/src/IRCChannel.py
index ced8648f..31c3ee19 100644
--- a/IRCChannel.py
+++ b/src/IRCChannel.py
@@ -1,5 +1,5 @@
import uuid
-import IRCBuffer, Utils
+from . import IRCBuffer, Utils
class Channel(object):
def __init__(self, name, id, server, bot):
diff --git a/IRCLineHandler.py b/src/IRCLineHandler.py
index 062ff2d5..7d2336dc 100644
--- a/IRCLineHandler.py
+++ b/src/IRCLineHandler.py
@@ -1,5 +1,5 @@
import re, threading
-import Utils
+from . import Utils
RE_PREFIXES = re.compile(r"\bPREFIX=\((\w+)\)(\W+)(?:\b|$)")
RE_CHANMODES = re.compile(
diff --git a/IRCServer.py b/src/IRCServer.py
index 8bc2567f..d88cc38a 100644
--- a/IRCServer.py
+++ b/src/IRCServer.py
@@ -1,5 +1,5 @@
import collections, socket, ssl, sys, time
-import IRCChannel, IRCUser, Utils
+from . import IRCChannel, IRCUser, Utils
THROTTLE_LINES = 4
THROTTLE_SECONDS = 1
diff --git a/IRCUser.py b/src/IRCUser.py
index 02ecefa5..1b2fdbdc 100644
--- a/IRCUser.py
+++ b/src/IRCUser.py
@@ -1,5 +1,5 @@
import uuid
-import IRCBuffer, Utils
+from . import IRCBuffer, Utils
class User(object):
def __init__(self, nickname, id, server, bot):
diff --git a/Logging.py b/src/Logging.py
index 22d10711..3f5815d6 100644
--- a/Logging.py
+++ b/src/Logging.py
@@ -1,4 +1,4 @@
-import logging, logging.handlers, sys, time
+import logging, logging.handlers, os, sys, time
class BitBotFormatter(logging.Formatter):
def formatTime(self, record, datefmt=None):
@@ -14,7 +14,7 @@ class BitBotFormatter(logging.Formatter):
return s
class Log(object):
- def __init__(self, bot):
+ def __init__(self, bot, directory, filename):
self.logger = logging.getLogger(__name__)
self.logger.setLevel(logging.DEBUG)
@@ -29,7 +29,7 @@ class Log(object):
self.logger.addHandler(stdout_handler)
file_handler = logging.handlers.TimedRotatingFileHandler(
- "bot.log", when="midnight", backupCount=5)
+ os.path.join(directory, filename), when="midnight", backupCount=5)
file_handler.setLevel(logging.DEBUG)
file_handler.setFormatter(formatter)
self.logger.addHandler(file_handler)
diff --git a/ModuleManager.py b/src/ModuleManager.py
index a9d9f7d4..2a3ae713 100644
--- a/ModuleManager.py
+++ b/src/ModuleManager.py
@@ -24,7 +24,7 @@ class BaseModule(object):
pass
class ModuleManager(object):
- def __init__(self, bot, events, exports, directory="modules"):
+ def __init__(self, bot, events, exports, directory):
self.bot = bot
self.events = events
self.exports = exports
@@ -109,7 +109,7 @@ class ModuleManager(object):
raise
except Exception as e:
self.bot.log.error("Failed to load module \"%s\": %s",
- [name, e.msg])
+ [name, str(e)])
raise
self.modules[module._import_name] = module
diff --git a/Timer.py b/src/Timer.py
index 7ac83630..7ac83630 100644
--- a/Timer.py
+++ b/src/Timer.py
diff --git a/Utils.py b/src/Utils.py
index 40445606..cd0e0cfa 100644
--- a/Utils.py
+++ b/src/Utils.py
@@ -1,7 +1,7 @@
import json, re, traceback, urllib.request, urllib.parse, urllib.error, ssl
import string
import bs4
-import ModuleManager
+from . import ModuleManager
USER_AGENT = ("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 "
"(KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36")
diff --git a/start.py b/start.py
index 04defccb..53b08023 100755
--- a/start.py
+++ b/start.py
@@ -1,7 +1,8 @@
#!/usr/bin/env python3
-import argparse, sys, time
-import IRCBot, Config, Database
+import argparse, os, sys, time
+from src import Config, Database, EventManager, Exports, IRCBot
+from src import IRCLineHandler, Logging, ModuleManager
def bool_input(s):
result = input("%s (Y/n): " % s)
@@ -17,20 +18,29 @@ arg_parser.add_argument("--verbose", "-v", action="store_true")
args = arg_parser.parse_args()
+directory = os.path.dirname(os.path.realpath(__file__))
+
bot = IRCBot.Bot()
-database = Database.Database(bot, args.database)
-config = Config.Config(bot, args.config)
-bot.database = database
-bot.config = config.load_config()
+bot._events = events = EventManager.EventHook(bot)
+bot._exports = exports = Exports.Exports()
+bot.modules = modules = ModuleManager.ModuleManager(bot, events, exports,
+ os.path.join(directory, "modules"))
+bot.line_handler = IRCLineHandler.LineHandler(bot, bot._events)
+bot.log = Logging.Log(bot, directory, "bot.log")
+bot.database = Database.Database(bot, directory, args.database)
+bot.config = Config.Config(bot, directory, args.config).load_config()
bot.args = args
+bot._events.on("timer.reconnect").hook(bot.reconnect)
+bot._events.on("boot.done").hook(bot.setup_timers)
+
whitelist = bot.get_setting("module-whitelist", [])
blacklist = bot.get_setting("module-blacklist", [])
bot.modules.load_modules(whitelist=whitelist, blacklist=blacklist)
servers = []
-for server_id, alias in database.servers.get_all():
+for server_id, alias in bot.database.servers.get_all():
server = bot.add_server(server_id, connect=False)
if not server == None:
servers.append(server)
@@ -54,7 +64,7 @@ else:
nickname = input("nickname: ")
username = input("username: ")
realname = input("realname: ")
- database.servers.add(alias, hostname, port, password, ipv4,
+ bot.database.servers.add(alias, hostname, port, password, ipv4,
tls, nickname, username, realname)
except KeyboardInterrupt:
print()