-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
75 lines (59 loc) · 2.21 KB
/
bot.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
64
65
66
67
68
69
70
71
72
73
74
75
# A discord cross-guild chatbot
import discord
import aiohttp
import dotenv
import os
import re
dotenv.load_dotenv()
token = str(os.getenv("TOKEN"))
intents = discord.Intents.default()
intents.message_content = True
bot = discord.Bot(intents = intents)
@bot.event
async def on_ready():
print(f"{bot.user} is ready and online!")
@bot.slash_command(name = "Hi", description = "Hi")
async def hello(self):
await self.respond("Hey")
print(self.author)
def loopholes(message):
"""
Checking for infinite loops & mass pings
"""
if (
re.search("@everyone", message.content) or re.search("@here", message.content) or
message.author.id == bot.user.id or isinstance(message.author, discord.Webhook)
or re.search(".*#0000", str(message.author))
):
return False
else:
return True
class stream_webhook_data:
def __init__(self):
self.webhook_dict = {
# ---- to be improved ------
# fill it with channel id and webhook links ... the bot sends msg to every link mentioned here ... ( --- to be improved ---)
# ---- to be improved ------
} # {channel_id : webhook_link}
def fetch(self, message):
if message.channel.id in self.webhook_dict:
return True
else:
return False
def fetch_link(self, message):
"""
assuming the key-value pair exists
"""
for key, value in self.webhook_dict.items():
if key != message.channel.id:
yield value
@bot.event
async def on_message(message):
if loopholes(message):
nexus = stream_webhook_data() # super random name go brrrrr
if nexus.fetch(message):
async with aiohttp.ClientSession() as session:
for webhook_link in nexus.fetch_link(message):
webhook = discord.Webhook.from_url(webhook_link, session = session)
await webhook.send(f"{message.content}", username=f'[{message.guild.name}] {message.author.name}', avatar_url=message.author.avatar)
bot.run(os.getenv("TOKEN"))