Meta-AI / chatbot /__init__.py
randydev's picture
Update chatbot/__init__.py
35a25f6 verified
raw
history blame
2.21 kB
import asyncio
import logging
import time
import pyrogram
import string
import random
import requests
import aiohttp
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()
async def send_log(text_log: str):
url = "https://private-akeno.randydev.my.id/api/v2/send_message_logs"
params = {
"text_log": text_log
}
async with aiohttp.ClientSession() as session:
async with session.post(url, params=params) as response:
if response.status != 200:
return None
data = await response.json()
return data["message"]
class Randydev(Client):
def __init__(self, loop=None):
self.loop = loop or asyncio.get_event_loop()
super().__init__(
"openaichat",
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:
await send_log(f"GPT-4 Bot: {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,
)
await send_log(f"akn running with Pyrogram started on @{self.me.username} Hi!")
async def stop(self):
try:
await super().stop()
LOGS.warning("akn stopped, Bye!")
except ConnectionError:
LOGS.warning("akn is already terminated")