useless: fix syntax warning
storage: shorten code
This commit is contained in:
parent
e03f5d0a43
commit
80cfa2f815
@ -15,28 +15,26 @@ class DBConn:
|
||||
|
||||
def _reconnect(self):
|
||||
self._con = psycopg2.connect(*self.args, **self.kwargs)
|
||||
return self._con
|
||||
|
||||
def commit(self, *args, **kwargs):
|
||||
try:
|
||||
return self._con.commit(*args, **kwargs)
|
||||
except psycopg2.InterfaceError:
|
||||
self._reconnect()
|
||||
return self._con.commit(*args, **kwargs)
|
||||
return self._reconnect().commit(*args, **kwargs)
|
||||
|
||||
def rollback(self, *args, **kwargs):
|
||||
try:
|
||||
return self._con.rollback(*args, **kwargs)
|
||||
except psycopg2.InterfaceError:
|
||||
self._reconnect()
|
||||
return self._con.rollback(*args, **kwargs)
|
||||
return self._reconnect().rollback(*args, **kwargs)
|
||||
|
||||
@contextlib.contextmanager
|
||||
def cursor(self, *args, **kwargs):
|
||||
try:
|
||||
yield self._con.cursor(cursor_factory=DictCursor, *args, **kwargs)
|
||||
except psycopg2.InterfaceError:
|
||||
self._reconnect()
|
||||
yield self._con.cursor(cursor_factory=DictCursor, *args, **kwargs)
|
||||
yield self._reconnect().cursor(cursor_factory=DictCursor, *args, **kwargs)
|
||||
|
||||
|
||||
class Storage(Plugin):
|
||||
|
@ -114,7 +114,7 @@ class Useless(DatabasePlugin):
|
||||
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<target>\S+) :.*(woah|whoa).*$')
|
||||
def woah(self, target: str):
|
||||
"""Colorize words in a sentence with rainbow colors."""
|
||||
if random.randint(0, 4) is 0:
|
||||
if random.randint(0, 4) == 0:
|
||||
self.bot.privmsg(target, random.choice(self.WOAH))
|
||||
|
||||
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<target>\S+) :(?P<msg>huehuehue)$')
|
||||
|
Loading…
Reference in New Issue
Block a user