-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfunctions.py
56 lines (45 loc) · 1.49 KB
/
functions.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
import re
import os
import sys
import yaml
import random
import discord
import logging as log
from datetime import datetime
def load_yaml(yaml_file_name):
with open(os.path.join(sys.path[0], yaml_file_name), "r", encoding="utf8") as yaml_file:
return yaml.safe_load(yaml_file)
def paginate(text):
pages = []
lines = text.split("\n")
page = ""
for line in lines:
if len(page + line + "\n") < 1024:
page = page + line + "\n"
else:
pages.append(page)
page = line + "\n"
pages.append(page)
return pages
def sentence_case(text):
return ". ".join(i.capitalize() for i in text.split(". "))
def chance(percent):
return random.randint(0, 99) < percent
def replace_ignore_case(text, find, replace):
pattern = re.compile(find, re.IGNORECASE)
return pattern.sub(replace, text)
def ascii_only(text):
stripped = (c for c in text if 0 < ord(c) < 127)
return ''.join(stripped)
def time_since(date_time):
return (datetime.utcnow() - date_time)
def time_until(date_time):
return (date_time - datetime.utcnow())
def date_time_from_str(timestamp):
timestamp = re.sub('[^0-9]','', timestamp)[:14]
return datetime.strptime(timestamp[:19], "%Y%m%d%H%M%S")
def seconds_since(then):
return abs((datetime.utcnow() - then).total_seconds())
log.basicConfig(format="[%(asctime)s] [%(levelname)s] %(message)s", level=log.INFO, stream=sys.stdout)
config = load_yaml("config.yaml")
strings = load_yaml("strings.yaml")