2016-03-29 11:56:58 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2018-09-24 14:13:27 +00:00
|
|
|
import argparse, os, sys, time
|
2018-09-29 11:53:39 +00:00
|
|
|
from src import Cache, Config, Database, EventManager, Exports, IRCBot
|
2018-09-30 18:43:20 +00:00
|
|
|
from src import Logging, ModuleManager, Timers
|
2016-03-29 11:56:58 +00:00
|
|
|
|
|
|
|
def bool_input(s):
|
|
|
|
result = input("%s (Y/n): " % s)
|
|
|
|
return not result or result[0].lower() in ["", "y"]
|
|
|
|
|
2018-09-27 10:07:29 +00:00
|
|
|
directory = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
|
2016-03-31 12:20:56 +00:00
|
|
|
arg_parser = argparse.ArgumentParser(
|
2018-09-27 10:07:29 +00:00
|
|
|
description="Python3 event-driven modular IRC bot")
|
|
|
|
|
|
|
|
arg_parser.add_argument("--config", "-c",
|
|
|
|
help="Location of the JSON config file",
|
|
|
|
default=os.path.join(directory, "bot.conf"))
|
|
|
|
|
|
|
|
arg_parser.add_argument("--database", "-d",
|
|
|
|
help="Location of the sqlite3 database file",
|
|
|
|
default=os.path.join(directory, "databases", "bot.db"))
|
|
|
|
|
|
|
|
arg_parser.add_argument("--log", "-l",
|
|
|
|
help="Location of the main log file",
|
|
|
|
default=os.path.join(directory, "logs", "bot.log"))
|
|
|
|
|
2017-01-27 21:41:47 +00:00
|
|
|
arg_parser.add_argument("--verbose", "-v", action="store_true")
|
|
|
|
|
2016-03-31 12:20:56 +00:00
|
|
|
args = arg_parser.parse_args()
|
|
|
|
|
2018-09-28 15:51:36 +00:00
|
|
|
|
2018-09-27 10:07:29 +00:00
|
|
|
log = Logging.Log(args.log)
|
2018-09-29 11:53:39 +00:00
|
|
|
cache = Cache.Cache()
|
2018-09-28 15:51:36 +00:00
|
|
|
config = Config.Config(args.config)
|
2018-09-27 10:07:29 +00:00
|
|
|
database = Database.Database(log, args.database)
|
|
|
|
events = events = EventManager.EventHook(log)
|
|
|
|
exports = exports = Exports.Exports()
|
2018-09-28 16:01:20 +00:00
|
|
|
timers = Timers.Timers(database, events, log)
|
2018-09-28 15:51:36 +00:00
|
|
|
modules = modules = ModuleManager.ModuleManager(events, exports, config, log,
|
2018-09-24 14:13:27 +00:00
|
|
|
os.path.join(directory, "modules"))
|
2018-09-27 10:07:29 +00:00
|
|
|
|
2018-09-29 11:53:39 +00:00
|
|
|
bot = IRCBot.Bot(directory, args, cache, config, database, events,
|
2018-09-30 18:43:20 +00:00
|
|
|
exports, log, modules, timers)
|
2018-09-24 14:13:27 +00:00
|
|
|
|
2018-09-13 12:35:05 +00:00
|
|
|
whitelist = bot.get_setting("module-whitelist", [])
|
|
|
|
blacklist = bot.get_setting("module-blacklist", [])
|
2018-09-28 15:51:36 +00:00
|
|
|
modules.load_modules(bot, whitelist=whitelist, blacklist=blacklist)
|
2016-03-29 11:56:58 +00:00
|
|
|
|
2018-07-02 11:08:26 +00:00
|
|
|
servers = []
|
2018-09-24 14:13:27 +00:00
|
|
|
for server_id, alias in bot.database.servers.get_all():
|
2018-09-21 10:34:38 +00:00
|
|
|
server = bot.add_server(server_id, connect=False)
|
2018-07-02 11:08:26 +00:00
|
|
|
if not server == None:
|
|
|
|
servers.append(server)
|
|
|
|
if len(servers):
|
2018-09-19 12:25:12 +00:00
|
|
|
bot._events.on("boot.done").call()
|
2018-09-28 15:51:36 +00:00
|
|
|
|
|
|
|
bot.timers.setup(bot.find_settings_prefix("timer-"))
|
|
|
|
|
2018-07-02 11:08:26 +00:00
|
|
|
for server in servers:
|
|
|
|
if not bot.connect(server):
|
|
|
|
sys.stderr.write("failed to connect to '%s', exiting\r\n" % (
|
|
|
|
str(server)))
|
|
|
|
sys.exit(1)
|
|
|
|
bot.run()
|
2016-03-29 11:56:58 +00:00
|
|
|
else:
|
|
|
|
try:
|
|
|
|
if bool_input("no servers found, add one?"):
|
2018-09-23 09:40:19 +00:00
|
|
|
alias = input("alias: ")
|
2016-03-29 11:56:58 +00:00
|
|
|
hostname = input("hostname: ")
|
|
|
|
port = int(input("port: "))
|
|
|
|
tls = bool_input("tls?")
|
|
|
|
password = input("password?: ")
|
|
|
|
ipv4 = bool_input("ipv4?")
|
|
|
|
nickname = input("nickname: ")
|
|
|
|
username = input("username: ")
|
|
|
|
realname = input("realname: ")
|
2018-09-24 14:13:27 +00:00
|
|
|
bot.database.servers.add(alias, hostname, port, password, ipv4,
|
2016-03-29 11:56:58 +00:00
|
|
|
tls, nickname, username, realname)
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
print()
|
|
|
|
pass
|