update
This commit is contained in:
parent
c40603e5ad
commit
768274f547
@ -6,3 +6,9 @@ A discord bot for playing rengo games!
|
||||
- python-sgfmill
|
||||
|
||||
Make sure to run the bot in an environment with read/write permissions
|
||||
|
||||
|
||||
state.txt
|
||||
```
|
||||
[]
|
||||
```
|
48
rengobot.py
48
rengobot.py
@ -12,7 +12,10 @@ from discord.ext import commands
|
||||
# We don't use fancy slash commands here. It seems there is this library for python but it looks a bit more involved.
|
||||
# https://pypi.org/project/discord-py-slash-command/
|
||||
|
||||
bot = commands.Bot(command_prefix='$', help_command=None)
|
||||
intents = discord.Intents.default()
|
||||
intents.message_content = True
|
||||
|
||||
bot = commands.Bot(command_prefix='$', help_command=None, intents=intents)
|
||||
|
||||
min_time_player= timedelta(seconds=1) # in random games, min time between same player plays (default days=1)
|
||||
time_to_skip= timedelta(days=1) # in queue games, how much time to wait for the next move
|
||||
@ -20,18 +23,12 @@ min_players = 2
|
||||
|
||||
# People who can start and resign games :O
|
||||
# Later we might replace this with checking for a role.
|
||||
admins=[ 756220448118669463, # Young Sun
|
||||
732403731810877450, # Yeonwoo
|
||||
145294584077877249, # Mrchance
|
||||
477895596141707264 # René
|
||||
]
|
||||
admins=[ ]
|
||||
|
||||
teachers=[ 756220448118669463, # Young Sun
|
||||
145294584077877249, # Mrchance
|
||||
732403731810877450] # Yeonwoo
|
||||
teachers=[ ]
|
||||
|
||||
awesome_server_id= 767835617002258443
|
||||
permitted_channel_ids= [ 875353143867752489, 885498819385634816, 878649716269785150, 881984021192671242, 892435998070431755, 892436145651216444,870604751354613770, 896111390216040540, 896112340657909820, 896112378805116978, 896112602105659442]
|
||||
awesome_server_id= 123
|
||||
permitted_channel_ids= [ ]
|
||||
|
||||
white_stone= "<:white_stone:882731089548939314>"
|
||||
black_stone= "<:black_stone:882730888453046342>"
|
||||
@ -215,8 +212,7 @@ async def board(ctx):
|
||||
i= filter_state[0]
|
||||
colour= sgfengine.next_colour(str(channel_id))
|
||||
|
||||
os.system("sgf-render --style fancy --label-sides nesw -o "+str(channel_id)+".png -n last "+str(channel_id)+".sgf")
|
||||
|
||||
os.system("sgf-render -f png --style fancy --label-sides nesw -o "+str(channel_id)+".png -n last "+str(channel_id)+".sgf")
|
||||
file = discord.File(str(ctx.channel.id)+".png")
|
||||
if state[i][1]=="queue":
|
||||
if len(state[i][4][colour]) > 0:
|
||||
@ -224,7 +220,7 @@ async def board(ctx):
|
||||
await ctx.send(file=file, content="{}'s turn! ⭐".format(next_player.display_name))
|
||||
else:
|
||||
await ctx.send(file=file, content="Waiting for players to join!")
|
||||
if state[i][1]=="teachers":
|
||||
elif state[i][1]=="teachers":
|
||||
if colour==0:
|
||||
next_player=(await guild.fetch_member(state[i][4][colour][0]))
|
||||
await ctx.send(file=file, content="{}'s turn! ⭐".format(next_player.display_name))
|
||||
@ -400,19 +396,23 @@ async def newgame(ctx, gametype, handicap=0, komi=6.5):
|
||||
return
|
||||
|
||||
# lowest effort serialization
|
||||
with open("state.txt") as f: state = ast.literal_eval(f.read())
|
||||
with open("state.txt") as f:
|
||||
state = eval(f.read())
|
||||
|
||||
if ctx.channel.id in [ ch for (ch,_,_,_,_) in state]:
|
||||
|
||||
if channel_id in [ ch for (ch,_,_,_,_) in state]:
|
||||
await ctx.send("A game is already active in this channel!")
|
||||
return
|
||||
|
||||
sgfengine.new_game(str(ctx.channel.id), handicap, komi)
|
||||
sgfengine.new_game(str(channel_id), handicap, komi)
|
||||
if gametype== "teachers":
|
||||
state.append((ctx.channel.id, gametype, [], [], [[],teachers]))
|
||||
state.append((channel_id, gametype, [], [], [[],teachers]))
|
||||
else:
|
||||
state.append((ctx.channel.id, gametype, [], [], [[],[]]))
|
||||
state.append((channel_id, gametype, [], [], [[],[]]))
|
||||
|
||||
file = discord.File(str(ctx.channel.id)+".png")
|
||||
os.system("sgf-render -f png --style fancy --label-sides nesw -o "+str(channel_id)+".png -n last "+str(channel_id)+".sgf")
|
||||
|
||||
file = discord.File(str(channel_id)+".png")
|
||||
if gametype in ["queue", "teachers"]:
|
||||
await ctx.send(file=file, content="A new game has started! Join with `$join`")
|
||||
else:
|
||||
@ -493,5 +493,9 @@ async def background_task():
|
||||
except ConnectionResetError:
|
||||
print("Connection error")
|
||||
|
||||
bot.loop.create_task(background_task())
|
||||
bot.run(token)
|
||||
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
bot.loop.create_task(background_task())
|
||||
|
||||
bot.run(token)
|
@ -26,7 +26,7 @@ def new_game(channel_id, handicap=0, komi=6.5):
|
||||
f.write(game.serialise())
|
||||
f.close()
|
||||
|
||||
os.system("sgf-render --style fancy --label-sides nesw -o "+channel_id+".png -n last "+channel_id+".sgf")
|
||||
os.system("sgf-render -f png --style fancy --label-sides nesw -o "+str(channel_id)+".png -n last "+str(channel_id)+".sgf")
|
||||
|
||||
#0 if black to play, 1 if white to play
|
||||
def next_colour(channel_id):
|
||||
@ -87,7 +87,7 @@ def play_move(channel_id, messagestr, player, overwrite=False):
|
||||
f.write(game.serialise())
|
||||
f.close()
|
||||
|
||||
os.system("sgf-render --style fancy --label-sides nesw -o "+channel_id+".png -n last "+channel_id+".sgf")
|
||||
os.system("sgf-render -f png --style fancy --label-sides nesw -o "+str(channel_id)+".png -n last "+str(channel_id)+".sgf")
|
||||
|
||||
# colour is "B" if black resigns, "W" if white resigns
|
||||
def resign(channel_id, colour, file_name):
|
||||
|
Loading…
x
Reference in New Issue
Block a user