Skip to content

Commit

Permalink
Who knows
Browse files Browse the repository at this point in the history
  • Loading branch information
katie-oh committed Jun 13, 2023
1 parent d6c4e48 commit dce705c
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 14 deletions.
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM liuchong/rustup

RUN apt-get update
RUN apt-get install python3 python3-pip -y
RUN apt-get install -y git

RUN cargo install sgf-render

COPY . .

RUN pip3 install -r requirements.txt

ENTRYPOINT python3 rengobot.py
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ A discord bot for playing rengo games!
- python-sgfmill

Make sure to run the bot in an environment with read/write permissions


* installed Rust
* updated requirements.txt
* updated admin and teachers
49 changes: 39 additions & 10 deletions rengobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,47 @@
import sgfengine

import discord
from discord.ext import commands
from discord.ext import commands, tasks

# import requests
# import raw_input

# 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)
# res = requests.get("https://sh.rustup.rs")
# print(res)
# os.system("curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh")
# os.system("cargo install sgf-render")
# os.system("cargo --version")
# raw_input()

intents = discord.Intents.default()
# intents.message_content = True
# client = discord.Client(intents=intents)
# bot = commands.Bot(command_prefix='$', intents=intents)
bot = commands.Bot(command_prefix='$', intents=intents, help_command=None)

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
time_to_skip= timedelta(seconds=1) # in queue games, how much time to wait for the next move
min_players = 2

# People who can start and resign games :O
# Later we might replace this with checking for a role.
admins=[ 463380651467472896, # Devin
907684282145849375, # David
# 631824578934734848 # Katie
631824578934734848 # Katie
]

teachers=[ 463380651467472896, # Devin
907684282145849375, # David
# 631824578934734848 # Katie
631824578934734848 # Katie
]

server_id= 1060261462733496320
permitted_channel_ids= [ 1115328734694748231 ] # #zen-go channel
# server_id= 1060261462733496320 # Columbus Go Club
server_id= 1115830515396792342
permitted_channel_ids= [ 1115612796734943374 ] #zen-go channel
#permitted_channel_ids= [ 1115830516046893109 ] #my channel

white_stone= "<:white_stone:882731089548939314>"
black_stone= "<:black_stone:882730888453046342>"
Expand Down Expand Up @@ -79,7 +95,7 @@ async def play(ctx, arg):

filter_state= [i for i in range(len(state)) if state[i][0] == channel_id] # This is where I should use a fancy next()
if not filter_state:
await ctx.send("No active game in this channel!")
# await ctx.send("No active game in this channel!")
return

i= filter_state[0]
Expand All @@ -103,7 +119,7 @@ async def play(ctx, arg):

if len(state[i][2])>0 and state[i][2][-1] == user.id and (state[i][1]!="teachers" or colour=="0"):
await ctx.send("No two consecutive moves by the same player!")
# return
return

for j in range(len(state[i][2])):
if (state[i][2][j] == user.id and
Expand Down Expand Up @@ -151,6 +167,9 @@ async def play(ctx, arg):
else:
await ctx.send(file=file)

colour_text="B" if colour else "W"
await ctx.send(colour_text+ "'s turn!")

with open("state.txt", "w") as f: f.write(repr(state))

@bot.command()
Expand Down Expand Up @@ -452,11 +471,12 @@ async def resign(ctx, arg):

with open("state.txt", "w") as f: f.write(repr(state))

@tasks.loop(seconds = 10)
async def background_task():
await bot.wait_until_ready()
print("bot ready!")

guild=discord.utils.get(bot.guilds, name="Awesome Baduk")
guild=discord.utils.get(bot.guilds, name="Columbus Go Club")
game=discord.Game("multiplayer Baduk! $help for command list")
await bot.change_presence(status=discord.Status.online, activity=game)

Expand Down Expand Up @@ -524,3 +544,12 @@ async def background_task():

bot.loop.create_task(background_task())
bot.run(token)


# @bot.event
# async def on_ready():
# background_task.start()
# bot.run(token)

# background_task.start()
# bot.run(token)
6 changes: 2 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
git+https://github.com/katie-oh/rengobot
# dnspython==1.16.0
# PyNaCl==1.3.0
# async-timeout==3.0.1
# pandas
sgfmill
python-discord
5 changes: 5 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from setuptools import setup
import os
# from distutils.core import setup

# os.system("curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs")
# os.system("cargo install sgf-render")

setup(name='ZenGoBot',
version='1.0',
description='Zen Go, forked from AwesomeRengoBot',
py_modules=['sgfengine', 'rengobot'],
scripts=["scripts/install-sgf-render"],
)

0 comments on commit dce705c

Please sign in to comment.