|
@@ -1,10 +1,12 @@
|
|
|
import datetime
|
|
|
import re
|
|
|
import base64
|
|
|
+import logging
|
|
|
|
|
|
from sqlalchemy import Column, Integer, String, DateTime
|
|
|
|
|
|
-from command_system import as_plugin, RollbotResponse, RollbotFailure, ModelBase, pop_arg
|
|
|
+from command_system import RollbotPlugin, RollbotResponse, RollbotFailure, ModelBase, pop_arg
|
|
|
+from config import get_secret
|
|
|
|
|
|
|
|
|
GUY_STAGES = [
|
|
@@ -271,18 +273,20 @@ def render_game(game_state, guy_state):
|
|
|
"Bad Guesses: " + ", ".join(game_state.bad_guesses)
|
|
|
|
|
|
|
|
|
-def handle_in_game(db, msg, game_state, guy_state):
|
|
|
+def handle_in_game(bot, db, msg, game_state, guy_state):
|
|
|
if msg.raw_args.startswith("!"):
|
|
|
subc = msg.raw_args[1:].strip().lower()
|
|
|
if subc == "cancel":
|
|
|
end_game(game_state)
|
|
|
return RollbotResponse(msg, txt="The game has been cancelled. The guy has not been reset.")
|
|
|
+ elif subc == "alert":
|
|
|
+ return subc_alert(bot, msg)
|
|
|
else:
|
|
|
return RollbotResponse(
|
|
|
msg,
|
|
|
failure=RollbotFailure.INVALID_SUBCOMMAND,
|
|
|
debugging=dict(
|
|
|
- explain="The only in-game subcommand is !cancel to end the game"
|
|
|
+ explain="The only in-game subcommands are !cancel to end the game and !alert to alert the main chat."
|
|
|
)
|
|
|
)
|
|
|
|
|
@@ -332,8 +336,12 @@ def subc_retire(db, guy_state):
|
|
|
return txt
|
|
|
|
|
|
|
|
|
-@as_plugin("hangguy")
|
|
|
-def hangguy(db, msg):
|
|
|
+def subc_alert(bot, msg):
|
|
|
+ bot.manually_post_message(f"{msg.name} wants you to check out the hangguy chat!", get_secret("hangguy.alert_chat"))
|
|
|
+ return RollbotResponse(msg, respond=False)
|
|
|
+
|
|
|
+
|
|
|
+def hangguy(bot, db, msg):
|
|
|
game_state = get_game(db, msg.group_id)
|
|
|
guy_state = get_guy(db, msg.group_id)
|
|
|
|
|
@@ -341,14 +349,14 @@ def hangguy(db, msg):
|
|
|
return RollbotResponse(msg, failure=RollbotFailure.MISSING_SUBCOMMAND)
|
|
|
|
|
|
if game_is_active(game_state):
|
|
|
- return handle_in_game(db, msg, game_state, guy_state)
|
|
|
+ return handle_in_game(bot, db, msg, game_state, guy_state)
|
|
|
|
|
|
if not msg.raw_args.startswith("!"):
|
|
|
return RollbotResponse(
|
|
|
msg,
|
|
|
failure=RollbotFailure.MISSING_SUBCOMMAND,
|
|
|
debugging=dict(
|
|
|
- explain="You are not currently in a game, and so you must use one of the subcommands: !view, !retire, !start"
|
|
|
+ explain="You are not currently in a game, and so you must use one of the subcommands: !view, !retire, !start, !alert"
|
|
|
)
|
|
|
)
|
|
|
|
|
@@ -365,13 +373,23 @@ def hangguy(db, msg):
|
|
|
elif subc == "start":
|
|
|
init_game(game_state, rest)
|
|
|
return RollbotResponse(msg, txt=render_game(game_state, guy_state))
|
|
|
+ elif subc == "alert":
|
|
|
+ return subc_alert(bot, msg)
|
|
|
else:
|
|
|
return RollbotResponse(
|
|
|
msg,
|
|
|
failure=RollbotFailure.INVALID_SUBCOMMAND,
|
|
|
debugging=dict(
|
|
|
- explain="You must use one of the subcommands: !view, !retire, !start"
|
|
|
+ explain="You must use one of the subcommands: !view, !retire, !start, !alert"
|
|
|
)
|
|
|
)
|
|
|
|
|
|
return RollbotResponse(msg, txt="My first plugin!")
|
|
|
+
|
|
|
+
|
|
|
+class HangGuy(RollbotPlugin):
|
|
|
+ def __init__(self, bot, logger=logging.getLogger(__name__)):
|
|
|
+ RollbotPlugin.__init__(self, "hangguy", bot, logger=logger)
|
|
|
+
|
|
|
+ def on_command(self, db, msg):
|
|
|
+ return hangguy(self.bot, db, msg)
|