-
Notifications
You must be signed in to change notification settings - Fork 0
/
audit-filter.py
63 lines (53 loc) · 1.89 KB
/
audit-filter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import discord
import requests
import asyncio
import os
from dotenv import loaddotenv
Load environment variables from a .env file (if applicable)
loaddotenv()
Discord bot token and webhook URL from environment variables
DISCORDTOKEN = os.getenv('DISCORDTOKEN')
DESTINATION_WEBHOOK_URL = os.getenv('DESTINATION_WEBHOOK_URL')
Channel IDs to monitor
CHANNEL_IDS = [
1261781408968347625,
1262412438733590558
]
def filter_message(content):
# Print the message content for debugging
# print(f"Checking message content: {content}")
# Return True for messages that do not contain 'broadcast', 'whitespace', or 'Camera'
return 'broadcast' not in content and 'whitespace' not in content and 'Camera' not in content
Create a client instance
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
@client.event
async def on_ready():
print(f'Logged in as {client.user}')
# Start the periodic task
client.loop.create_task(periodic_check())
@client.event
async def on_message(message):
# Skip messages from the bot itself
if message.author == client.user:
return
# Check if the message is from one of the specified channels
if message.channel.id in CHANNEL_IDS:
# Filter the message
if filter_message(message.content):
# Forward the message to the destination webhook
payload = {
'content': message.content,
}
response = requests.post(DESTINATION_WEBHOOK_URL, json=payload)
async def periodic_check():
while True:
await asyncio.sleep(30) # Wait for 30 seconds
# Add periodic tasks here if needed
Run the bot
if __name == "__main":
if not DISCORD_TOKEN or not DESTINATION_WEBHOOK_URL:
print("Environment variables for DISCORD_TOKEN or DESTINATION_WEBHOOK_URL are missing.")
else:
client.run(DISCORD_TOKEN)