Adds tetris highscore

This commit is contained in:
nikolark committed 2012-11-15 17:37:32 +01:00
1 parent e8fcd048fe
commit c3d415c92f
1 file changed
+21
+21
View File
@@ -100,6 +100,7 @@ class IRCActions():
self.bot = bot
if not settings.DISABLE_LOG:
self.dbpool = self._get_dbpool()
self.tetris_dbpool = self._get_tetris_dbpool()
def _get_dbpool(self):
# Setup an async db connection
@@ -109,6 +110,14 @@ class IRCActions():
charset="utf8", use_unicode=True,
cp_reconnect=True)
def _get_tetris_dbpool(self):
# Setup an async db connection
return ReconnectingConnectionPool(settings.DB_API_ADAPTER,
host=settings.TETRIS_DB_HOST, user=settings.TETRIS_DB_USER,
passwd=settings.TETRIS_DB_PASSWORD, db=settings.TETRIS_DB_NAME,
charset="utf8", use_unicode=True,
cp_reconnect=True)
def ping(self, host):
# TODO rewrite async
try:
@@ -157,6 +166,9 @@ class IRCActions():
elif parts[0] == "lastlog" and len(parts) == 1 and not settings.DISABLE_LOG:
# ...same as above
self.get_lastlog().addCallback(self.msg_lastlog, channel, nick)
elif parts[0] == "tetrishigh" and len(parts) == 1 and not settings.DISABLE_TETRIS:
self.get_tetris_highscore().addCallback(self.msg_tetris_highscore, channel, nick)
else:
self.bot.msgReply(nick, channel, "Need !help " + nick + "?")
@@ -178,6 +190,15 @@ class IRCActions():
string_entry = str(i) + ": " + entry[2] + " (" + entry[1] + ", " + str(entry[3]) + ")"
self.bot.msgReply(nick, channel, string_entry.encode("utf-8"))
def get_tetris_highscore(self):
sql = "SELECT * FROM highscore ORDER BY score DESC LIMIT 1"
return self.tetris_dbpool.runQuery(sql)
def msg_tetris_highscore(self, highscore, channel, nick):
h_id,score,name,time,ip,country = highscore[0]
string_highscore = "Tetris AI highscore: " + str(score) + " by " + name + "."
self.bot.msgReply(nick, channel, string_highscore.encode("utf-8"))
class ReconnectingConnectionPool(adbapi.ConnectionPool):
"""Reconnecting adbapi connection pool for MySQL.