forked from zachkont/dotaUpdatesBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
79 lines (69 loc) · 1.67 KB
/
utils.py
File metadata and controls
79 lines (69 loc) · 1.67 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
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import telebot
import time
import json
import re
import datetime
from sortedcontainers import SortedDict
from datetime import datetime
from settings import BOT_TOKEN
# bot and admin chat id
bot = telebot.TeleBot(BOT_TOKEN)
adminid = bot.get_me()
uptime = datetime.now()
def getCID(message):
return message.chat.id
def getContent(text):
command = re.findall(r'/{1}\w+[@RadRetroRobot]*\s+(.*)', text.text, re.DOTALL)
if command:
whole = ""
for line in command:
if line == "":
whole += "\n"
else:
whole += line
return whole
else:
pass
def addUser(userID, userName, filename):
user = {
userID : userName
}
with open(filename + '.json') as f:
data = json.load(f)
data.update(user)
with open(filename + '.json', 'w') as f:
json.dump(data, f)
def loadjson(filename):
with open(filename + '.json') as f:
data = json.load(f)
if filename == "suggestion" or filename == 'todo':
data = SortedDict(data)
return data
def deljson(value, filename):
data = loadjson(filename)
for key in data.keys():
if key == value:
del data[key]
with open(filename + '.json', 'w') as f:
json.dump(data, f)
return True
elif data[key] == value:
del data[key]
with open(filename + '.json', 'w') as f:
json.dump(data, f)
return True
return False
def intime(message):
timeRange = time.mktime(datetime.now().timetuple())
if int(timeRange - message.date) < 10:
if message.forward_from == None:
return True
else:
return False
def addBlogPostInstantView(url):
prefix = 'https://t.me/iv?url='
postfix = '&rhash=ef812bf2b658b4'
instant_view_link = prefix + url + postfix
return instant_view_link