-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
77 lines (63 loc) · 2.27 KB
/
bot.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
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
import json
import asyncio
import discord
from discord.ext import commands # gets the bot commands archive
from discord.utils import get # gets the finding functions
from discord.ext import commands
from board import Board
from img import draw_board
import helper
import game
CONFIG = json.load(open("./config.json"))
TOKEN = CONFIG["token"]
intents = discord.Intents.all()
bot = commands.Bot(command_prefix='!', intents=intents)
@bot.command(pass_context=True)
async def generate(ctx, *, FEN):
b = Board(FEN)
b.load_board_from_fen()
draw_board(b)
file_ = discord.File("./assets/RunningBoard.jpg", filename="board.png")
await ctx.send(file=file_)
@bot.command(pass_context=True)
async def challenge(ctx, user='', *, FEN=''):
if not user:
await ctx.send("Please select a user to challenge!")
else:
id = int(user[2:-1])
# if ctx.author.id == id:
# await ctx.send("You cannot challenge yourself!")
# return
msg = await ctx.send(f"{user}: Please accept or deny this challenge.")
await msg.add_reaction("✅")
await msg.add_reaction("❌")
def check(reaction, user):
return user.id == id and reaction.message.id == msg.id
try:
reaction, user = await bot.wait_for('reaction_add', timeout=60.0, check=check)
if reaction.emoji == "✅":
await ctx.send("Accepted!")
if not FEN:
FEN = CONFIG["baseFEN"]
await game.run(bot, ctx, FEN, id)
elif reaction.emoji == "❌":
await ctx.send("Denied!")
except asyncio.TimeoutError:
await ctx.send("Challenge has timed out.")
@bot.command(pass_context=True)
async def code(ctx):
await ctx.send("My code can be found here:\nhttps://github.com/ryankarch/chessbot")
@bot.command(pass_context=True)
async def moves(ctx, move, *, FEN):
b = Board(FEN)
b.switch_player()
try:
move = helper.get_cell_tuple(move)
b.advance_turn()
moves = b.board_piece[move[0]][move[1]].return_moves()
except:
moves = []
draw_board(b, moves)
file_ = discord.File("./assets/RunningBoard.jpg", filename="board.png")
await ctx.send(file=file_)
bot.run(TOKEN)