-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
executable file
·91 lines (64 loc) · 2.16 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# pylint: disable-all
from var import *
from sys import argv, executable
from os import execl
from time import gmtime, strftime
from cairosvg import svg2png
import chess
import os
def fix_message(message):
chars = ('"[]‘')
for c in chars:
message = message.replace(c, "")
for c in forbiden_chars:
message = message.replace(c, "")
message = message.replace(".", ".")
return message
def fix_name(name):
for chars in forbiden_chars:
name.replace(chars, '')
return name
def restart_program():
execl(executable, executable, *argv)
def format_out_list(input_list):
return ", ".join(input_list)
def curly_replace(text):
return text.replace("{", "").replace("}", "")
def is_creator(id):
if id in ("0", "14267520", "24039236"):
return True
def image_to_link(image):
link = image["link"].replace("https://", "")
link = "Image: " + link
return link
def return_datestring(deltatimedays, date_channel):
if deltatimedays == 0:
return ""
elif deltatimedays == 1:
return "a day and "
return "{} days and ".format(deltatimedays)
def board_to_svg(board):
return chess.svg.board(board)
def svg_to_png(svg):
return svg2png(bytestring=svg, write_to='output.png')
def chess_imgur():
link = CLIENT.upload_from_path("output.png")
os.remove("output.png")
return link
def return_deltatime(timestamp):
timestamp = str(timestamp)
current_time = strftime("%a, %d %b %Y %I:%M:%S %p %Z", gmtime())
return datetime.strptime(current_time,
"%a, %d %b %Y %I:%M:%S %p %Z") - datetime.strptime(
timestamp, "%Y-%m-%d %H:%M:%S")
def join_list(list):
return ", ".join(list)
def process_input_name(input_name):
input_name = input_name.replace("\n", "").strip()
me_regex = re.compile(r"m\s*e(\\n)*\b", re.I)
input_name = re.sub(me_regex, "you", input_name)
myself_regex = re.compile(r"my\s*self\s*(\\n)*\b", re.I)
input_name = re.sub(myself_regex, "you", input_name)
my_regex = re.compile(r"my\s*(\\n)*\b", re.I)
input_name = re.sub(my_regex, "your", input_name)
return input_name