Skip to content

Commit

Permalink
Modify the way to run the program in development mode
Browse files Browse the repository at this point in the history
  • Loading branch information
SeoulSKY committed Jan 17, 2024
1 parent f9dc98f commit b77b65f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
25 changes: 11 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,16 @@

Create `.env` file, copy and paste all contents from `.env.example` file, and fill the values for your development environment.

<details>
<summary>
<h3>Description of each environment variable (Click to expand)</h3>
</summary>

| Name | Description |
|--------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|
| BOT_TOKEN | [Token](https://discord.com/developers/applications) for your own Discord bot |
| TEST_GUILD_ID | (Optional) Find your test server id following the [guide](https://support.discord.com/hc/en-us/articles/206346498-Where-can-I-find-my-User-Server-Message-ID-). In the test server, the slash commands immediately get updated when you run the program |
| CAI_TOKEN | Token for your Character AI account. Follow the [guide](https://pycai.gitbook.io/welcome/api/values) to learn how to acquire it. |
| CAI_CHAR_ID | ID for the character in the Character AI. Follow the [guide](https://pycai.gitbook.io/welcome/api/values) to learn how to acquire it. |
| CAI_TGT | ID for the target in the Character AI. Its value starts with `internal_id:`. Run `scripts/cai_tgt.py` to get it. |
</details>
### Description of each environment variable

| Name | Description |
|--------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| BOT_TOKEN | [Token](https://discord.com/developers/applications) for your own Discord bot |
| TEST_GUILD_ID | (Optional) Find your test server id following the [guide](https://support.discord.com/hc/en-us/articles/206346498-Where-can-I-find-my-User-Server-Message-ID-). If provided, the bot runs in development mode. |
| CAI_TOKEN | Token for your Character AI account. Follow the [guide](https://pycai.gitbook.io/welcome/api/values) to learn how to acquire it. |
| CAI_CHAR_ID | ID for the character in the Character AI. Follow the [guide](https://pycai.gitbook.io/welcome/api/values) to learn how to acquire it. |
| CAI_TGT | ID for the target in the Character AI. Its value starts with `internal_id:`. Run `scripts/cai_tgt.py` to get it. |


### Running with [Docker](https://www.docker.com) and [Docker Compose](https://docs.docker.com/compose/install/) (Recommended)

Expand Down Expand Up @@ -93,4 +90,4 @@ pyenv exec python main.py

## How to Contribute

Read [CONTRIBUTING.md](https://github.com/SeoulSKY/SoruSora/blob/master/docs/CONTRIBUTING.md) for details
Read [CONTRIBUTING.md](https://github.com/SeoulSKY/SoruSora/blob/master/docs/CONTRIBUTING.md) for details.
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ services:
- ./cache:/app/cache
env_file:
- .env
environment:
- PRODUCTION=1

mongo:
image: mongo:7.0.5
Expand Down
5 changes: 2 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@

load_dotenv()

IS_DEV_ENV = "PRODUCTION" not in os.environ

ROOT_DIR = os.path.dirname(os.path.abspath(__file__))

LOGS_DIR = os.path.join(ROOT_DIR, "logs")
ERROR_DIR = os.path.join(LOGS_DIR, "error")
WARNING_DIR = os.path.join(LOGS_DIR, "warning")

TEST_GUILD = discord.Object(id=os.getenv("TEST_GUILD_ID")) if os.getenv("TEST_GUILD_ID") else None
IS_DEV_ENV = TEST_GUILD is not None

DEV_COMMANDS = {
Movie,
Expand Down Expand Up @@ -86,7 +85,7 @@ def _add_commands(self):
self.tree.add_command(group_command_class(bot=self))

async def setup_hook(self):
if TEST_GUILD is not None:
if IS_DEV_ENV:
self.tree.copy_global_to(guild=TEST_GUILD)
synced_commands = [command.name for command in await self.tree.sync(guild=TEST_GUILD)]
logging.info("Synced commands to the test guild: %s", str(synced_commands))
Expand Down
11 changes: 9 additions & 2 deletions scripts/clear_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@ class TempBot(Bot):
"""

async def setup_hook(self) -> None:
if os.getenv("TEST_GUILD_ID"):
guild = discord.Object(id=os.getenv("TEST_GUILD_ID"))
self.tree.clear_commands(guild=guild)
assert len(await self.tree.sync(guild=guild)) == 0

print("Test guild commands cleared")

self.tree.clear_commands(guild=None)
await self.tree.sync()
assert len(await self.tree.sync()) == 0

print("Done")
print("Global commands cleared")
sys.exit(0)


Expand Down

0 comments on commit b77b65f

Please sign in to comment.