Skip to content

Commit 961c341

Browse files
authored
Example updates, bug fixes (#135)
1 parent f3b307d commit 961c341

File tree

18 files changed

+138
-75
lines changed

18 files changed

+138
-75
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212

1313
servers = [
1414
fw.GUILD(
15-
guild_id=123456789,
16-
messages_to_send=[
15+
snowflake=123456789,
16+
messages=[
1717

18-
fw.TextMESSAGE(start_period=None, end_period=10, data=app.app.get_data(), channel_ids=[123456789], mode="send", start_now=True)
18+
fw.TextMESSAGE(start_period=None, end_period=10, data=app.app.get_data(), channels=[123456789], mode="send", start_now=True)
1919
],
20-
generate_log=True
20+
logging=True
2121
)
2222
]
2323

Examples/Additional Application Layer Example/Scheduled messages/BOT/main_obv.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,11 @@ async def main():
250250
# Create the server list
251251
servers = [
252252
fw.GUILD (
253-
guild_id=guild["SERVER-ID"],
254-
messages_to_send= [
253+
snowflake=guild["SERVER-ID"],
254+
messages= [
255255
fw.TextMESSAGE(None, 1, get_data(ch_id), [ch_id], "send", True) for ch_id in guild["CHANNEL-IDs"]
256256
],
257-
generate_log=True
257+
logging=True
258258
) for guild in conf.WHITELISTED_GUILDS
259259
]
260260

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
"""
2+
The following example automatically generates the shilling list if the channel name matches
3+
any of the allowed_strings words.
4+
5+
It then dynamically adds an object, and later calls .update() method to change the initialization parameters
6+
passed at the start.
7+
"""
8+
9+
import asyncio
10+
import framework as fw
11+
from framework import trace
12+
13+
14+
# Create a list in which we will automatically add guilds
15+
allowed_strings = {"shill", "advert", "promo"}
16+
data_to_shill = ( # Example data set
17+
"Hello World",
18+
fw.EMBED(title="Example Embed",
19+
color=fw.EMBED.Color.blue(),
20+
description="This is a test embed")
21+
)
22+
23+
24+
async def user_task():
25+
# Returns the client to send commands to discord, for more info about client see https://docs.pycord.dev/en/master/api.html?highlight=discord%20client#discord.Client
26+
client = fw.get_client()
27+
for guild in client.guilds: # Iterate thru all the guilds where the bot is in
28+
await fw.add_object(
29+
fw.GUILD(guild.id, logging=True)
30+
)
31+
32+
# Find channels that match allowed_strings
33+
channels = []
34+
for channel in guild.text_channels: # Iterate thru all the text channels in the guild
35+
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
36+
channels.append(channel)
37+
38+
text_msg = fw.TextMESSAGE(None, 15, data_to_shill, channels, "send", True)
39+
40+
# Dynamically add a message to the list
41+
await fw.add_object(text_msg, guild.id)
42+
43+
#########################################################################
44+
# Dynamic text message modification of the shill data and send period
45+
#########################################################################
46+
await asyncio.sleep(10)
47+
trace("Updating the TextMESSAGE object")
48+
# Update the object
49+
await text_msg.update(data="Updated Data", end_period=60)
50+
51+
trace("Now shilling 'Updated Data' with period of 60 seconds")
52+
#########################################################################
53+
54+
############################################################################################################################################################################
55+
56+
57+
############################################################################################
58+
if __name__ == "__main__":
59+
fw.run(token="OOFOAFO321o3oOOAOO$Oo$o$@O4242",
60+
user_callback=user_task)
61+

Examples/Logging/JSON files/main_rickroll.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ def get(st):
1919

2020
servers = [
2121
fw.GUILD(
22-
guild_id=12345,
23-
messages_to_send=[
22+
snowflake=12345,
23+
messages=[
2424
fw.TextMESSAGE(None, 5, get(rolls.copy()), [12345], "edit", True)
2525
],
26-
generate_log=True
26+
logging=True
2727
)
2828
]
2929

Examples/Logging/SQL Logging/main_rickroll.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ def get(st):
1919

2020
servers = [
2121
fw.GUILD(
22-
guild_id=12345,
23-
messages_to_send=[
22+
snowflake=12345,
23+
messages=[
2424
fw.TextMESSAGE(None, 5, get(rolls.copy()), [12345], "edit", True)
2525
],
26-
generate_log=True
26+
logging=True
2727
)
2828
]
2929

Examples/Message Types/DirectMESSAGE/main_data_function.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ def get_data(parameter):
1515

1616
guilds = [
1717
framework.USER(
18-
user_id=123456789, # ID of server (guild)
19-
messages_to_send=[ # List MESSAGE objects
18+
user_id=123456789, # ID of server (guild) or a discord.Guild object
19+
messages=[ # List MESSAGE objects
2020
framework.DirectMESSAGE(
2121
start_period=None, # If None, messages will be send on a fixed period (end period)
2222
end_period=15, # If start_period is None, it dictates the fixed sending period,
@@ -29,7 +29,7 @@ def get_data(parameter):
2929
start_now=True # Start sending now (True) or wait until period
3030
),
3131
],
32-
generate_log=True ## Generate file log of sent messages (and failed attempts) for this user
32+
logging=True ## Generate file log of sent messages (and failed attempts) for this user
3333
)
3434
]
3535

Examples/Message Types/DirectMESSAGE/main_send_embed.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
############################################################################################
4242
guilds = [
4343
fw.USER(
44-
user_id=123456789, # ID of server (guild)
45-
messages_to_send=[ # List MESSAGE objects
44+
user_id=123456789, # ID of server (guild) or a discord.Guild object
45+
messages=[ # List MESSAGE objects
4646
fw.DirectMESSAGE(
4747
start_period=None, # If None, messages will be send on a fixed period (end period)
4848
end_period=15, # If start_period is None, it dictates the fixed sending period,
@@ -65,7 +65,7 @@
6565
start_now=True
6666
),
6767
],
68-
generate_log=True ## Generate file log of sent messages (and failed attempts) for this user
68+
logging=True ## Generate file log of sent messages (and failed attempts) for this user
6969
)
7070
]
7171

Examples/Message Types/DirectMESSAGE/main_send_file.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
guilds = [
1414
framework.USER(
15-
user_id=123456789, # ID of server (guild)
16-
messages_to_send=[ # List MESSAGE objects
15+
user_id=123456789, # ID of server (guild) or a discord.Guild object
16+
messages=[ # List MESSAGE objects
1717
framework.DirectMESSAGE(
1818
start_period=None, # If None, messages will be send on a fixed period (end period)
1919
end_period=15, # If start_period is None, it dictates the fixed sending period,
@@ -26,7 +26,7 @@
2626
start_now=True # Start sending now (True) or wait until period
2727
),
2828
],
29-
generate_log=True ## Generate file log of sent messages (and failed attempts) for this user
29+
logging=True ## Generate file log of sent messages (and failed attempts) for this user
3030
)
3131
]
3232

Examples/Message Types/DirectMESSAGE/main_send_multiple.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828

2929
guilds = [
3030
framework.USER(
31-
user_id=123456789, # ID of server (guild)
32-
messages_to_send=[ # List MESSAGE objects
31+
user_id=123456789, # ID of server (guild) or a discord.Guild object
32+
messages=[ # List MESSAGE objects
3333
framework.DirectMESSAGE(
3434
start_period=None, # If None, messages will be send on a fixed period (end period)
3535
end_period=15, # If start_period is None, it dictates the fixed sending period,
@@ -43,7 +43,7 @@
4343
start_now=True # Start sending now (True) or wait until period
4444
),
4545
],
46-
generate_log=True ## Generate file log of sent messages (and failed attempts) for this user
46+
logging=True ## Generate file log of sent messages (and failed attempts) for this user
4747
)
4848
]
4949

Examples/Message Types/DirectMESSAGE/main_send_string.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
guilds = [
1111
framework.USER(
12-
user_id=123456789, # ID of server (guild)
13-
messages_to_send=[ # List MESSAGE objects
12+
user_id=123456789, # ID of server (guild) or a discord.Guild object
13+
messages=[ # List MESSAGE objects
1414
framework.DirectMESSAGE(
1515
start_period=None, # If None, messages will be send on a fixed period (end period)
1616
end_period=15, # If start_period is None, it dictates the fixed sending period,
@@ -22,9 +22,9 @@
2222
# the previous message and then send a new one
2323
start_now=True # Start sending now (True) or wait until period
2424
),
25-
framework.TextMESSAGE(start_period=5, end_period=10, data="Second Message", channel_ids=[12345], mode="send", start_now=True)
25+
framework.TextMESSAGE(start_period=5, end_period=10, data="Second Message", channels=[12345], mode="send", start_now=True)
2626
],
27-
generate_log=True ## Generate file log of sent messages (and failed attempts) for this user
27+
logging=True ## Generate file log of sent messages (and failed attempts) for this user
2828
)
2929
]
3030

0 commit comments

Comments
 (0)