Adds args.verbose and fixes a couple of bug
This commit is contained in:
parent
ec4036a501
commit
fd75b71286
2 changed files with 14 additions and 8 deletions
13
IRCBot.py
13
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,6 +126,7 @@ class Bot(object):
|
|||
if event & select.EPOLLIN:
|
||||
lines = server.read()
|
||||
for line in lines:
|
||||
if self.args.verbose:
|
||||
print(line)
|
||||
server.parse_line(line)
|
||||
elif event & select.EPOLLOUT:
|
||||
|
|
5
start.py
5
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,7 +31,7 @@ for server in servers:
|
|||
if len(bot.servers):
|
||||
bot.events.on("boot").on("done").call()
|
||||
time.sleep(5)
|
||||
bot.connect_all()
|
||||
if bot.connect_all():
|
||||
bot.run()
|
||||
else:
|
||||
try:
|
||||
|
|
Loading…
Reference in a new issue