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):
|
class Bot(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.lock = threading.Lock()
|
self.lock = threading.Lock()
|
||||||
|
self.args = None
|
||||||
self.database = None
|
self.database = None
|
||||||
self.config = None
|
self.config = None
|
||||||
self.bot_directory = os.path.dirname(os.path.realpath(__file__))
|
self.bot_directory = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
@ -39,7 +40,9 @@ class Bot(object):
|
||||||
def connect_all(self):
|
def connect_all(self):
|
||||||
for server in self.servers.values():
|
for server in self.servers.values():
|
||||||
if server.get_setting("connect", True):
|
if server.get_setting("connect", True):
|
||||||
self.connect(server)
|
if not self.connect(server):
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
def setup_timers(self, event):
|
def setup_timers(self, event):
|
||||||
for setting, value in self.find_settings("timer-%"):
|
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)
|
timer = Timer.Timer(self, event_name, delay, next_due, **kwargs)
|
||||||
if id:
|
if id:
|
||||||
timer.id = id
|
timer.id = id
|
||||||
else:
|
elif persist:
|
||||||
self.timer_setting(timer)
|
self.timer_setting(timer)
|
||||||
self.timers.append(timer)
|
self.timers.append(timer)
|
||||||
def next_timer(self):
|
def next_timer(self):
|
||||||
|
@ -67,15 +70,14 @@ class Bot(object):
|
||||||
time_left = timer.time_left()
|
time_left = timer.time_left()
|
||||||
if not next or time_left < next:
|
if not next or time_left < next:
|
||||||
next = time_left
|
next = time_left
|
||||||
return next or 30
|
|
||||||
|
return next if not next == None and next <= 30 else 30;
|
||||||
def call_timers(self):
|
def call_timers(self):
|
||||||
for timer in self.timers[:]:
|
for timer in self.timers[:]:
|
||||||
if timer.due():
|
if timer.due():
|
||||||
timer.call()
|
timer.call()
|
||||||
if timer.done():
|
if timer.done():
|
||||||
self.timer_setting_remove(timer)
|
self.timer_setting_remove(timer)
|
||||||
else:
|
|
||||||
self.timer_setting(timer)
|
|
||||||
|
|
||||||
def register_read(self, server):
|
def register_read(self, server):
|
||||||
self.poll.modify(server.fileno(), select.EPOLLIN)
|
self.poll.modify(server.fileno(), select.EPOLLIN)
|
||||||
|
@ -124,6 +126,7 @@ class Bot(object):
|
||||||
if event & select.EPOLLIN:
|
if event & select.EPOLLIN:
|
||||||
lines = server.read()
|
lines = server.read()
|
||||||
for line in lines:
|
for line in lines:
|
||||||
|
if self.args.verbose:
|
||||||
print(line)
|
print(line)
|
||||||
server.parse_line(line)
|
server.parse_line(line)
|
||||||
elif event & select.EPOLLOUT:
|
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")
|
help="Location of the JSON config file")
|
||||||
arg_parser.add_argument("--database", "-d", default="bot.db",
|
arg_parser.add_argument("--database", "-d", default="bot.db",
|
||||||
help="Location of the sqlite3 database file")
|
help="Location of the sqlite3 database file")
|
||||||
|
arg_parser.add_argument("--verbose", "-v", action="store_true")
|
||||||
|
|
||||||
args = arg_parser.parse_args()
|
args = arg_parser.parse_args()
|
||||||
|
|
||||||
bot = IRCBot.Bot()
|
bot = IRCBot.Bot()
|
||||||
|
@ -20,6 +22,7 @@ database = Database.Database(bot, args.database)
|
||||||
config_object = Config.Config(bot, args.config)
|
config_object = Config.Config(bot, args.config)
|
||||||
bot.database = database
|
bot.database = database
|
||||||
bot.config_object = config_object
|
bot.config_object = config_object
|
||||||
|
bot.args = args
|
||||||
bot.modules.load_modules()
|
bot.modules.load_modules()
|
||||||
|
|
||||||
servers = database.get_servers()
|
servers = database.get_servers()
|
||||||
|
@ -28,7 +31,7 @@ for server in servers:
|
||||||
if len(bot.servers):
|
if len(bot.servers):
|
||||||
bot.events.on("boot").on("done").call()
|
bot.events.on("boot").on("done").call()
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
bot.connect_all()
|
if bot.connect_all():
|
||||||
bot.run()
|
bot.run()
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue