-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* v1.7.6 (#28) * EMBED, documentation * from_discord_embed, documentation * fixed methods from base class being referenced to inherited class * Fixed EMBED.from_discord_embed method copying base class methods * Better error reporting (TRACE) * embed copy fix * Better error checking, get_client() function * Better error reporting * README * v1.7.6 - WIP (#29) * Improved error reporting, retreive client object * removed warning * v1.7.6 (#30) # What's changed - get_client() - Gives returns discord.Client object - Improved logging - Added send modes : ["send", "edit", "clear-send"] - Update Examples w/ application layer example
- Loading branch information
1 parent
7797d63
commit e2c79d5
Showing
155 changed files
with
4,018 additions
and
1,191 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
29 changes: 29 additions & 0 deletions
29
Examples/Additional Application Layer Example/Coffee/app/app.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import framework, datetime, os, random | ||
|
||
|
||
|
||
already_sent = False | ||
randomized_images = [] | ||
|
||
IMAGE_PATH = "./app/images/" | ||
|
||
@framework.data_function | ||
def get_data(): | ||
global already_sent, randomized_images | ||
datum=datetime.datetime.now() | ||
if datum.hour == 10 and not already_sent: | ||
already_sent = True | ||
if not randomized_images: | ||
found_images = [os.path.join(IMAGE_PATH,x) for x in os.listdir("./app/images")] | ||
while found_images: | ||
randomized_images.append(found_images.pop(random.randrange(0,len(found_images)))) | ||
image = randomized_images.pop(0) | ||
text = \ | ||
"""\ | ||
Good morning @everyone\nDate: {:02d}.{:02d}.{:02d} - {:02d}:{:02d}\ | ||
""".format(datum.day,datum.month,datum.year,datum.hour,datum.minute) | ||
return text, framework.FILE(image) # Return message to be sent | ||
|
||
elif datum.hour == 11 and already_sent: | ||
already_sent = False | ||
return None # Return None if nothing is to be send |
Binary file added
BIN
+162 KB
...dditional Application Layer Example/Coffee/app/images/A_small_cup_of_coffee.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.8 MB
...ional Application Layer Example/Coffee/app/images/CA_Home_Coffee_in_cafe@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+136 KB
Examples/Additional Application Layer Example/Coffee/app/images/Cappuccino-2.webp
Binary file not shown.
Binary file added
BIN
+585 KB
...Additional Application Layer Example/Coffee/app/images/Roasted_coffee_beans.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+27.6 KB
... Application Layer Example/Coffee/app/images/istockphoto-1137365972-612x612.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+35.3 KB
...l Application Layer Example/Coffee/app/images/istockphoto-508347326-612x612.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11.7 KB
Examples/Additional Application Layer Example/Coffee/app/images/pexels-photo-302899.webp
Binary file not shown.
Binary file added
BIN
+19.3 KB
Examples/Additional Application Layer Example/Coffee/app/images/pexels-photo-312418.webp
Binary file not shown.
28 changes: 28 additions & 0 deletions
28
Examples/Additional Application Layer Example/Coffee/main_coffee.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
""" | ||
Description: | ||
This is an example of an additional application layer you can build with this framework. | ||
The application sends a message saying 'Good morning' every day at 10 AM and then sends a picture of a coffe cup from a randomized list. | ||
""" | ||
import framework as fw | ||
import app.app | ||
from framework import discord | ||
|
||
|
||
|
||
|
||
servers = [ | ||
fw.GUILD( | ||
guild_id=123456789, | ||
messages_to_send=[ | ||
|
||
fw.MESSAGE(start_period=None, end_period=10, data=app.app.get_data(), channel_ids=[123456789], mode="send", start_now=True) | ||
], | ||
generate_log=True | ||
) | ||
] | ||
|
||
|
||
############################################################################################ | ||
fw.run( token="YOUR TOKEN", server_list=servers) | ||
|
||
|
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
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
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
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,85 @@ | ||
diff --git a/Patches/http_rate_limit.patch b/Patches/http_rate_limit.patch | ||
deleted file mode 100644 | ||
index 757b434..0000000 | ||
--- a/Patches/http_rate_limit.patch | ||
+++ /dev/null | ||
@@ -1,40 +0,0 @@ | ||
-diff --git a/discord/http.py b/discord/http.py | ||
-index 3f63a75d..19fe6959 100644 | ||
---- a/discord/http.py | ||
-+++ b/discord/http.py | ||
-@@ -211,33 +211,9 @@ class HTTPClient: | ||
- | ||
- # we are being rate limited | ||
- if r.status == 429: | ||
-- if not r.headers.get('Via'): | ||
-- # Banned by Cloudflare more than likely. | ||
-- raise HTTPException(r, data) | ||
-- | ||
-- fmt = 'We are being rate limited. Retrying in %.2f seconds. Handled under the bucket "%s"' | ||
-- | ||
-- # sleep a bit | ||
-- retry_after = data['retry_after'] / 1000.0 | ||
-- log.warning(fmt, retry_after, bucket) | ||
-- | ||
-- # check if it's a global rate limit | ||
-- is_global = data.get('global', False) | ||
-- if is_global: | ||
-- log.warning('Global rate limit has been hit. Retrying in %.2f seconds.', retry_after) | ||
-- self._global_over.clear() | ||
-- | ||
-- await asyncio.sleep(retry_after) | ||
-- log.debug('Done sleeping for the rate limit. Retrying...') | ||
-- | ||
-- # release the global lock now that the | ||
-- # global rate limit has passed | ||
-- if is_global: | ||
-- self._global_over.set() | ||
-- log.debug('Global rate limit is now over.') | ||
-- | ||
-- continue | ||
-+ raise HTTPException(r, data) | ||
- | ||
-+ | ||
- # we've received a 500 or 502, unconditional retry | ||
- if r.status in {500, 502}: | ||
- await asyncio.sleep(1 + tries * 2) | ||
diff --git a/src/_discord/http.py b/src/_discord/http.py | ||
index cdefd1f..4e6ecd5 100644 | ||
--- a/src/_discord/http.py | ||
+++ b/src/_discord/http.py | ||
@@ -295,32 +295,7 @@ class HTTPClient: | ||
|
||
# we are being rate limited | ||
if response.status == 429: | ||
- if not response.headers.get('Via') or isinstance(data, str): | ||
- # Banned by Cloudflare more than likely. | ||
- raise HTTPException(response, data) | ||
- | ||
- fmt = 'We are being rate limited. Retrying in %.2f seconds. Handled under the bucket "%s"' | ||
- | ||
- # sleep a bit | ||
- retry_after: float = data['retry_after'] | ||
- _log.warning(fmt, retry_after, bucket) | ||
- | ||
- # check if it's a global rate limit | ||
- is_global = data.get('global', False) | ||
- if is_global: | ||
- _log.warning('Global rate limit has been hit. Retrying in %.2f seconds.', retry_after) | ||
- self._global_over.clear() | ||
- | ||
- await asyncio.sleep(retry_after) | ||
- _log.debug('Done sleeping for the rate limit. Retrying...') | ||
- | ||
- # release the global lock now that the | ||
- # global rate limit has passed | ||
- if is_global: | ||
- self._global_over.set() | ||
- _log.debug('Global rate limit is now over.') | ||
- | ||
- continue | ||
+ raise HTTPException(response, data) | ||
|
||
# we've received a 500, 502, or 504, unconditional retry | ||
if response.status in {500, 502, 504}: | ||
|
Oops, something went wrong.