|
4 | 4 | from time import time |
5 | 5 |
|
6 | 6 | from sqlalchemy import Table, Column, String, Integer, PrimaryKeyConstraint, desc, Boolean |
| 7 | +from sqlalchemy.exc import DatabaseError |
7 | 8 | from sqlalchemy.sql import select |
8 | 9 |
|
9 | 10 | from cloudbot import hook |
@@ -318,17 +319,22 @@ def bang(nick, chan, message, db, conn, notice): |
318 | 319 | else: |
319 | 320 | message(out) |
320 | 321 | game_status[network][chan]['duck_status'] = 2 |
321 | | - score = db.execute(select([table.c.shot]) \ |
322 | | - .where(table.c.network == conn.name) \ |
323 | | - .where(table.c.chan == chan.lower()) \ |
324 | | - .where(table.c.name == nick.lower())).fetchone() |
325 | | - if score: |
326 | | - score = score[0] |
327 | | - score += 1 |
328 | | - dbupdate(nick, chan, db, conn, score, 0) |
329 | | - else: |
330 | | - score = 1 |
331 | | - dbadd_entry(nick, chan, db, conn, score, 0) |
| 322 | + try: |
| 323 | + score = db.execute(select([table.c.shot]) |
| 324 | + .where(table.c.network == conn.name) |
| 325 | + .where(table.c.chan == chan.lower()) |
| 326 | + .where(table.c.name == nick.lower())).fetchone() |
| 327 | + if score: |
| 328 | + score = score[0] |
| 329 | + score += 1 |
| 330 | + dbupdate(nick, chan, db, conn, score, 0) |
| 331 | + else: |
| 332 | + score = 1 |
| 333 | + dbadd_entry(nick, chan, db, conn, score, 0) |
| 334 | + except DatabaseError: |
| 335 | + game_status[network][chan]['duck_status'] = 1 |
| 336 | + raise |
| 337 | + |
332 | 338 | timer = "{:.3f}".format(shoot - deploy) |
333 | 339 | duck = "duck" if score == 1 else "ducks" |
334 | 340 | message("{} you shot a duck in {} seconds! You have killed {} {} in {}.".format(nick, timer, score, duck, chan)) |
@@ -380,17 +386,22 @@ def befriend(nick, chan, message, db, conn, notice): |
380 | 386 | message(out) |
381 | 387 |
|
382 | 388 | game_status[network][chan]['duck_status'] = 2 |
383 | | - score = db.execute(select([table.c.befriend]) \ |
384 | | - .where(table.c.network == conn.name) \ |
385 | | - .where(table.c.chan == chan.lower()) \ |
386 | | - .where(table.c.name == nick.lower())).fetchone() |
387 | | - if score: |
388 | | - score = score[0] |
389 | | - score += 1 |
390 | | - dbupdate(nick, chan, db, conn, 0, score) |
391 | | - else: |
392 | | - score = 1 |
393 | | - dbadd_entry(nick, chan, db, conn, 0, score) |
| 389 | + try: |
| 390 | + score = db.execute(select([table.c.befriend]) |
| 391 | + .where(table.c.network == conn.name) |
| 392 | + .where(table.c.chan == chan.lower()) |
| 393 | + .where(table.c.name == nick.lower())).fetchone() |
| 394 | + if score: |
| 395 | + score = score[0] |
| 396 | + score += 1 |
| 397 | + dbupdate(nick, chan, db, conn, 0, score) |
| 398 | + else: |
| 399 | + score = 1 |
| 400 | + dbadd_entry(nick, chan, db, conn, 0, score) |
| 401 | + except DatabaseError: |
| 402 | + game_status[network][chan]['duck_status'] = 1 |
| 403 | + raise |
| 404 | + |
394 | 405 | duck = "duck" if score == 1 else "ducks" |
395 | 406 | timer = "{:.3f}".format(shoot - deploy) |
396 | 407 | message( |
|
0 commit comments