From e1c0ee065ac445f6be6fd0ebddded2c8a8a5abce Mon Sep 17 00:00:00 2001 From: mctaylors Date: Wed, 6 Nov 2024 21:55:31 +0300 Subject: [PATCH 1/6] Add automatic deployment Signed-off-by: mctaylors --- .forgejo/workflows/push.yml | 93 +++++++++++++++++++++++++++++++++++++ .gitignore | 5 +- main.py | 1 + 3 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 .forgejo/workflows/push.yml diff --git a/.forgejo/workflows/push.yml b/.forgejo/workflows/push.yml new file mode 100644 index 0000000..4d340be --- /dev/null +++ b/.forgejo/workflows/push.yml @@ -0,0 +1,93 @@ +name: Update production + +on: + push: + branches: + - master + +jobs: + build-upload-artifact: + name: Build and upload Lurker as artifact + runs-on: docker + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Python 3.13 + uses: actions/setup-python@v5 + with: + python-version: '3.13' + + - name: Setup virtual environment + run: python -m venv .venv/ + + - name: Install necessary packages using pip + run: ./.venv/bin/pip install $PIP_PACKAGES + env: + PIP_PACKAGES: ${{vars.PIP_PACKAGES}} + + - name: Build binary + run: ./.venv/bin/pyinstaller $PYINSTALLER_FLAGS main.py + env: + PYINSTALLER_FLAGS: ${{vars.PYINSTALLER_FLAGS}} + + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: lurker-bin + path: dist/ + + update-production: + name: Update Lurker on production + runs-on: docker + + steps: + - name: Download artifact + uses: actions/download-artifact@v4 + with: + name: lurker-bin + + - name: Copy SSH key + run: | + install -m 600 -D /dev/null ~/.ssh/id_ed25519 + echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_ed25519 + shell: bash + env: + SSH_PRIVATE_KEY: ${{secrets.SSH_PRIVATE_KEY}} + + - name: Generate SSH known hosts file + run: | + ssh-keyscan -H -p $SSH_PORT $SSH_HOST > ~/.ssh/known_hosts + shell: bash + env: + SSH_HOST: ${{secrets.SSH_HOST}} + SSH_PORT: ${{secrets.SSH_PORT}} + + - name: Stop currently running instance + run: | + ssh $SSH_USER@$SSH_HOST $STOP_COMMAND + shell: bash + env: + SSH_USER: ${{secrets.SSH_USER}} + SSH_HOST: ${{secrets.SSH_HOST}} + STOP_COMMAND: ${{vars.STOP_COMMAND}} + + - name: Upload artifact + run: | + scp -r $UPLOAD_FROM $SSH_USER@$SSH_HOST:$UPLOAD_TO + shell: bash + env: + SSH_USER: ${{secrets.SSH_USER}} + SSH_HOST: ${{secrets.SSH_HOST}} + UPLOAD_FROM: ${{vars.UPLOAD_FROM}} + UPLOAD_TO: ${{vars.UPLOAD_TO}} + + - name: Start new instance + run: | + ssh $SSH_USER@$SSH_HOST $START_COMMAND + shell: bash + env: + SSH_USER: ${{secrets.SSH_USER}} + SSH_HOST: ${{secrets.SSH_HOST}} + START_COMMAND: ${{vars.START_COMMAND}} diff --git a/.gitignore b/.gitignore index 3e8ecb4..e40e3cf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ .idea/ -.venv/ \ No newline at end of file +.venv/ +build/ +dist/ +*.spec \ No newline at end of file diff --git a/main.py b/main.py index 1a480c1..5a71573 100644 --- a/main.py +++ b/main.py @@ -4,6 +4,7 @@ import client import asyncio from next.ext.commands import DefaultHelpCommand +from sys import exit async def main(): From 4b7b7bc0625fca5b5910626e349bf14d5cb5039d Mon Sep 17 00:00:00 2001 From: mctaylors Date: Wed, 6 Nov 2024 23:12:29 +0300 Subject: [PATCH 2/6] server: Fix stats by using ctx.author.server Signed-off-by: mctaylors --- .gitignore | 6 +++++- client.py | 5 ++--- main.py | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 3e8ecb4..a56dfdd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ .idea/ -.venv/ \ No newline at end of file +.venv/ +build/ +dist/ +__pycache__/ +*.spec \ No newline at end of file diff --git a/client.py b/client.py index 0ed35ae..a58fa4d 100644 --- a/client.py +++ b/client.py @@ -99,7 +99,6 @@ class Client(commands.CommandsClient): if server.banner is not None: banner = extensions.icon_info(server.banner) - state = server.state # used for statistics await ctx.send(f"## {server.name}\n" f"{description}\n" f"| ID | `{server.id}` |\n| --- | --- |\n" @@ -108,7 +107,7 @@ class Client(commands.CommandsClient): f"| Server banner | {banner} |\n" f"| Server owner | {server.owner.original_name}#{server.owner.discriminator} |\n" f"---\n| Statistics | Value |\n| --- | --- |\n" - f"| Members | {len(state.users)} |\n" - f"| Channels | {len(state.channels)} |\n" + f"| Members | {len(server.members)} |\n" + f"| Channels | {len(server.channels)} |\n" f"| Roles | {len(server.roles)} |\n" f"| Emojis | {len(server.emojis)} |") diff --git a/main.py b/main.py index 1a480c1..5a71573 100644 --- a/main.py +++ b/main.py @@ -4,6 +4,7 @@ import client import asyncio from next.ext.commands import DefaultHelpCommand +from sys import exit async def main(): From 92797df87304144f543cb94f2c970c5b9568b110 Mon Sep 17 00:00:00 2001 From: mctaylors Date: Wed, 6 Nov 2024 23:26:04 +0300 Subject: [PATCH 3/6] timestamp: Send formatted timestamp Signed-off-by: mctaylors --- client.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client.py b/client.py index a58fa4d..1f696aa 100644 --- a/client.py +++ b/client.py @@ -37,17 +37,17 @@ class Client(commands.CommandsClient): if x > y: message = randrange(y, x + 1) - await ctx.send(f"**{str(message)}** `({y};{x})`") + await ctx.send(f"**{message}** `({y};{x})`") return message = randrange(x, y + 1) - await ctx.send(f"**{str(message)}** `({x};{y})`") + await ctx.send(f"**{message}** `({x};{y})`") @commands.command() async def timestamp(self, ctx: commands.Context): """Shows current timestamp""" message = trunc(time()) - await ctx.send(str(message)) + await ctx.send(f"**{message}** ") @commands.command() async def self(self, ctx: commands.Context): From 4211f72b9d3c233b4a26d7cc739fdabb64270ae4 Mon Sep 17 00:00:00 2001 From: mctaylors Date: Wed, 6 Nov 2024 23:36:24 +0300 Subject: [PATCH 4/6] timestamp: Add chat syntax table Signed-off-by: mctaylors --- client.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/client.py b/client.py index 1f696aa..4bab57c 100644 --- a/client.py +++ b/client.py @@ -47,7 +47,16 @@ class Client(commands.CommandsClient): async def timestamp(self, ctx: commands.Context): """Shows current timestamp""" message = trunc(time()) - await ctx.send(f"**{message}** ") + await ctx.send(f"## {message}\n" + f"| Chat syntax | Result |\n" + f"| --- | --- |\n" + f"| `` | |\n" + f"| `` | |\n" + f"| `` | |\n" + f"| `` | |\n" + f"| `` | |\n" + f"| `` | |\n" + f"| `` | |") @commands.command() async def self(self, ctx: commands.Context): From befd494de2f5a6192a45f31ccdf806b0d48fd1f7 Mon Sep 17 00:00:00 2001 From: mctaylors Date: Thu, 7 Nov 2024 00:33:32 +0300 Subject: [PATCH 5/6] random: Show the given range as a table Signed-off-by: mctaylors --- client.py | 8 ++++---- extensions.py | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/client.py b/client.py index 4bab57c..f382ee3 100644 --- a/client.py +++ b/client.py @@ -36,12 +36,12 @@ class Client(commands.CommandsClient): return if x > y: - message = randrange(y, x + 1) - await ctx.send(f"**{message}** `({y};{x})`") + result = randrange(y, x + 1) + await ctx.send(extensions.random_message(result, y, x)) return - message = randrange(x, y + 1) - await ctx.send(f"**{message}** `({x};{y})`") + result = randrange(x, y + 1) + await ctx.send(extensions.random_message(result, x, y)) @commands.command() async def timestamp(self, ctx: commands.Context): diff --git a/extensions.py b/extensions.py index d92dc5e..96c6d4a 100644 --- a/extensions.py +++ b/extensions.py @@ -1,2 +1,8 @@ def icon_info(icon): return f"[{icon.filename}](<{icon.url}>) ({icon.width}x{icon.height})" + +def random_message(result, min, max): + return (f"## {result}\n" + f"| Min | Max |\n" + f"| --- | --- |\n" + f"|{min}|{max}|") From b5b801f07fb16d3857cd0350e205e8f8c96efccc Mon Sep 17 00:00:00 2001 From: mctaylors Date: Thu, 7 Nov 2024 00:43:07 +0300 Subject: [PATCH 6/6] timestamp: Add list[str] for timestamp styles Signed-off-by: mctaylors --- client.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/client.py b/client.py index f382ee3..4c284a8 100644 --- a/client.py +++ b/client.py @@ -46,17 +46,15 @@ class Client(commands.CommandsClient): @commands.command() async def timestamp(self, ctx: commands.Context): """Shows current timestamp""" - message = trunc(time()) - await ctx.send(f"## {message}\n" + timestamp = trunc(time()) + table = str() + styles = ['d', 'D', 't', 'T', 'f', 'F', 'R'] + for style in styles: + table = table + f"\n| `` | |" + await ctx.send(f"## {timestamp}\n" f"| Chat syntax | Result |\n" - f"| --- | --- |\n" - f"| `` | |\n" - f"| `` | |\n" - f"| `` | |\n" - f"| `` | |\n" - f"| `` | |\n" - f"| `` | |\n" - f"| `` | |") + f"| --- | --- |" + + table) @commands.command() async def self(self, ctx: commands.Context):