-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple channels, Attachments and Docker #9
base: master
Are you sure you want to change the base?
Conversation
This reverts commit f50fd48.
Multiple channels
Github actions setup
Updating docker file for requirements location
Causes failures in pyproject.toml
[default] | ||
# Create a discord channels, and copy the channel ID to this default section. | ||
# if this section is missing it will fail to start | ||
# for subsequent sections, is no channel ID is specified it will default to this ID. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# for subsequent sections, is no channel ID is specified it will default to this ID. | |
# for subsequent sections, if no channel ID is specified it will default to this ID. |
@@ -69,6 +153,10 @@ def discord_field(self, name, value="", inline=False): | |||
"inline": inline | |||
} | |||
return r | |||
#def discord_field(self, name, value="", inline=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the discord_field
function isn't actually used anymore, so it should be deleted.
self.client.channelid = channelid | ||
self.client.subject = subject | ||
self.client.embeds = discord.Embed(title=subject,description="desc") | ||
self.client.embeds.add_field(name="To",value=to_addr,inline=False) | ||
print(f'Email To: "{to_addr}"') | ||
self.client.embeds.add_field(name="From",value=from_addr) | ||
print(f'Email From: "{from_addr}"') | ||
self.client.embeds.add_field(name="Subject",value=subject) | ||
if body is not None: | ||
chunklength = 1000 | ||
chunks = [body[i:i+chunklength] for i in range(0,len(body),chunklength)] | ||
print('Email Body length: %s = %s chunks' % (len(body),len(chunks))) | ||
chunknum = 1 | ||
for chunk in chunks: | ||
self.client.embeds.add_field(name="Body-%s" %chunknum,value=chunk) | ||
chunknum += 1 | ||
|
||
print('Adding Attachments: %s' % len(attachments) ) | ||
self.client.files = attachments | ||
|
||
print('Sending email') | ||
#reset flag | ||
self.client.msg_sent = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one's a bit of a bigger comment, but I don't really like how this tells the discord bot to send the message. It looks like this is setting some fields in the bot object, then turning on the msg_sent
flag which the bot looks for in a loop. But I suspect that will have concurrency issues (like if multiple messages come in at once).
I think a better way would be to send an event, passing all of the information as parameters. It looks relatively easy to send custom events:
https://stackoverflow.com/questions/64810905/how-do-i-emit-custom-discord-py-events
Then instead of a timer, you could simply register that event and send the message when it fires.
I'm envisioning something along the lines of
embeds = discord.Embed(title=subject,description="desc")
embeds.add_field(name="To",value=to_addr,inline=False)
...
print('Sending email')
await client.emit('send_email', channelid, subject, embeds, attachments)
Then in the bot, instead of
@tasks.loop(seconds=1)
async def timer(self):
try:
if not self.msg_sent:
print("Email content passed to bot for processing.")
...
it would be like:
async def on_send_email(channelid, subject, embeds, attachments):
print("Email content passed to bot for processing.")
# all the stuff for sending the message to the channel
...
Is this something you'd want to try doing? If not, I can accept this as-is and give it a shot.
@@ -0,0 +1,15 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, the repo shouldn't include IDE configuration files. I'd delete this file and add .vscode to the gitignore
Added a few features.