approve-dev / chatbot /__init__.py
randydev's picture
Update chatbot/__init__.py
2dee48c verified
raw
history blame
2 kB
import asyncio
import logging
import time
import pyrogram
import string
import random
import requests
from inspect import getfullargspec
from os import path
from random import choice
import aiohttp
import re
import os
from datetime import datetime as dt
from pyrogram import Client
from pyrogram.types import *
from pyrogram import filters
from pyrogram.errors import *
from pyrogram.raw.all import layer
from pyrogram.handlers import MessageHandler
from config import API_HASH, API_ID, BOT_TOKEN
from database import db
from logger import LOGS
from platform import python_version
from pyrogram import __version__ as pyrogram_version
StartTime = time.time()
START_TIME = dt.now()
def send_log(text_log: str):
url = "https://private-akeno.randydev.my.id/api/v2/send_message_logs"
params = {
"text_log": text_log
}
response = requests.post(url, params=params)
if response.status_code != 200:
return None
return response.json()["message"]
class Randydev(Client):
def __init__(self, loop=None):
self.loop = loop or asyncio.get_event_loop()
super().__init__(
"chatbotai",
app_version=f"akeno ai latest",
api_id=API_ID,
api_hash=API_HASH,
bot_token=BOT_TOKEN,
workers=300,
plugins=dict(root="chatbot.plugins"),
sleep_threshold=180,
)
async def start(self):
try:
await super().start()
except FloodWait as e:
LOGS.debug(e.value)
await asyncio.sleep(e.value)
self.start_time = time.time()
LOGS.info(
"akn running with Pyrogram v%s (Layer %s) started on @%s. Hi!",
pyrogram.__version__,
layer,
self.me.username,
)
async def stop(self):
try:
await super().stop()
LOGS.warning("akn stopped, Bye!")
except ConnectionError:
LOGS.warning("akn is already terminated")