-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
74 lines (64 loc) · 2.51 KB
/
Copy pathmain.py
File metadata and controls
74 lines (64 loc) · 2.51 KB
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
import sys
import discord
import re
from yaml import safe_load, safe_dump
# Settings. Modify these.
token = '-'
guild_id = 0
admin_role_id = 0
# role_id = 0
anonchan_id = 0 # The anonymous board.
logger_id = 0 # The GM board that lets you see posters.
client = discord.Client()
@client.event
async def on_ready():
global guild
global admin_role
# global role
global anonchan
global logger
guild = discord.utils.get(client.guilds, id=guild_id)
admin_role = discord.utils.get(guild.roles, id=admin_role_id)
# role = discord.utils.get(guild.roles, id=role_id)
anonchan = discord.utils.get(guild.channels, id=anonchan_id)
logger = discord.utils.get(guild.channels, id=logger_id)
if guild == None or anonchan == None or logger == None:
print("I couldn't find a thing I needed! Aborting.")
sys.exit()
print(f'Anonymous Messenger up as {client.user} in guild {guild}')
# with open("blacklist.yaml", "r", encoding="utf-8") as blacklist:
# blacklist = safe_load(blacklist)
@client.event
async def on_message(message):
if message.author.bot:
return # Bot should not trigger on bots
if not isinstance(message.channel, discord.DMChannel):
return # Only trigger upon DM message
member = await guild.fetch_member(message.author.id)
if member == None:
await message.author.send("You are not in the guild.")
return # Only trigger if member is in guild
# if role not in member.roles and admin_role not in member.roles:
# await message.author.send("You don't have the right role to send an anonymous message.")
# return # Only trigger if they have the right role
# Ignore attachments
message.attachments = []
msg = message.clean_content
# Strip links
if re.match(r'http[s:(]\S*', msg) != None:
await message.author.send("Your message may not contain links.")
return
if msg == "":
await message.author.send("Couldn't send that message.")
return
embed = discord.Embed(description=msg, color=0xc0c0c0)
embed.set_author(
name="???", icon_url='https://cdn.discordapp.com/avatars/946571933930127391/492b7fc83d95886aa9f4b687ba9970d0.png')
# All checks passed, go ahead with posting.
await anonchan.send(embed=embed)
# Log the embed
embed.set_author(name=message.author.name,
icon_url=message.author.avatar_url)
await logger.send(embed=embed)
await message.author.send(f'Message sent to <#{anonchan_id}>!')
client.run(token)