forked from lichess-bot-devs/lichess-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconversation.py
35 lines (28 loc) · 1.16 KB
/
conversation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from time import time
class Conversation():
def __init__(self, game, engine, xhr, version):
self.game = game
self.engine = engine
self.xhr = xhr
self.version = version
command_prefix = "!"
def react(self, line, game):
print("*** {} [{}] {}: {}".format(self.game.url(), line.room, line.username, line.text.encode("utf-8")))
if (line.text[0] == self.command_prefix):
self.command(line, game, line.text[1:].lower())
pass
def command(self, line, game, cmd):
if cmd == "wait" and game.is_abortable():
game.abort_in(60)
self.send_reply(line, "Waiting 60 seconds...")
if cmd == "name":
self.send_reply(line, "{} (lichess-bot v{})".format(self.engine.name(), self.version))
if cmd == "howto":
self.send_reply(line, "How to run your own bot: lichess.org/api#tag/Chess-Bot")
def send_reply(self, line, reply):
self.xhr.chat(self.game.id, line.room, reply)
class ChatLine():
def __init__(self, json):
self.room = json.get("room")
self.username = json.get("username")
self.text = json.get("text")