forked from Infiziert90/Tsuzuru-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handle_messages.py
49 lines (32 loc) · 1.46 KB
/
handle_messages.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import asyncio
import discord
def message_init(new_client):
global client
client = new_client
async def handle_msg(message, content=None, embed=None, func=None):
func = func or client.send_message
try:
msg_answer = await client.start_private_message(message.author)
await func(msg_answer, content=content, embed=embed)
except (AttributeError, discord.Forbidden):
del_message = await func(message.channel, content=f"{content or ''}\n\nThis Message will getting deleted in 5min.", embed=embed)
asyncio.get_event_loop().call_later(300, lambda: asyncio.ensure_future(delete_user_message(del_message)))
async def private_msg(message, answer):
await handle_msg(message, content=answer)
async def private_msg_embed(message, embed):
await handle_msg(message, embed=embed)
async def private_msg_code(message, text):
await handle_msg(message, content=f"```\n{text}```")
async def private_msg_file(message, file, content):
async def _send_file_without_embed(msg, embed=None, **kwargs):
return await client.send_file(msg, file, **kwargs)
await handle_msg(message, content, func=_send_file_without_embed)
async def wait_for_message(message):
return await client.wait_for_message(author=message.author)
async def delete_user_message(message):
try:
await client.delete_message(message)
except (discord.Forbidden, discord.NotFound):
pass