You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.7 KiB
56 lines
1.7 KiB
from telegram import ForceReply, Update
|
|
from telegram.ext import Application, CommandHandler, ContextTypes, MessageHandler, filters
|
|
import os, sys
|
|
|
|
#не трогай это на новый год
|
|
class AsyncIterator:
|
|
def __init__(self, seq):
|
|
self.iter = iter(seq)
|
|
|
|
def __aiter__(self):
|
|
return self
|
|
|
|
async def __anext__(self):
|
|
try:
|
|
return next(self.iter)
|
|
except StopIteration:
|
|
raise StopAsyncIteration
|
|
|
|
class Sunduk:
|
|
application: Application = None
|
|
loaded_extensions = {}
|
|
a_ext = None
|
|
|
|
def __init__(self, token) -> None:
|
|
self.application = Application.builder().token(token).build()
|
|
self.admins = [int(_id) for _id in os.getenv("COOLBOYS", "").split(";")]
|
|
|
|
self.load_extensions("./extensions")
|
|
self.application.add_handler(MessageHandler(filters=filters.ALL, callback=self.execute))
|
|
|
|
def run(self):
|
|
self.application.run_polling()
|
|
|
|
def load_extensions(self, extensions_path):
|
|
if type(extensions_path) == str:
|
|
extensions_path = [extensions_path]
|
|
for path in extensions_path:
|
|
print(f"Load extensions from: {path}")
|
|
sys.path.insert(0, path)
|
|
for extension in os.listdir(path):
|
|
extension, ext = os.path.splitext(extension)
|
|
if ext != ".py":
|
|
continue
|
|
print(f"Loading: {extension}")
|
|
self.loaded_extensions[extension] = __import__(extension).Extension(self)
|
|
sys.path.pop(0)
|
|
self.a_ext = AsyncIterator(self.loaded_extensions.values())
|
|
|
|
async def execute(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|
#пиздец
|
|
for ext in self.loaded_extensions.values():
|
|
await ext(update, context)
|
|
|
|
if __name__ == "__main__":
|
|
print(f"Build date: {os.getenv('BUILDDATE', 0)}")
|
|
Sunduk(os.getenv("BOT_TOKEN", None)).run()
|