fixed singlethread reloading, and functional database system (still no ORM usage)
This commit is contained in:
parent
cdc9102694
commit
2ebb30d2d7
4 changed files with 16 additions and 9 deletions
|
@ -110,7 +110,7 @@ class PluginLoader(object):
|
||||||
# stop all currently running instances of the plugins from this file
|
# stop all currently running instances of the plugins from this file
|
||||||
for func, handler in list(self.bot.threads.iteritems()):
|
for func, handler in list(self.bot.threads.iteritems()):
|
||||||
if func._filename == filename:
|
if func._filename == filename:
|
||||||
main.handler.stop()
|
handler.stop()
|
||||||
del self.bot.threads[func]
|
del self.bot.threads[func]
|
||||||
|
|
||||||
self.rebuild()
|
self.rebuild()
|
||||||
|
|
|
@ -124,12 +124,16 @@ class Handler(object):
|
||||||
break
|
break
|
||||||
|
|
||||||
if uses_db:
|
if uses_db:
|
||||||
input.db = None
|
input.db = input.bot.db_session()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
run(self.bot, self.func, input)
|
run(self.bot, self.func, input)
|
||||||
except:
|
except:
|
||||||
self.bot.logger.exception("Error in plugin {}:".format(self.func._filename))
|
self.bot.logger.exception("Error in plugin {}:".format(self.func._filename))
|
||||||
|
finally:
|
||||||
|
if uses_db:
|
||||||
|
print "Closett"
|
||||||
|
input.db.close()
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.input_queue.put(StopIteration)
|
self.input_queue.put(StopIteration)
|
||||||
|
|
|
@ -29,8 +29,8 @@ def horoscope(inp, db=None, notice=None, nick=None):
|
||||||
db.execute("create table if not exists horoscope(nick primary key, sign)")
|
db.execute("create table if not exists horoscope(nick primary key, sign)")
|
||||||
|
|
||||||
if not sign:
|
if not sign:
|
||||||
sign = db.execute("select sign from horoscope where nick=lower(?)",
|
sign = db.execute("select sign from horoscope where nick=lower(:nick)",
|
||||||
(nick,)).fetchone()
|
{'nick':nick}).fetchone()
|
||||||
if not sign:
|
if not sign:
|
||||||
notice("horoscope <sign> -- Get your horoscope")
|
notice("horoscope <sign> -- Get your horoscope")
|
||||||
return
|
return
|
||||||
|
@ -49,8 +49,8 @@ def horoscope(inp, db=None, notice=None, nick=None):
|
||||||
return "Could not get the horoscope for {}.".format(inp)
|
return "Could not get the horoscope for {}.".format(inp)
|
||||||
|
|
||||||
if inp and not dontsave:
|
if inp and not dontsave:
|
||||||
db.execute("insert or replace into horoscope(nick, sign) values (?,?)",
|
db.execute("insert or replace into horoscope(nick, sign) values (:nick,:sign)",
|
||||||
(nick.lower(), sign))
|
{'nick':nick.lower(), 'sign': sign})
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
|
@ -27,8 +27,11 @@ def seen_sieve(paraml, input=None, db=None):
|
||||||
# keep private messages private
|
# keep private messages private
|
||||||
if input.chan[:1] == "#" and not re.findall('^s/.*/.*/$', input.msg.lower()):
|
if input.chan[:1] == "#" and not re.findall('^s/.*/.*/$', input.msg.lower()):
|
||||||
db.execute("insert or replace into seen_user(name, time, quote, chan, host)"
|
db.execute("insert or replace into seen_user(name, time, quote, chan, host)"
|
||||||
"values(?,?,?,?,?)", (input.nick.lower(), time.time(), input.msg,
|
"values(:name,:time,:quote,:chan,:host)", {'name': input.nick.lower(),
|
||||||
input.chan, input.mask))
|
'time': time.time(),
|
||||||
|
'quote': input.msg,
|
||||||
|
'chan': input.chan,
|
||||||
|
'host': input.mask})
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,7 +52,7 @@ def seen(inp, nick='', chan='', db=None, input=None):
|
||||||
db_init(db)
|
db_init(db)
|
||||||
|
|
||||||
last_seen = db.execute("select name, time, quote from seen_user where name"
|
last_seen = db.execute("select name, time, quote from seen_user where name"
|
||||||
" like ? and chan = ?", (inp, chan)).fetchone()
|
" like :name and chan = :chan", {'name': inp, 'chan': chan}).fetchone()
|
||||||
|
|
||||||
if last_seen:
|
if last_seen:
|
||||||
reltime = timesince.timesince(last_seen[1])
|
reltime = timesince.timesince(last_seen[1])
|
||||||
|
|
Reference in a new issue