-
Notifications
You must be signed in to change notification settings - Fork 1
/
tools.py
63 lines (48 loc) · 1.84 KB
/
tools.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
53
54
55
56
57
58
59
60
61
62
63
"""File for some tools."""
import requests # lib for going on internet
from bs4 import BeautifulSoup
from discord.utils import get as disc_get
def string_is_int(string):
"""Return if 'string' is an int or not (bool)."""
try:
int(string)
return True
except ValueError:
return False
def get_soup_lxml(url):
"""Return a BeautifulSoup soup from given url, Parser is lxml.
Args:
url (str): url
Returns:
BeautifulSoup: soup
"""
# get HTML page with requests.get
res = requests.get(url, timeout=3)
res.close()
# BeautifulSoup will transform raw HTML in a tree easy to parse
return BeautifulSoup(res.text, 'lxml')
def get_soup_html(url):
"""Return a BeautifulSoup soup from given url, Parser is html.parser.
Args:
url (str): url
Returns:
BeautifulSoup: soup
"""
# get HTML page with requests.get
res = requests.get(url, timeout=3)
res.close()
# BeautifulSoup will transform raw HTML in a tree easy to parse
return BeautifulSoup(res.text, 'html.parser')
def args_separator_for_log_function(guild,args):
"""check the args if there are user, channel and command"""
commands = ['kick','clear','ban']
[user,command,channel] = [None,None,None] # They are defaulted to None, if any of them is specified, it will be changed
liste = args.split() # split the args into a list
for word in liste:
if disc_get(guild.members, name=word) is not None: # if word is a member of the guild
user = word
elif disc_get(guild.text_channels, name=word) is not None: # if word is a channel of the guild
channel = word
elif word in commands: # if word is a command
command = word
return [user, command, channel] # variables not specified in the args are defaulted to None