From fd75b712868b30ebb74714875c8d7437e4a1dbd6 Mon Sep 17 00:00:00 2001 From: jesopo Date: Fri, 27 Jan 2017 21:41:47 +0000 Subject: [PATCH] Adds args.verbose and fixes a couple of bug --- IRCBot.py | 15 +++++++++------ start.py | 7 +++++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/IRCBot.py b/IRCBot.py index be1fac9c..36f3b789 100644 --- a/IRCBot.py +++ b/IRCBot.py @@ -4,6 +4,7 @@ import EventManager, IRCServer, ModuleManager, Timer class Bot(object): def __init__(self): self.lock = threading.Lock() + self.args = None self.database = None self.config = None self.bot_directory = os.path.dirname(os.path.realpath(__file__)) @@ -39,7 +40,9 @@ class Bot(object): def connect_all(self): for server in self.servers.values(): if server.get_setting("connect", True): - self.connect(server) + if not self.connect(server): + return False + return True def setup_timers(self, event): for setting, value in self.find_settings("timer-%"): @@ -58,7 +61,7 @@ class Bot(object): timer = Timer.Timer(self, event_name, delay, next_due, **kwargs) if id: timer.id = id - else: + elif persist: self.timer_setting(timer) self.timers.append(timer) def next_timer(self): @@ -67,15 +70,14 @@ class Bot(object): time_left = timer.time_left() if not next or time_left < next: next = time_left - return next or 30 + + return next if not next == None and next <= 30 else 30; def call_timers(self): for timer in self.timers[:]: if timer.due(): timer.call() if timer.done(): self.timer_setting_remove(timer) - else: - self.timer_setting(timer) def register_read(self, server): self.poll.modify(server.fileno(), select.EPOLLIN) @@ -124,7 +126,8 @@ class Bot(object): if event & select.EPOLLIN: lines = server.read() for line in lines: - print(line) + if self.args.verbose: + print(line) server.parse_line(line) elif event & select.EPOLLOUT: server._send() diff --git a/start.py b/start.py index 748a5089..848a2a08 100755 --- a/start.py +++ b/start.py @@ -13,6 +13,8 @@ arg_parser.add_argument("--config", "-c", default="bot.json", help="Location of the JSON config file") arg_parser.add_argument("--database", "-d", default="bot.db", help="Location of the sqlite3 database file") +arg_parser.add_argument("--verbose", "-v", action="store_true") + args = arg_parser.parse_args() bot = IRCBot.Bot() @@ -20,6 +22,7 @@ database = Database.Database(bot, args.database) config_object = Config.Config(bot, args.config) bot.database = database bot.config_object = config_object +bot.args = args bot.modules.load_modules() servers = database.get_servers() @@ -28,8 +31,8 @@ for server in servers: if len(bot.servers): bot.events.on("boot").on("done").call() time.sleep(5) - bot.connect_all() - bot.run() + if bot.connect_all(): + bot.run() else: try: if bool_input("no servers found, add one?"):