From 9d2f64f892dd80dc0f5dae2d57efcfc97e91b920 Mon Sep 17 00:00:00 2001 From: Appelsiini1 <37345715+Appelsiini1@users.noreply.github.com> Date: Sun, 6 Jun 2021 20:04:55 +0300 Subject: [PATCH 1/2] Add webhook broadcasting script for service updates --- .gitignore | 2 ++ webhook/updateBroadcaster.py | 53 ++++++++++++++++++++++++++++++++++++ webhook/versions.txt | 3 ++ 3 files changed, 58 insertions(+) create mode 100644 webhook/updateBroadcaster.py create mode 100644 webhook/versions.txt diff --git a/.gitignore b/.gitignore index 19b5469..d839993 100644 --- a/.gitignore +++ b/.gitignore @@ -94,6 +94,7 @@ venv/ ENV/ env.bak/ venv.bak/ +urls.txt # Spyder project settings .spyderproject @@ -121,6 +122,7 @@ modules/test_module.py #Log Coralog.txt +broadcaster_log.txt #Database Databases/ \ No newline at end of file diff --git a/webhook/updateBroadcaster.py b/webhook/updateBroadcaster.py new file mode 100644 index 0000000..a8dc91c --- /dev/null +++ b/webhook/updateBroadcaster.py @@ -0,0 +1,53 @@ +import requests +import logging + + +def main(): + logging.basicConfig( + filename="broadcaster_log.txt", + level=logging.INFO, + format="%(asctime)s %(levelname)s - %(message)s", + datefmt="%d/%m/%Y %H:%M:%S", + ) + + with open("urls.txt", "r") as f: + urls = f.readlines() + + with open("versions.txt", "r") as f: + txtFromFile = f.readline() + if txtFromFile.startswith("v"): + title = f"New version of CoraBot is live!" + version = txtFromFile + txtFromFile = f.readline() + + text = f"**{version}**\n" + while txtFromFile.strip() != "###": + text += txtFromFile + txtFromFile = f.readline() + + # for all params, see https://discordapp.com/developers/docs/resources/webhook#execute-webhook + data = { + "username": "CoraBot Updates", + "avatar_url": "https://media.discordapp.net/attachments/693166291468681227/851120811393417216/cora_pfp_update_pride.png", + } + + # for all params, see https://discordapp.com/developers/docs/resources/channel#embed-object + data["embeds"] = [{"description": text, "title": title}] + + for i, url in enumerate(urls): + if url.strip() == "": + continue + result = requests.post(url.strip(), json=data) + + try: + result.raise_for_status() + except requests.exceptions.HTTPError: + logging.exception("Error occured while sending message:") + else: + logging.info( + f"Payload {i} delivered successfully, code {result.status_code}." + ) + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/webhook/versions.txt b/webhook/versions.txt new file mode 100644 index 0000000..c65e58d --- /dev/null +++ b/webhook/versions.txt @@ -0,0 +1,3 @@ +v1.14.11 +- Fix advanced polls not ending correctly +### \ No newline at end of file From 95304acc42d3f9f38da76dc3ca7476fd4e83c34d Mon Sep 17 00:00:00 2001 From: Appelsiini1 <37345715+Appelsiini1@users.noreply.github.com> Date: Sun, 6 Jun 2021 20:05:25 +0300 Subject: [PATCH 2/2] Add workflow to run broadcaster --- .github/workflows/notifications.yml | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .github/workflows/notifications.yml diff --git a/.github/workflows/notifications.yml b/.github/workflows/notifications.yml new file mode 100644 index 0000000..c6c9db4 --- /dev/null +++ b/.github/workflows/notifications.yml @@ -0,0 +1,31 @@ +# This is a basic workflow to help you get started with Actions + +name: Notification system + +# Controls when the action will run. +on: + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + + # Runs a single command using the runners shell + - name: executing remote ssh commands using key + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.HOST }} + username: ${{ secrets.USERNAME }} + key: ${{ secrets.KEY }} + port: ${{ secrets.PORT }} + script: | + cd ~/CoraBot/webhook + python3 updateBroadcaster.py