Selaa lähdekoodia

Added rolling functionality

Kirk Trombley 6 vuotta sitten
vanhempi
commit
29b0d7b67d
5 muutettua tiedostoa jossa 21 lisäystä ja 8 poistoa
  1. 0 5
      README.md
  2. 0 2
      TODO_commands
  3. 1 0
      config/config.toml
  4. 2 1
      requirements.txt
  5. 18 0
      src/plugins/roll.py

+ 0 - 5
README.md

@@ -7,8 +7,3 @@
 # Deploy
 
     `docker run -p6070:6070 --name rollbot3-instance -d rollbot3`
-
-# Or, run locally
-
-    `cd src/`
-    `ROLLBOT_CFG_DIR=../config python3 app.py`

+ 0 - 2
TODO_commands

@@ -1,6 +1,4 @@
 old:
-roll
-session
 seychelles
 inspire
 pokemon

+ 1 - 0
config/config.toml

@@ -4,6 +4,7 @@ database = "/tmp/rollbot.sqlite"
 simple = [ "info", "isadmin", "debug", "echo", "thanks", "guess", "meme", "unmeme", "greet", "console" ]
 teamspeak = [ "teamspeak" ]
 session = [ "session" ]
+roll = [ "roll" ]
 
 [teamspeak]
 host = "kirkleon.ddns.net"

+ 2 - 1
requirements.txt

@@ -2,4 +2,5 @@ toml
 sqlalchemy
 Flask
 gunicorn
-requests
+requests
+dice

+ 18 - 0
src/plugins/roll.py

@@ -0,0 +1,18 @@
+import dice
+
+from command_system import RollbotResponse, as_plugin
+
+
+@as_plugin
+def roll(db, message):
+    argstr = message.raw_args
+    try:
+        rolls = []
+        for roll_exp in argstr.split(","):
+            roll = dice.roll(roll_exp)
+            if not isinstance(roll, int):
+                roll = int(roll)
+            rolls.append(str(roll))
+        return RollbotResponse(message, txt="Rolled {}, got: {}".format(argstr, ", ".join(rolls)))
+    except Exception as _:
+        return RollbotResponse(message, txt="Sorry - dice expression appears malformed. Add more ()'s")