Skip to content

Commit

Permalink
Discord Webhook Module
Browse files Browse the repository at this point in the history
* Discord Webhook Module
  • Loading branch information
cyberofficial committed Aug 1, 2023
1 parent f8cb8d6 commit 5f3754b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
25 changes: 25 additions & 0 deletions modules/discord.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import requests
import re
import json

def send_to_discord_webhook(webhook_url, text):
data = {
"content": text
}
headers = {
"Content-Type": "application/json"
}
try:
if len(text) > 1800:
for i in range(0, len(text), 1800):
data["content"] = text[i:i+1800]
response = requests.post(webhook_url, data=json.dumps(data), headers=headers)
if response.status_code == 429:
print("Discord webhook is being rate limited.")
else:
response = requests.post(webhook_url, data=json.dumps(data), headers=headers)
if response.status_code == 429:
print("Discord webhook is being rate limited.")
except:
print("Failed to send message to Discord webhook.")
pass
22 changes: 1 addition & 21 deletions transcribe_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@

from modules.version_checker import check_for_updates
from modules.model_downloader import fine_tune_model_dl, fine_tune_model_dl_compressed
from modules.discord import send_to_discord_webhook

# Code is semi documented, but if you have any questions, feel free to ask in the Discussions tab.

Expand All @@ -116,27 +117,6 @@ def set_window_title(detected_language, confidence):
sys.stdout.write(f"\x1b]2;{title}\x1b\x5c")
sys.stdout.flush()

def send_to_discord_webhook(webhook_url, text):
data = {
"content": text
}
headers = {
"Content-Type": "application/json"
}
try:
if len(text) > 1800:
for i in range(0, len(text), 1800):
data["content"] = text[i:i+1800]
response = requests.post(webhook_url, data=json.dumps(data), headers=headers)
if response.status_code == 429:
print("Discord webhook is being rate limited.")
else:
response = requests.post(webhook_url, data=json.dumps(data), headers=headers)
if response.status_code == 429:
print("Discord webhook is being rate limited.")
except:
print("Failed to send message to Discord webhook.")
pass

def is_input_device(device_index):
pa = pyaudio.PyAudio()
Expand Down

0 comments on commit 5f3754b

Please sign in to comment.