-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
69 lines (56 loc) · 1.84 KB
/
utils.py
File metadata and controls
69 lines (56 loc) · 1.84 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
from config import config
import database
import plugin
import json
import requests
import re
import discord
from discord.ext import commands
class Msg:
text: str = ""
user_text: str
chat_id: int
msg_id: int
from_id: int
user: database.User
username: str = None
reply_id: int = None
reply_msg = None
attachments: list
real_name: str
skip: bool = False
command: str = ""
argv: list
is_command: bool = False
has_prefix: bool = False
message: discord.Message = None
client: commands.Bot = None
is_cmd_regex = re.compile(f'^/?\\s?(?P<bot_name>{"|".join(config.names)})?\\s?', re.IGNORECASE)
def parse_msg(self, update: discord.Message):
self.text = update.clean_content
self.chat_id = update.channel.id
self.msg_id = update.id
self.from_id = update.author.id
self.user = database.users.get(self.from_id)
self.username = update.author.name
self.real_name = update.author.global_name
self.attachments = update.attachments
self.message = update
def parse_command(self):
self.is_cmd_regex = re.compile(f'^/?!?\\s?(?P<bot_name>{"|".join(config.names)})?\\s?', re.IGNORECASE)
if self.is_cmd_regex.search(self.text).group(0) == '': return
self.has_prefix = True
argv = []
argv = self.is_cmd_regex.sub('', self.text).split(' ')
command = argv[0].lower()
if command not in plugin.plugins_map:
self.argv = argv
self.user_text = ' '.join(argv)
return
del argv[0]
self.command = command
self.is_command = True
self.argv = argv
self.user_text = ' '.join(argv)
async def sendMessage(self, text, **parameters):
await self.message.channel.send(text, reference=self.message, **parameters)