-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from Appelsiini1/dev3
Notification broadcasting system
- Loading branch information
Showing
4 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
v1.14.11 | ||
- Fix advanced polls not ending correctly | ||
### |