-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutils.py
50 lines (39 loc) · 1.06 KB
/
utils.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
import re
import discord
from settings import *
from log import *
pattern_id = re.compile("<@!?(\d+)>")
def is_private(channel):
return isinstance(channel, discord.abc.PrivateChannel)
def is_allowed(channel):
return is_private(channel) or channel.name in ALLOWED_CHAN
async def is_admin(ctx):
return ctx.author.id in ADMIN
def mention(user_id):
return "<@{}>".format(user_id)
def get_user_id(m):
match = pattern_id.match(m)
if match is None:
return None
user_id = int(match.group(1))
return user_id
async def send_msg(msg_chunks, channel):
res = ''
c = 0
for m in msg_chunks:
c += 1
#log_info("chunk {}/{}".format(c, len(msg_chunks)))
if len(m) > 2000:
log_error("(send_msg) Message too long, cannot send.")
return 1
if len(res + m) > 2000:
await channel.send(res)
res = ''
res += m + "\n"
await channel.send(res)
return 0
def surround_markdown(msg):
res = "```markdown\n"
res += msg
res += "```"
return res