diff --git a/bot.py b/bot.py new file mode 100644 index 0000000..2591004 --- /dev/null +++ b/bot.py @@ -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() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..466b22c --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +discord-webhook +git+https://github.com/dolfies/discord.py-self@renamed#egg=selfcord.py[voice] \ No newline at end of file