-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
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,54 @@ | ||
import selfcord | ||
import re | ||
from discord_webhook import DiscordWebhook | ||
#put the server and channel IDs here, preferably above the channel you want to listen to. comma separate them with no spaces | ||
serverids = [] | ||
channelids = [] | ||
|
||
#put URLs of webhooks you want to send the images to- quote enclosed and comma separated. using only 1 webhook is ok | ||
WEBHOOK_URL = ["",] | ||
#put the token of the listener account here | ||
DISCORD_USER_TOKEN = "" | ||
|
||
#put the listener account's ID here so it doesnt relay its own messages | ||
BOT_ID = | ||
LISTEN_GUILD_IDS = serverids | ||
LISTEN_CHANNEL_IDS = channelids | ||
|
||
def main(): | ||
dc = selfcord.Client() | ||
|
||
@dc.event | ||
async def on_ready(): | ||
print(f"Listening User: {dc.user}") | ||
|
||
@dc.event | ||
async def on_message(message): | ||
guild_id = message.guild.id | ||
if guild_id not in LISTEN_GUILD_IDS: | ||
return | ||
|
||
channel_id = message.channel.id | ||
if channel_id not in LISTEN_CHANNEL_IDS: | ||
return | ||
|
||
author_id = message.author.id | ||
if author_id == BOT_ID: | ||
return | ||
|
||
if not message.attachments: | ||
return | ||
attachmentUnformatted = message.attachments #get the message's attachment, it is not returned as a string | ||
attachmentLastSplit = re.split(r".*url='", str(attachmentUnformatted))[1] #split it at the URL part and also cast it to a string | ||
attachmentURL = attachmentLastSplit[: len (attachmentLastSplit) - 3] #remove the last three characters and assign it to the final variable | ||
|
||
msg_to_send = f"[{str(message.guild.name).upper()}] {message.author.name}:\t{attachmentURL}" | ||
|
||
for i in range(0, len(WEBHOOK_URL)): #iterate through the webhook URLs in case you want to send to multiple places | ||
webhook = DiscordWebhook(url=WEBHOOK_URL[i], username='Unify', content=msg_to_send) | ||
webhook.execute() | ||
|
||
dc.run(DISCORD_USER_TOKEN) | ||
|
||
if __name__ == '__main__': | ||
main() |
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,2 @@ | ||
discord-webhook | ||
git+https://github.com/dolfies/discord.py-self@renamed#egg=selfcord.py[voice] |