2016-03-29 11:56:58 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2018-07-02 11:08:26 +00:00
|
|
|
import argparse, sys, time
|
2016-03-29 11:56:58 +00:00
|
|
|
import IRCBot, Config, Database
|
|
|
|
|
|
|
|
def bool_input(s):
|
|
|
|
result = input("%s (Y/n): " % s)
|
|
|
|
return not result or result[0].lower() in ["", "y"]
|
|
|
|
|
2016-03-31 12:20:56 +00:00
|
|
|
arg_parser = argparse.ArgumentParser(
|
|
|
|
description="Python3 event-driven asynchronous modular IRC bot")
|
2018-07-15 23:45:32 +00:00
|
|
|
arg_parser.add_argument("--config", "-c", default="bot.conf",
|
2016-03-31 12:20:56 +00:00
|
|
|
help="Location of the JSON config file")
|
|
|
|
arg_parser.add_argument("--database", "-d", default="bot.db",
|
|
|
|
help="Location of the sqlite3 database file")
|
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()
|
|
|
|
|
2016-03-29 11:56:58 +00:00
|
|
|
bot = IRCBot.Bot()
|
2016-03-31 12:20:56 +00:00
|
|
|
database = Database.Database(bot, args.database)
|
2018-08-30 10:40:41 +00:00
|
|
|
config = Config.Config(bot, args.config)
|
|
|
|
|
2016-03-29 11:56:58 +00:00
|
|
|
bot.database = database
|
2018-08-30 10:40:41 +00:00
|
|
|
bot.config = config.load_config()
|
2017-01-27 21:41:47 +00:00
|
|
|
bot.args = args
|
2018-08-30 10:41:02 +00:00
|
|
|
|
|
|
|
whitelist = bot.config.get("module_whitelist", None)
|
|
|
|
if not whitelist == None:
|
|
|
|
whitelist = whitelist.split(",")
|
|
|
|
bot.modules.load_modules(whitelist=whitelist)
|
2016-03-29 11:56:58 +00:00
|
|
|
|
2018-08-05 21:41:38 +00:00
|
|
|
server_details = database.servers.get_all()
|
2018-07-02 11:08:26 +00:00
|
|
|
servers = []
|
|
|
|
for server_detail in server_details:
|
|
|
|
server = bot.add_server(*server_detail)
|
|
|
|
if not server == None:
|
|
|
|
servers.append(server)
|
|
|
|
if len(servers):
|
2016-03-29 11:56:58 +00:00
|
|
|
bot.events.on("boot").on("done").call()
|
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?"):
|
|
|
|
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-08-30 16:12:37 +00:00
|
|
|
database.servers.add(hostname, port, password, ipv4,
|
2016-03-29 11:56:58 +00:00
|
|
|
tls, nickname, username, realname)
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
print()
|
|
|
|
pass
|