Skip to content

Commit

Permalink
Merge pull request #58 from Appelsiini1/dev3
Browse files Browse the repository at this point in the history
Notification broadcasting system
  • Loading branch information
Appelsiini1 authored Jun 6, 2021
2 parents 4e50dca + 95304ac commit 69d3799
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
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
###

0 comments on commit 69d3799

Please sign in to comment.