Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notification broadcasting system #58

Merged
merged 2 commits into from
Jun 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/notifications.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ venv/
ENV/
env.bak/
venv.bak/
urls.txt

# Spyder project settings
.spyderproject
Expand Down Expand Up @@ -121,6 +122,7 @@ modules/test_module.py

#Log
Coralog.txt
broadcaster_log.txt

#Database
Databases/
53 changes: 53 additions & 0 deletions webhook/updateBroadcaster.py
Original file line number Diff line number Diff line change
@@ -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()
3 changes: 3 additions & 0 deletions webhook/versions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
v1.14.11
- Fix advanced polls not ending correctly
###