-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.py
52 lines (43 loc) · 1.59 KB
/
script.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
import discord
import asyncio
import config
client = discord.Client()
def username(user):
res = user.name
if user.nick:
res = "{} ({})".format(user.nick, user.name)
return res.replace(":", "")
def get_channel(message):
server_id = message.server.id
channel_or_none = config.log_channels.get(server_id)
return client.get_channel(channel_or_none) or message.channel
def sanitize(msg):
return msg.replace("\n", "\\n").replace("`", " \` ")
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
@client.event
async def on_message(message):
if message.content.startswith("!help"):
await client.send_message(message.channel, "no")
@client.event
async def on_message_delete(message):
if message.author == client.user:
return
content_sanitized = sanitize(message.clean_content)
author = username(message.author)
await client.send_message(get_channel(message),
":wastebasket: {} deleted from <#{}>: {}".format(author, message.channel.id, content_sanitized))
@client.event
async def on_message_edit(before, after):
if before.author == client.user or before.clean_content == after.clean_content:
return
author = username(before.author)
before_sanitized = sanitize(before.clean_content)
after_sanitized = sanitize(after.clean_content)
await client.send_message(get_channel(before),
":pencil2: {} edited in <#{}>:\n**From:** {}\n**To:** {}".format(author, before.channel.id, before_sanitized, after_sanitized))
client.run(config.token)