Skip to content

Commit 95074f4

Browse files
authored
Optional dependancies, proxies, Pycord update (#167)
* Optional voice * Proxy * _generate_log_context types fix * Optional proxy requirement * optional.json * ytdl, event loop fix * Pycord update * rename.patch * Rename patches * Apply patches * Suppress ffmpeg errors * Check channel existence * Optional SQL and documentation
1 parent dfad7cb commit 95074f4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+5925
-3208
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22
settings.json
33
dist/**
44
test**
5-
build**
6-
__**
5+
build**

Examples/Additional Application Layer Example/Coffee/main_coffee.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
This is an example of an additional application layer you can build with this framework.
44
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.
55
"""
6+
from datetime import timedelta
67
import framework as fw
78
import app.app
89
from framework import discord
@@ -15,7 +16,7 @@
1516
snowflake=123456789,
1617
messages=[
1718

18-
fw.TextMESSAGE(start_period=None, end_period=10, data=app.app.get_data(), channels=[123456789], mode="send", start_now=True)
19+
fw.TextMESSAGE(start_period=None, end_period=timedelta(seconds=10), data=app.app.get_data(), channels=[123456789], mode="send", start_in=timedelta(seconds=0))
1920
],
2021
logging=True
2122
)

Examples/Automatic Generation/find_promo_channels.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
66
We pass the framework a user_callback function named `find_advertisement_channels` which autofills the `servers` list with GUILD objects.
77
"""
8+
from datetime import timedelta
89
import framework as fw
910

1011

@@ -31,21 +32,22 @@ async def find_advertisement_channels():
3132
channels.append(channel.id) # If so, add the channel id to the list
3233

3334
# Add the guild to the internal shilling list
34-
await fw.core.add_object(
35-
fw.GUILD(
36-
guild.id, # Guild id
37-
[ # List of messages
38-
fw.TextMESSAGE(None, # Start period
39-
5, # End period
40-
data_to_shill, # Data that will be sent
41-
channels, # List of channels to send the message to
42-
"send", # Sending moode (send, edit, clear-send)
43-
True # Should the message be sent immediately after adding it to the list
44-
)
45-
],
46-
True # Should the framework generate a log of sent messages for this guild
35+
if len(channels):
36+
await fw.core.add_object(
37+
fw.GUILD(
38+
guild.id, # Guild id
39+
[ # List of messages
40+
fw.TextMESSAGE(None, # Start period
41+
timedelta(seconds=5), # End period
42+
data_to_shill, # Data that will be sent
43+
channels, # List of channels to send the message to
44+
"send", # Sending moode (send, edit, clear-send)
45+
timedelta(seconds=0) # Should the message be sent immediately after adding it to the list
46+
)
47+
],
48+
True # Should the framework generate a log of sent messages for this guild
49+
)
4750
)
48-
)
4951

5052

5153
fw.run(

Examples/Dynamic Modification/main.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
It then dynamically adds an object, and later calls .update() method to change the initialization parameters
66
passed at the start.
77
"""
8-
8+
from datetime import timedelta
99
import asyncio
10-
import framework as fw
11-
from framework import trace
10+
import framework as fw
11+
1212

1313

1414
# Create a list in which we will automatically add guilds
@@ -35,7 +35,7 @@ async def user_task():
3535
if any([x in channel.name for x in allowed_strings]): # Check if any of the strings in allowed_strings are in the channel name
3636
channels.append(channel)
3737

38-
text_msg = fw.TextMESSAGE(None, 15, data_to_shill, channels, "send", True)
38+
text_msg = fw.TextMESSAGE(None, timedelta(seconds=5), data_to_shill, channels, "send", timedelta(seconds=0))
3939

4040
# Dynamically add a message to the list
4141
await fw.add_object(text_msg, guild.id)
@@ -44,11 +44,11 @@ async def user_task():
4444
# Dynamic text message modification of the shill data and send period
4545
#########################################################################
4646
await asyncio.sleep(10)
47-
trace("Updating the TextMESSAGE object")
47+
fw.trace("Updating the TextMESSAGE object")
4848
# Update the object
4949
await text_msg.update(data="Updated Data", end_period=60)
5050

51-
trace("Now shilling 'Updated Data' with period of 60 seconds")
51+
fw.trace("Now shilling 'Updated Data' with period of 60 seconds")
5252
#########################################################################
5353

5454
############################################################################################################################################################################

Examples/Logging/JSON files/main_rickroll.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from datetime import timedelta
2+
from framework import trace
13
import framework as fw
24

35
rolls = [
@@ -21,7 +23,7 @@ def get(st):
2123
fw.GUILD(
2224
snowflake=12345,
2325
messages=[
24-
fw.TextMESSAGE(None, 5, get(rolls.copy()), [12345], "edit", True)
26+
fw.TextMESSAGE(None, timedelta(seconds=5), get(rolls.copy()), [12345], "edit", timedelta(seconds=5))
2527
],
2628
logging=True
2729
)

Examples/Logging/SQL Logging/main_rickroll.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from datetime import timedelta
12
import framework as fw
23

34
rolls = [
@@ -21,7 +22,7 @@ def get(st):
2122
fw.GUILD(
2223
snowflake=12345,
2324
messages=[
24-
fw.TextMESSAGE(None, 5, get(rolls.copy()), [12345], "edit", True)
25+
fw.TextMESSAGE(None, timedelta(seconds=10), get(rolls.copy()), [12345], "edit", timedelta(seconds=5))
2526
],
2627
logging=True
2728
)
Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from datetime import timedelta
12
import framework, datetime, secret
23
from framework import discord
34

@@ -15,32 +16,27 @@ def get_data(parameter):
1516

1617
guilds = [
1718
framework.USER(
18-
user_id=123456789, # ID of server (guild) or a discord.Guild object
19-
messages=[ # List MESSAGE objects
19+
user_id=123456789, # ID of server (guild) or a discord.Guild object
20+
messages=[ # List MESSAGE objects
2021
framework.DirectMESSAGE(
21-
start_period=None, # If None, messages will be send on a fixed period (end period)
22-
end_period=15, # If start_period is None, it dictates the fixed sending period,
23-
# If start period is defined, it dictates the maximum limit of randomized period
24-
data=get_data(123), # Data you want to sent to the function (Can be of types : str, embed, file, list of types to the left
25-
# or function that returns any of above types(or returns None if you don't have any data to send yet),
26-
# where if you pass a function you need to use the framework.FUNCTION decorator on top of it ).
27-
mode="send", # "send" will send a new message every time, "edit" will edit the previous message, "clear-send" will delete
28-
# the previous message and then send a new one
29-
start_now=True # Start sending now (True) or wait until period
22+
start_period=None, # If None, messages will be send on a fixed period (end period)
23+
end_period=timedelta(seconds=15), # If start_period is None, it dictates the fixed sending period,
24+
# If start period is defined, it dictates the maximum limit of randomized period
25+
data=get_data(123), # Data you want to sent to the function (Can be of types : str, embed, file, list of types to the left
26+
# or function that returns any of above types(or returns None if you don't have any data to send yet),
27+
# where if you pass a function you need to use the framework.FUNCTION decorator on top of it ).
28+
mode="send", # "send" will send a new message every time, "edit" will edit the previous message, "clear-send" will delete
29+
# the previous message and then send a new one
30+
start_in=timedelta(seconds=0) # Start sending now (True) or wait until period
3031
),
3132
],
32-
logging=True ## Generate file log of sent messages (and failed attempts) for this user
33+
logging=True # Generate file log of sent messages (and failed attempts) for this user
3334
)
3435
]
3536

3637
############################################################################################
3738

38-
if __name__ == "__main__":
39-
framework.run( token=secret.C_TOKEN, # MANDATORY,
40-
intents=discord.Intents.default(), # OPTIONAL (see https://docs.pycord.dev/en/master/intents.html)
41-
server_list=guilds, # OPTIONAL (if not provided, the objects need to be added via add_object function)
42-
is_user=False, # OPTIONAL
43-
user_callback=None, # OPTIONAL
44-
server_log_output="History", # OPTIONAL
45-
debug=True) # OPTIONAL
39+
framework.run(token=secret.C_TOKEN,
40+
server_list=guilds,
41+
is_user=False)
4642

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from datetime import timedelta
12
import framework as fw, secret
23
from framework import discord
34
############################################################################################
@@ -12,12 +13,12 @@
1213
author_icon="https://solarsystem.nasa.gov/system/basic_html_elements/11561_Sun.png",
1314
fields=\
1415
[
15-
fw.EmbedFIELD("Test 1", "Hello World", True),
16-
fw.EmbedFIELD("Test 2", "Hello World 2", True),
17-
fw.EmbedFIELD("Test 3", "Hello World 3", True),
18-
fw.EmbedFIELD("No Inline", "This is without inline", False),
19-
fw.EmbedFIELD("Test 4", "Hello World 4", True),
20-
fw.EmbedFIELD("Test 5", "Hello World 5", True)
16+
discord.EmbedField("Test 1", "Hello World", True),
17+
discord.EmbedField("Test 2", "Hello World 2", True),
18+
discord.EmbedField("Test 3", "Hello World 3", True),
19+
discord.EmbedField("No Inline", "This is without inline", False),
20+
discord.EmbedField("Test 4", "Hello World 4", True),
21+
discord.EmbedField("Test 5", "Hello World 5", True)
2122
],
2223
## ... for other arguments, see https://github.com/davidhozic/discord-advertisement-framework
2324
)
@@ -41,41 +42,27 @@
4142
############################################################################################
4243
guilds = [
4344
fw.USER(
44-
user_id=123456789, # ID of server (guild) or a discord.Guild object
45-
messages=[ # List MESSAGE objects
45+
user_id=123456789, # ID of server (guild) or a discord.Guild object
46+
messages=[ # List MESSAGE objects
4647
fw.DirectMESSAGE(
47-
start_period=None, # If None, messages will be send on a fixed period (end period)
48-
end_period=15, # If start_period is None, it dictates the fixed sending period,
49-
# If start period is defined, it dictates the maximum limit of randomized period
50-
data=test_embed1, # Data you want to sent to the function (Can be of types : str, embed, file, list of types to the left
51-
# or function that returns any of above types(or returns None if you don't have any data to send yet),
52-
# where if you pass a function you need to use the fw.FUNCTION decorator on top of it ).
53-
mode="send", # "send" will send a new message every time, "edit" will edit the previous message, "clear-send" will delete
54-
# the previous message and then send a new one
55-
start_now=True # Start sending now (True) or wait until period
56-
),
57-
58-
fw.DirectMESSAGE(
59-
start_period=None,
60-
end_period=15,
61-
62-
data=test_embed_fw_2,
63-
64-
mode="send",
65-
start_now=True
48+
start_period=None, # If None, messages will be send on a fixed period (end period)
49+
end_period=timedelta(seconds=15), # If start_period is None, it dictates the fixed sending period,
50+
# If start period is defined, it dictates the maximum limit of randomized period
51+
data=test_embed1, # Data you want to sent to the function (Can be of types : str, embed, file, list of types to the left
52+
# or function that returns any of above types(or returns None if you don't have any data to send yet),
53+
# where if you pass a function you need to use the fw.FUNCTION decorator on top of it ).
54+
mode="send", # "send" will send a new message every time, "edit" will edit the previous message, "clear-send" will delete
55+
# the previous message and then send a new one
56+
start_in=timedelta(seconds=0) # Start sending now (True) or wait until period
6657
),
6758
],
68-
logging=True ## Generate file log of sent messages (and failed attempts) for this user
59+
logging=True # Generate file log of sent messages (and failed attempts) for this user
6960
)
7061
]
7162

7263
############################################################################################
7364

74-
if __name__ == "__main__":
75-
fw.run( token=secret.C_TOKEN, # MANDATORY
76-
intents=discord.Intents.default(), # OPTIONAL (see https://docs.pycord.dev/en/master/intents.html)
77-
server_list=guilds, # MANDATORY
78-
is_user=False, # OPTIONAL
79-
user_callback=None, # OPTIONAL
80-
server_log_output="History", # OPTIONAL
81-
debug=True) # OPTIONAL
65+
fw.run(token=secret.C_TOKEN,
66+
server_list=guilds,
67+
is_user=False)
68+

Examples/Message Types/DirectMESSAGE/main_send_file.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
messages=[ # List MESSAGE objects
1717
framework.DirectMESSAGE(
1818
start_period=None, # If None, messages will be send on a fixed period (end period)
19-
end_period=15, # If start_period is None, it dictates the fixed sending period,
19+
end_period=timedelta(seconds=15), # If start_period is None, it dictates the fixed sending period,
2020
# If start period is defined, it dictates the maximum limit of randomized period
2121
data=l_file, # Data you want to sent to the function (Can be of types : str, embed, file, list of types to the left
2222
# or function that returns any of above types(or returns None if you don't have any data to send yet),
2323
# where if you pass a function you need to use the framework.FUNCTION decorator on top of it ).
2424
mode="send", # "send" will send a new message every time, "edit" will edit the previous message, "clear-send" will delete
2525
# the previous message and then send a new one
26-
start_now=True # Start sending now (True) or wait until period
26+
start_in=timedelta(seconds=0) # Start sending now (True) or wait until period
2727
),
2828
],
2929
logging=True ## Generate file log of sent messages (and failed attempts) for this user
@@ -32,12 +32,7 @@
3232

3333
############################################################################################
3434

35-
if __name__ == "__main__":
36-
framework.run( token=secret.C_TOKEN, # MANDATORY
37-
intents=discord.Intents.default(), # OPTIONAL (see https://docs.pycord.dev/en/master/intents.html)
38-
server_list=guilds, # MANDATORY
39-
is_user=False, # OPTIONAL
40-
user_callback=None, # OPTIONAL
41-
server_log_output="History", # OPTIONAL
42-
debug=True) # OPTIONAL
35+
framework.run(token=secret.C_TOKEN,
36+
server_list=guilds,
37+
is_user=False)
4338

0 commit comments

Comments
 (0)