Spaces:
Sleeping
Sleeping
File size: 2,332 Bytes
5893311 a21bca3 17d9988 a21bca3 5893311 a21bca3 b0d53d6 a21bca3 17d9988 a21bca3 17d9988 a21bca3 17d9988 a21bca3 17d9988 faf38e6 a21bca3 17d9988 a21bca3 17d9988 a21bca3 0f1f925 cf2f8df a21bca3 b0d53d6 faf38e6 0f1f925 a21bca3 17d9988 faf38e6 | 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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | import os
import pytest
import pytest_timeout
import requests
import time
import zipfile
import yaml
import shutil
import importlib
lishogi_bot = importlib.import_module("lishogi-bot")
TOKEN = os.environ['BOT_TOKEN']
def test_nothing():
assert True
def run_bot(CONFIG, logging_level):
lishogi_bot.logger.info(lishogi_bot.intro())
li = lishogi_bot.lishogi.Lishogi(CONFIG["token"], CONFIG["url"], lishogi_bot.__version__, logging_level)
user_profile = li.get_profile()
username = user_profile["username"]
is_bot = user_profile.get("title") == "BOT"
lishogi_bot.logger.info(f"Welcome BOT {username}!")
if not is_bot:
is_bot = lishogi_bot.upgrade_account(li)
if is_bot:
games = li.get_ongoing_games()
game_ids = list(map(lambda game: game["gameId"], games))
for game in game_ids:
try:
li.abort(game)
except:
pass
time.sleep(2)
while li.get_ongoing_games():
time.sleep(60)
game_id = li.challenge_ai()["id"]
time.sleep(2)
@pytest.mark.timeout(300)
def run_test():
lishogi_bot.start(li, user_profile, CONFIG, logging_level, None, one_game=True)
headers = {"Accept": "application/json"}
response = requests.get(f"https://lishogi.org/game/export/{game_id}?moves=false", headers=headers)
json = response.json()
winner = json["winner"]
assert "user" in json["players"][winner]
run_test()
else:
lishogi_bot.logger.error(f"{username} is not a bot account. Please upgrade it to a bot account!")
games = li.get_ongoing_games()
game_ids = list(map(lambda game: game["gameId"], games))
for game in game_ids:
try:
li.abort(game)
except:
pass
time.sleep(2)
def test_bot():
logging_level = lishogi_bot.logging.INFO
lishogi_bot.logging_configurer(logging_level, None)
with open("./config.yml.default") as file:
CONFIG = yaml.safe_load(file)
CONFIG["token"] = TOKEN
CONFIG["engine"]["dir"] = "/usr/games"
CONFIG["engine"]["name"] = "fairy-stockfish"
CONFIG["engine"]["protocol"] = "usi"
run_bot(CONFIG, logging_level)
if __name__ == "__main__":
test_bot()
|