From fe8c2fc007172de403fa9db65c08a20827399694 Mon Sep 17 00:00:00 2001 From: Rodo Date: Sun, 11 Feb 2024 13:30:43 +1000 Subject: [PATCH 01/10] docs: discord bot readme --- README_DISCORDBOT.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 README_DISCORDBOT.md diff --git a/README_DISCORDBOT.md b/README_DISCORDBOT.md new file mode 100644 index 0000000..641d4e7 --- /dev/null +++ b/README_DISCORDBOT.md @@ -0,0 +1,7 @@ +# Discord Bot Development + +## Getting started +- Create a bot in discord https://interactions-py.github.io/interactions.py/Guides/02%20Creating%20Your%20Bot/ +- Create your own discord server, add that bot to a test server (feel free to use ) +- Implement bot logics (and add bot token to your code too) +- Now, run the bot code locally and test the bot on your server \ No newline at end of file From 9ab9a9338fa0f711ce5f7ff5220eea2f7dfd7b0c Mon Sep 17 00:00:00 2001 From: Rodo Date: Sun, 11 Feb 2024 13:34:23 +1000 Subject: [PATCH 02/10] docs: add auto formatter --- README_DISCORDBOT.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README_DISCORDBOT.md b/README_DISCORDBOT.md index 641d4e7..d73a500 100644 --- a/README_DISCORDBOT.md +++ b/README_DISCORDBOT.md @@ -4,4 +4,15 @@ - Create a bot in discord https://interactions-py.github.io/interactions.py/Guides/02%20Creating%20Your%20Bot/ - Create your own discord server, add that bot to a test server (feel free to use ) - Implement bot logics (and add bot token to your code too) -- Now, run the bot code locally and test the bot on your server \ No newline at end of file +- Now, run the bot code locally and test the bot on your server + +## Auto formatter for Python +https://marketplace.visualstudio.com/items?itemName=ms-python.black-formatter + +Add this in Preferences: Open User Settings (JSON). To go to this file, open command palette: `Ctrl Shift P` > `Preferences: Open User Settings (JSON)`. +``` +"[python]": { + "editor.defaultFormatter": "ms-python.black-formatter", + "editor.formatOnSave": true + }, +``` From 456cf0719e87257179f6602a928456b549e12154 Mon Sep 17 00:00:00 2001 From: Rodo Date: Thu, 15 Feb 2024 22:30:09 +1000 Subject: [PATCH 03/10] docs: add instructions for discord bot dev --- README.md | 13 +++++++++++++ README_DISCORDBOT.md | 18 ------------------ 2 files changed, 13 insertions(+), 18 deletions(-) delete mode 100644 README_DISCORDBOT.md diff --git a/README.md b/README.md index 1aa597c..0b12f3d 100644 --- a/README.md +++ b/README.md @@ -22,3 +22,16 @@ When you’re done working in the virtual environment, simply type: ``` exit ``` + +## Discord Bot Development + +### Getting started +- [Create a bot in discord](https://interactions-py.github.io/interactions.py/Guides/02%20Creating%20Your%20Bot/) +- Create your own discord server, add that bot to a test server (feel free to use ) +- Implement bot logics (and add bot token to your code too) +- Now, run the bot code locally and test the bot on your server + +### Auto formatter for Python +We use [Ruff](https://github.com/astral-sh/ruff) for linting and code formating. Ruff is already included and installed when you use `poetry install`. Follow the [instructions here](https://github.com/astral-sh/ruff) to use Ruff. + +**TL;DR:** just use `ruff check .` (Lint all files in the current directory and any subdirectories) before committing new code. \ No newline at end of file diff --git a/README_DISCORDBOT.md b/README_DISCORDBOT.md deleted file mode 100644 index d73a500..0000000 --- a/README_DISCORDBOT.md +++ /dev/null @@ -1,18 +0,0 @@ -# Discord Bot Development - -## Getting started -- Create a bot in discord https://interactions-py.github.io/interactions.py/Guides/02%20Creating%20Your%20Bot/ -- Create your own discord server, add that bot to a test server (feel free to use ) -- Implement bot logics (and add bot token to your code too) -- Now, run the bot code locally and test the bot on your server - -## Auto formatter for Python -https://marketplace.visualstudio.com/items?itemName=ms-python.black-formatter - -Add this in Preferences: Open User Settings (JSON). To go to this file, open command palette: `Ctrl Shift P` > `Preferences: Open User Settings (JSON)`. -``` -"[python]": { - "editor.defaultFormatter": "ms-python.black-formatter", - "editor.formatOnSave": true - }, -``` From 9549905b928ec219e01c3f125a2a321fb46266cd Mon Sep 17 00:00:00 2001 From: Rodo Date: Thu, 15 Feb 2024 22:32:43 +1000 Subject: [PATCH 04/10] chore: reword --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0b12f3d..43a278a 100644 --- a/README.md +++ b/README.md @@ -34,4 +34,8 @@ exit ### Auto formatter for Python We use [Ruff](https://github.com/astral-sh/ruff) for linting and code formating. Ruff is already included and installed when you use `poetry install`. Follow the [instructions here](https://github.com/astral-sh/ruff) to use Ruff. -**TL;DR:** just use `ruff check .` (Lint all files in the current directory and any subdirectories) before committing new code. \ No newline at end of file +**TL;DR:** +Just use this (Lint all files in the current directory and any subdirectories) before committing new code. +``` +ruff check . +``` From 9b785a24e9c903bf9dd5752b1ed6bb843aea11bd Mon Sep 17 00:00:00 2001 From: Rodo Date: Thu, 15 Feb 2024 22:41:51 +1000 Subject: [PATCH 05/10] feat: add `ruff` package --- poetry.lock | 2 +- pyproject.toml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/poetry.lock b/poetry.lock index 4927df1..cf7c9f5 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2048,4 +2048,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.12" -content-hash = "33c9aead0333895af8eaaf5cbac95e2382711d6fc27efa86b746ad50259b95ee" +content-hash = "5a62e466f97b06a9ba94a4d44f5e5ef9563c0979ff8e101a941466f555ef0dc1" diff --git a/pyproject.toml b/pyproject.toml index 85eba9c..be330a0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,6 +11,7 @@ litellm = {extras = ["proxy"], version = "^1.23.7"} openai = "^1.11.1" python-dotenv = "^1.0.1" discord-py-interactions = "5.11.0" +ruff = "^0.2.1" [tool.poetry.group.dev.dependencies] pre-commit = "^3.6.1" From 4ab053b87415373b3091eab2fe73ec4608b1746c Mon Sep 17 00:00:00 2001 From: Rodo Date: Thu, 15 Feb 2024 22:44:15 +1000 Subject: [PATCH 06/10] docs: "add package to pyproject.toml" instructions --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 43a278a..ab1b324 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,11 @@ When you’re done working in the virtual environment, simply type: exit ``` +To add missing package to the package list: +``` +poetry add your_new_package_name +``` + ## Discord Bot Development ### Getting started From 1b0ac8af49614d9bd4ce6b280568ae9e98c9eaa1 Mon Sep 17 00:00:00 2001 From: Rodo Date: Thu, 15 Feb 2024 22:53:56 +1000 Subject: [PATCH 07/10] docs: add and apply `ruff format .` --- README.md | 5 ++-- discord_bot/bot.py | 60 +++++++++++++++++++++++----------------------- 2 files changed, 33 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index ab1b324..a8eeb4e 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,8 @@ poetry add your_new_package_name We use [Ruff](https://github.com/astral-sh/ruff) for linting and code formating. Ruff is already included and installed when you use `poetry install`. Follow the [instructions here](https://github.com/astral-sh/ruff) to use Ruff. **TL;DR:** -Just use this (Lint all files in the current directory and any subdirectories) before committing new code. +Just use this before committing new code. ``` -ruff check . +ruff check . # Lint all +ruff format . # Format all ``` diff --git a/discord_bot/bot.py b/discord_bot/bot.py index 00b4077..25f5d0e 100644 --- a/discord_bot/bot.py +++ b/discord_bot/bot.py @@ -8,58 +8,58 @@ @interactions.listen() async def on_ready(): - print("Ready") - print(f"This bot is owned by {bot.owner}") + print("Ready") + print(f"This bot is owned by {bot.owner}") @interactions.listen() async def on_message_create(event): - print(f"message received: {event.message.content}") + print(f"message received: {event.message.content}") @interactions.slash_command(name="my_short_command", description="My first command :)") async def my_short_command(ctx: interactions.SlashContext): - await ctx.send("Hello World") + await ctx.send("Hello World") @interactions.slash_command(name="my_long_command", description="My second command :)") async def my_long_command_function(ctx: interactions.SlashContext): - await ctx.defer() # use defer for time-comsuming commands - await asyncio.sleep(600) - await ctx.send("Hello World") + await ctx.defer() # use defer for time-comsuming commands + await asyncio.sleep(600) + await ctx.send("Hello World") @interactions.slash_command(name="ask", description="Ask an LLM") @interactions.slash_option( - name="model", - description="Choose an LLM model", - required=True, - opt_type=interactions.OptionType.STRING, - autocomplete=True, + name="model", + description="Choose an LLM model", + required=True, + opt_type=interactions.OptionType.STRING, + autocomplete=True, ) async def ask_model(ctx: interactions.SlashContext, model: str): - await ctx.send(f"You asked model {model}") + await ctx.send(f"You asked model {model}") @ask_model.autocomplete("model") async def autocomplete(ctx: interactions.AutocompleteContext): - string_option_input = ctx.input_text # note: can be empty - print(f"input: {string_option_input}") - # you can use ctx.kwargs.get("name") to get the current state of other options - note they can be empty too - # make sure you respond within three seconds - - choices = ["gpt3", "gpt4"] - filtered_choices = [choice for choice in choices if string_option_input in choice] - - await ctx.send( - choices=[ - { - "name": choice, - "value": choice, - } - for choice in filtered_choices - ] - ) + string_option_input = ctx.input_text # note: can be empty + print(f"input: {string_option_input}") + # you can use ctx.kwargs.get("name") to get the current state of other options - note they can be empty too + # make sure you respond within three seconds + + choices = ["gpt3", "gpt4"] + filtered_choices = [choice for choice in choices if string_option_input in choice] + + await ctx.send( + choices=[ + { + "name": choice, + "value": choice, + } + for choice in filtered_choices + ] + ) load_dotenv() From 4f5a1e9f26c3c092b662e089b4769b4078f13de2 Mon Sep 17 00:00:00 2001 From: Rodo Date: Fri, 16 Feb 2024 15:22:01 +1000 Subject: [PATCH 08/10] docs: edit ruff commands --- README.md | 4 ++-- discord_bot/bot.py | 60 +++++++++++++++++++++++----------------------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index a8eeb4e..dbaa341 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,6 @@ We use [Ruff](https://github.com/astral-sh/ruff) for linting and code formating. **TL;DR:** Just use this before committing new code. ``` -ruff check . # Lint all -ruff format . # Format all +poetry run ruff check . # Lint all +poetry run ruff format . # Format all ``` diff --git a/discord_bot/bot.py b/discord_bot/bot.py index 25f5d0e..00b4077 100644 --- a/discord_bot/bot.py +++ b/discord_bot/bot.py @@ -8,58 +8,58 @@ @interactions.listen() async def on_ready(): - print("Ready") - print(f"This bot is owned by {bot.owner}") + print("Ready") + print(f"This bot is owned by {bot.owner}") @interactions.listen() async def on_message_create(event): - print(f"message received: {event.message.content}") + print(f"message received: {event.message.content}") @interactions.slash_command(name="my_short_command", description="My first command :)") async def my_short_command(ctx: interactions.SlashContext): - await ctx.send("Hello World") + await ctx.send("Hello World") @interactions.slash_command(name="my_long_command", description="My second command :)") async def my_long_command_function(ctx: interactions.SlashContext): - await ctx.defer() # use defer for time-comsuming commands - await asyncio.sleep(600) - await ctx.send("Hello World") + await ctx.defer() # use defer for time-comsuming commands + await asyncio.sleep(600) + await ctx.send("Hello World") @interactions.slash_command(name="ask", description="Ask an LLM") @interactions.slash_option( - name="model", - description="Choose an LLM model", - required=True, - opt_type=interactions.OptionType.STRING, - autocomplete=True, + name="model", + description="Choose an LLM model", + required=True, + opt_type=interactions.OptionType.STRING, + autocomplete=True, ) async def ask_model(ctx: interactions.SlashContext, model: str): - await ctx.send(f"You asked model {model}") + await ctx.send(f"You asked model {model}") @ask_model.autocomplete("model") async def autocomplete(ctx: interactions.AutocompleteContext): - string_option_input = ctx.input_text # note: can be empty - print(f"input: {string_option_input}") - # you can use ctx.kwargs.get("name") to get the current state of other options - note they can be empty too - # make sure you respond within three seconds - - choices = ["gpt3", "gpt4"] - filtered_choices = [choice for choice in choices if string_option_input in choice] - - await ctx.send( - choices=[ - { - "name": choice, - "value": choice, - } - for choice in filtered_choices - ] - ) + string_option_input = ctx.input_text # note: can be empty + print(f"input: {string_option_input}") + # you can use ctx.kwargs.get("name") to get the current state of other options - note they can be empty too + # make sure you respond within three seconds + + choices = ["gpt3", "gpt4"] + filtered_choices = [choice for choice in choices if string_option_input in choice] + + await ctx.send( + choices=[ + { + "name": choice, + "value": choice, + } + for choice in filtered_choices + ] + ) load_dotenv() From 7e0eba71a0d0253ad80745f3894ccd0cc054d092 Mon Sep 17 00:00:00 2001 From: Rodo Date: Fri, 16 Feb 2024 22:03:03 +1000 Subject: [PATCH 09/10] docs: resolve change requests --- README.md | 23 +++++------------------ pyproject.toml | 1 - 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index dbaa341..0a3b6b2 100644 --- a/README.md +++ b/README.md @@ -23,25 +23,12 @@ When you’re done working in the virtual environment, simply type: exit ``` -To add missing package to the package list: -``` -poetry add your_new_package_name -``` - ## Discord Bot Development ### Getting started - [Create a bot in discord](https://interactions-py.github.io/interactions.py/Guides/02%20Creating%20Your%20Bot/) -- Create your own discord server, add that bot to a test server (feel free to use ) -- Implement bot logics (and add bot token to your code too) -- Now, run the bot code locally and test the bot on your server - -### Auto formatter for Python -We use [Ruff](https://github.com/astral-sh/ruff) for linting and code formating. Ruff is already included and installed when you use `poetry install`. Follow the [instructions here](https://github.com/astral-sh/ruff) to use Ruff. - -**TL;DR:** -Just use this before committing new code. -``` -poetry run ruff check . # Lint all -poetry run ruff format . # Format all -``` +- Add that bot to a test server. + - When making the invite through OAuth2 URL Generator, make sure to enable `bot` and `applications.commands` options. + - Follow the [Invite your bot](https://interactions-py.github.io/interactions.py/Guides/02%20Creating%20Your%20Bot/) section for reference. +- Copy out `.env.example` into `.env`, and fill in the `DISCORD_BOT_TOKEN` and `DISCORD_GUILD_ID` +- Now, run the bot code locally and test the bot on your server \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 7c6db5d..12fcd2a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,7 +11,6 @@ litellm = {extras = ["proxy"], version = "^1.23.7"} openai = "^1.11.1" python-dotenv = "^1.0.1" discord-py-interactions = "5.11.0" -ruff = "^0.2.1" [tool.poetry.group.dev.dependencies] pre-commit = "^3.6.1" From 52cf618fed8814e12e3b55601852e485a2c91489 Mon Sep 17 00:00:00 2001 From: Rodo Date: Fri, 16 Feb 2024 22:12:32 +1000 Subject: [PATCH 10/10] chore: add extra line --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0a3b6b2..627ab80 100644 --- a/README.md +++ b/README.md @@ -26,9 +26,9 @@ exit ## Discord Bot Development ### Getting started -- [Create a bot in discord](https://interactions-py.github.io/interactions.py/Guides/02%20Creating%20Your%20Bot/) +- [Create a bot in discord](https://interactions-py.github.io/interactions.py/Guides/02%20Creating%20Your%20Bot/). - Add that bot to a test server. - When making the invite through OAuth2 URL Generator, make sure to enable `bot` and `applications.commands` options. - Follow the [Invite your bot](https://interactions-py.github.io/interactions.py/Guides/02%20Creating%20Your%20Bot/) section for reference. -- Copy out `.env.example` into `.env`, and fill in the `DISCORD_BOT_TOKEN` and `DISCORD_GUILD_ID` -- Now, run the bot code locally and test the bot on your server \ No newline at end of file +- Copy out `.env.example` into `.env`, and fill in the `DISCORD_BOT_TOKEN` and `DISCORD_GUILD_ID`. +- Now, run the bot code locally and test the bot on your server.