-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.py
74 lines (59 loc) · 1.81 KB
/
helpers.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
# temp db for banned
import asyncio
import logging
import traceback
import aiohttp
import database
from config import ADMINS, CHANNEL_ID, CHANNELS, PING_INTERVAL, PORT
class temp(object): # TrojanZ Idea of Temping
BOT_USERNAME = None
CANCEL = False
FIRST_NAME = None
START_TIME = None
BANNED_USERS = []
class AsyncIter:
def __init__(self, items):
self.items = items
async def __aiter__(self):
for item in self.items:
yield item
async def __anext__(self):
try:
return next(self.iter)
except StopIteration as e:
raise StopAsyncIteration from e
class Helpers:
def __init__(self):
self.username = temp.BOT_USERNAME
@property
async def user_method(self):
user_method = await database.db.get_bot_method(self.username)
return user_method or "None"
@property
async def get_channels(self):
if CHANNELS:
x = ""
async for i in AsyncIter(CHANNEL_ID):
x += f"~ `{i}`\n"
return x
return "Channels is set to False in heroku Var"
@property
async def get_admins(self):
x = ""
async for i in AsyncIter(ADMINS):
x += f"~ `{i}`\n"
return x
async def ping_server():
sleep_time = PING_INTERVAL
while True:
await asyncio.sleep(sleep_time)
try:
async with aiohttp.ClientSession(
timeout=aiohttp.ClientTimeout(total=10)
) as session:
async with session.get(f"http://0.0.0.0:{PORT}") as resp:
logging.info(f"Pinged server with response: {resp.status}")
except TimeoutError:
logging.warning("Couldn't connect to the site URL..!")
except Exception:
traceback.print_exc()