Skip to content

Commit

Permalink
v2.1 (#13 )
Browse files Browse the repository at this point in the history
looks good
remove extra client
  • Loading branch information
AshokShau authored Jul 11, 2023
2 parents b97cc27 + ee8fc25 commit 5b55ccc
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 86 deletions.
44 changes: 12 additions & 32 deletions Mickey/__init__.py
Original file line number Diff line number Diff line change
@@ -1,68 +1,48 @@
import asyncio
import importlib
import logging
import re
import sys
import logging
import time
from Abg import patch

from motor.motor_asyncio import AsyncIOMotorClient as MongoCli
from pyrogram import Client
from pyrogram.enums import ParseMode

import config
from Mickey.modules import all_modules

logging.basicConfig(
format="[%(asctime)s - %(levelname)s] - %(name)s - %(message)s",
datefmt="%d-%b-%y %H:%M:%S",
handlers=[logging.FileHandler("log.txt"), logging.StreamHandler()],
level=logging.INFO,
)

logging.getLogger("pyrogram").setLevel(logging.ERROR)
LOGGER = logging.getLogger(__name__)

boot = time.time()
mongo = MongoCli(config.MONGO_URL)
db = mongo.Anonymous


OWNER = config.OWNER_ID
# DEVS = config.SUDO_USERS | config.OWNER_ID


class MickeyBot(Client):
def __init__(self):
super().__init__(
name="MickeyBot",
api_id=config.API_ID,
api_hash=config.API_HASH,
lang_code="en",
bot_token=config.BOT_TOKEN,
plugins=dict(root="Mickey.modules"),
in_memory=True,
parse_mode=ParseMode.DEFAULT,
)

async def start(self):
await super().start()
get_me = await self.get_me()
self.id = get_me.id
self.name = get_me.mention
self.username = get_me.username
self.id = self.me.id
self.name = self.me.first_name + " " + (self.me.last_name or "")
self.username = self.me.username
self.mention = self.me.mention

async def stop(self):
await super().stop()


dev = Client(
"Dev",
bot_token=config.BOT_TOKEN,
api_id=config.API_ID,
api_hash=config.API_HASH,
# plugins=dict(root="Mickey.modules"),
)

dev.start()

BOT_ID = config.BOT_TOKEN.split(":")[0]
x = dev.get_me()
BOT_NAME = x.first_name + (x.last_name or "")
BOT_USERNAME = x.username
BOT_MENTION = x.mention
BOT_DC_ID = x.dc_id
MickeyBot = MickeyBot()
25 changes: 23 additions & 2 deletions Mickey/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
import asyncio
import importlib

from pyrogram import idle

from Mickey import LOGGER, MickeyBot
from Mickey.modules import ALL_MODULES


async def anony_boot():
try:
await MickeyBot.start()
except Exception as ex:
LOGGER.error(ex)
quit(1)

for all_module in ALL_MODULES:
importlib.import_module("Mickey.modules." + all_module)

LOGGER.info(f"@{MickeyBot.username} Started.")
await idle()


if __name__ == "__main__":
LOGGER.info("The MickeyBot Started.")
MickeyBot().run()
asyncio.get_event_loop().run_until_complete(anony_boot())
LOGGER.info("Stopping Mickey Bot...")
8 changes: 6 additions & 2 deletions Mickey/modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from os.path import basename, dirname, isfile


async def all_modules():
def __list_all_modules():
mod_paths = glob.glob(dirname(__file__) + "/*.py")

all_modules = [
Expand All @@ -11,4 +11,8 @@ async def all_modules():
if isfile(f) and f.endswith(".py") and not f.endswith("__init__.py")
]

return sorted(all_modules)
return all_modules


ALL_MODULES = sorted(__list_all_modules())
__all__ = ALL_MODULES + ["ALL_MODULES"]
17 changes: 9 additions & 8 deletions Mickey/modules/chatbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Github :- Devarora-0981 | Devarora2604

import random
from Abg.chat_status import adminsOnly

from pymongo import MongoClient
from pyrogram import Client, filters
Expand All @@ -13,18 +14,18 @@
from Mickey.modules.helpers import CHATBOT_ON, is_admins


@MickeyBot.on_message(filters.command(["chatbot"]) & filters.group & ~filters.bot)
@is_admins
async def chaton_off(_, m: Message):
@MickeyBot.on_cmd("chatbot", group_only=True)
@adminsOnly("can_delete_messages")
async def chaton_(_, m: Message):
await m.reply_text(
f"ᴄʜᴀᴛ: {m.chat.id}\n**ᴄʜᴏᴏsᴇ ᴀɴ ᴏᴩᴛɪᴏɴ ᴛᴏ ᴇɴᴀʙʟᴇ/ᴅɪsᴀʙʟᴇ ᴄʜᴀᴛʙᴏᴛ.**",
f"ᴄʜᴀᴛ: {m.chat.title}\n**ᴄʜᴏᴏsᴇ ᴀɴ ᴏᴩᴛɪᴏɴ ᴛᴏ ᴇɴᴀʙʟᴇ/ᴅɪsᴀʙʟᴇ ᴄʜᴀᴛʙᴏᴛ.**",
reply_markup=InlineKeyboardMarkup(CHATBOT_ON),
)
return


@MickeyBot.on_message(
(filters.text | filters.sticker | filters.group) & ~filters.private & ~filters.bot, group=11
(filters.text | filters.sticker | filters.group) & ~filters.private & ~filters.bot, group=4
)
async def chatbot_text(client: Client, message: Message):
try:
Expand Down Expand Up @@ -113,7 +114,7 @@ async def chatbot_text(client: Client, message: Message):


@MickeyBot.on_message(
(filters.sticker | filters.group | filters.text) & ~filters.private & ~filters.bot, group=11
(filters.sticker | filters.group | filters.text) & ~filters.private & ~filters.bot, group=4
)
async def chatbot_sticker(client: Client, message: Message):
try:
Expand Down Expand Up @@ -204,7 +205,7 @@ async def chatbot_sticker(client: Client, message: Message):


@MickeyBot.on_message(
(filters.text | filters.sticker | filters.group) & ~filters.private & ~filters.bot, group=11
(filters.text | filters.sticker | filters.group) & ~filters.private & ~filters.bot, group=4
)
async def chatbot_pvt(client: Client, message: Message):
try:
Expand Down Expand Up @@ -253,7 +254,7 @@ async def chatbot_pvt(client: Client, message: Message):
(filters.sticker | filters.sticker | filters.group)
& ~filters.private
& ~filters.bot,
group=11,
group=4,
)
async def chatbot_sticker_pvt(client: Client, message: Message):
try:
Expand Down
20 changes: 10 additions & 10 deletions Mickey/modules/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
from inspect import getfullargspec
from io import StringIO
from time import time

from pyrogram import Client
from pyrogram import filters
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message

from Mickey import OWNER, dev
from Mickey import OWNER, MickeyBot


async def aexec(code, client, message):
Expand All @@ -27,19 +27,19 @@ async def edit_or_reply(msg: Message, **kwargs):
await func(**{k: v for k, v in kwargs.items() if k in spec})


@dev.on_edited_message(
@MickeyBot.on_edited_message(
filters.command("eval")
& filters.user(OWNER)
& ~filters.forwarded
& ~filters.via_bot
)
@dev.on_message(
@MickeyBot.on_message(
filters.command("eval")
& filters.user(OWNER)
& ~filters.forwarded
& ~filters.via_bot
)
async def executor(client: dev, message: Message):
async def executor(client: MickeyBot, message: Message):
if len(message.command) < 2:
return await edit_or_reply(message, text="<b>ᴡʜᴀᴛ ʏᴏᴜ ᴡᴀɴɴᴀ ᴇxᴇᴄᴜᴛᴇ ʙᴀʙʏ ?</b>")
try:
Expand Down Expand Up @@ -112,13 +112,13 @@ async def executor(client: dev, message: Message):
await edit_or_reply(message, text=final_output, reply_markup=keyboard)


@dev.on_callback_query(filters.regex(r"runtime"))
@MickeyBot.on_cb("runtime")
async def runtime_func_cq(_, cq):
runtime = cq.data.split(None, 1)[1]
await cq.answer(runtime, show_alert=True)


@dev.on_callback_query(filters.regex("forceclose"))
@MickeyBot.on_cb("forceclose")
async def forceclose_command(_, CallbackQuery):
callback_data = CallbackQuery.data.strip()
callback_request = callback_data.split(None, 1)[1]
Expand All @@ -137,13 +137,13 @@ async def forceclose_command(_, CallbackQuery):
return


@dev.on_edited_message(
@MickeyBot.on_edited_message(
filters.command("sh") & filters.user(OWNER) & ~filters.forwarded & ~filters.via_bot
)
@dev.on_message(
@MickeyBot.on_message(
filters.command("sh") & filters.user(OWNER) & ~filters.forwarded & ~filters.via_bot
)
async def shellrunner(client: dev, message: Message):
async def shellrunner(client: MickeyBot, message: Message):
if len(message.command) < 2:
return await edit_or_reply(message, text="<b>ᴇxᴀᴍᴩʟᴇ :</b>\n/sh git pull")
text = message.text.split(None, 1)[1]
Expand Down
9 changes: 5 additions & 4 deletions Mickey/modules/helpers/inline.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from pyrogram.types import InlineKeyboardButton

from config import SUPPORT_GRP, UPDATE_CHNL
from Mickey import BOT_USERNAME, OWNER
from Mickey import OWNER
from Mickey import MickeyBot

DEV_OP = [
[
Expand All @@ -11,7 +12,7 @@
[
InlineKeyboardButton(
text="🧸 ᴀᴅᴅ ᴍᴇ ʙᴀʙʏ 🧸",
url=f"https://t.me/{BOT_USERNAME}?startgroup=true",
url=f"https://t.me/{MickeyBot.username}?startgroup=true",
),
],
[
Expand All @@ -27,7 +28,7 @@
[
InlineKeyboardButton(
text="🧸 ᴀᴅᴅ ᴍᴇ ʙᴀʙʏ 🧸",
url=f"https://t.me/{BOT_USERNAME}?startgroup=true",
url=f"https://t.me/{MickeyBot.username}?startgroup=true",
),
],
[
Expand Down Expand Up @@ -106,7 +107,7 @@
HELP_BUTN = [
[
InlineKeyboardButton(
text="🚀 ʜᴇʟᴘ 🚀", url=f"https://t.me/{BOT_USERNAME}?start=help"
text="🚀 ʜᴇʟᴘ 🚀", url=f"https://t.me/{MickeyBot.username}?start=help"
),
InlineKeyboardButton(text="🐳 ᴄʟᴏsᴇ 🐳", callback_data="CLOSE"),
],
Expand Down
20 changes: 10 additions & 10 deletions Mickey/modules/helpers/read.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
from config import OWNER_USERNAME, SUPPORT_GRP
from Mickey import BOT_NAME, BOT_USERNAME
from Mickey import MickeyBot

START = f"""
**๏ ʜᴇʏ, ɪ ᴀᴍ [{BOT_NAME}](t.me/{BOT_USERNAME})**
**๏ ʜᴇʏ, ɪ ᴀᴍ [{MickeyBot.name}](t.me/{MickeyBot.username})**
**➻ ᴀɴ ᴀɪ ʙᴀsᴇᴅ ᴄʜᴀᴛʙᴏᴛ**
**──────────────**
**➻ ᴜsᴀɢᴇ /chatbot [ᴏɴ/ᴏғғ]**
<b>||๏ ʜɪᴛ ʜᴇʟᴘ ʙᴜᴛᴛᴏɴ ғᴏʀ ʜᴇʟᴘ.||</b>
"""

HELP_READ = f"""
<u>**ᴄᴏᴍᴍᴀɴᴅs ғᴏʀ {BOT_NAME}**</u>
<u>**ᴄᴏᴍᴍᴀɴᴅs ғᴏʀ {MickeyBot.name}**</u>
<u>**ᴀʀᴇ ɢɪᴠᴇɴ ʙᴇʟᴏᴡ!**</u>
**ᴀʟʟ ᴛʜᴇ ᴄᴏᴍᴍᴀɴᴅs ᴄᴀɴ ʙᴇ ᴜsᴇᴅ ᴡɪᴛʜ:/**
**──────────────**
<b>||©️ @{OWNER_USERNAME}||</b>
"""

TOOLS_DATA_READ = f"""
<u>**ᴛᴏᴏʟs ғᴏʀ {BOT_NAME} ᴀʀᴇ:**</u>
<u>**ᴛᴏᴏʟs ғᴏʀ {MickeyBot.name} ᴀʀᴇ:**</u>
**➻ ᴜsᴇ /repo ғᴏʀ ɢᴇᴛᴛɪɴɢ sᴏᴜʀᴄᴇ ᴄᴏᴅᴇ!**
**──────────────**
**➻ ᴜsᴇ /ping ғᴏʀ ᴄʜᴇᴄᴋɪɴɢ ᴛʜᴇ ᴘɪɴɢ ᴏғ {BOT_NAME}**
**➻ ᴜsᴇ /ping ғᴏʀ ᴄʜᴇᴄᴋɪɴɢ ᴛʜᴇ ᴘɪɴɢ ᴏғ {MickeyBot.name}**
**──────────────**
**➻ ᴜsᴇ /id ᴛᴏ ɢᴇᴛ ʏᴏᴜʀ ᴜsᴇʀ ɪᴅ, ᴄʜᴀᴛ ɪᴅ ᴀɴᴅ ᴍᴇssᴀɢᴇ ɪᴅ ᴀʟʟ ɪɴ ᴀ sɪɴɢʟᴇ ᴍᴇssᴀɢᴇ.**
**──────────────**
<b>||©️ @{OWNER_USERNAME}||</b>
"""

CHATBOT_READ = f"""
<u>**ᴄᴏᴍᴍᴀɴᴅs ғᴏʀ {BOT_NAME}**</u>
<u>**ᴄᴏᴍᴍᴀɴᴅs ғᴏʀ {MickeyBot.name}**</u>
**➻ ᴜsᴇ /chatbot ᴛᴏ ᴇɴᴀʙʟᴇ/ᴅɪsᴀʙʟᴇ ᴛʜᴇ ᴄʜᴀᴛʙᴏᴛ.**
**๏ ɴᴏᴛᴇ ➻ ᴛʜᴇ ᴀʙᴏᴠᴇ ᴄᴏᴍᴍᴀɴᴅ ғᴏʀ ᴄʜᴀᴛʙᴏᴛ ᴡᴏʀᴋ ɪɴ ɢʀᴏᴜᴘ ᴏɴʟʏ!!**
**───────────────**
<b>||©️ @{OWNER_USERNAME}||</b>
"""

SOURCE_READ = f"**ʜᴇʏ, ᴛʜᴇ sᴏᴜʀᴄᴇ ᴄᴏᴅᴇ ᴏғ [{BOT_NAME}](https://t.me/{BOT_USERNAME}) ɪs ɢɪᴠᴇɴ ʙᴇʟᴏᴡ.**\n**ᴘʟᴇᴀsᴇ ғᴏʀᴋ ᴛʜᴇ ʀᴇᴘᴏ & ɢɪᴠᴇ ᴛʜᴇ sᴛᴀʀ ✯**\n**──────────────────**\n**ʜᴇʀᴇ ɪs ᴛʜᴇ [sᴏᴜʀᴄᴇ ᴄᴏᴅᴇ](https://github.com/Devarora-0981/Mickey)**\n**──────────────────**\n**ɪғ ʏᴏᴜ ғᴀᴄᴇ ᴀɴʏ ᴘʀᴏʙʟᴇᴍ ᴛʜᴇɴ ᴄᴏɴᴛᴀᴄᴛ ᴀᴛ [sᴜᴘᴘᴏʀᴛ ᴄʜᴀᴛ](https://t.me/{SUPPORT_GRP}).\n<b>||©️ @{OWNER_USERNAME}||</b>"
SOURCE_READ = f"**ʜᴇʏ, ᴛʜᴇ sᴏᴜʀᴄᴇ ᴄᴏᴅᴇ ᴏғ [{MickeyBot.name}](https://t.me/{MickeyBot.username}) ɪs ɢɪᴠᴇɴ ʙᴇʟᴏᴡ.**\n**ᴘʟᴇᴀsᴇ ғᴏʀᴋ ᴛʜᴇ ʀᴇᴘᴏ & ɢɪᴠᴇ ᴛʜᴇ sᴛᴀʀ ✯**\n**──────────────────**\n**ʜᴇʀᴇ ɪs ᴛʜᴇ [sᴏᴜʀᴄᴇ ᴄᴏᴅᴇ](https://github.com/Devarora-0981/Mickey)**\n**──────────────────**\n**ɪғ ʏᴏᴜ ғᴀᴄᴇ ᴀɴʏ ᴘʀᴏʙʟᴇᴍ ᴛʜᴇɴ ᴄᴏɴᴛᴀᴄᴛ ᴀᴛ [sᴜᴘᴘᴏʀᴛ ᴄʜᴀᴛ](https://t.me/{SUPPORT_GRP}).\n<b>||©️ @{OWNER_USERNAME}||</b>"

ADMIN_READ = f"sᴏᴏɴ"

ABOUT_READ = f"""
**➻ [{BOT_NAME}](https://t.me/{BOT_USERNAME}) ɪs ᴀɴ ᴀɪ ʙᴀsᴇᴅ ᴄʜᴀᴛ-ʙᴏᴛ.**
**➻ [{BOT_NAME}](https://t.me/{BOT_USERNAME}) ʀᴇᴘʟɪᴇs ᴀᴜᴛᴏᴍᴀᴛɪᴄᴀʟʟʏ ᴛᴏ ᴀ ᴜsᴇʀ.**
**➻ [{MickeyBot.name}](https://t.me/{MickeyBot.username}) ɪs ᴀɴ ᴀɪ ʙᴀsᴇᴅ ᴄʜᴀᴛ-ʙᴏᴛ.**
**➻ [{MickeyBot.name}](https://t.me/{MickeyBot.username}) ʀᴇᴘʟɪᴇs ᴀᴜᴛᴏᴍᴀᴛɪᴄᴀʟʟʏ ᴛᴏ ᴀ ᴜsᴇʀ.**
**➻ ʜᴇʟᴘs ʏᴏᴜ ɪɴ ᴀᴄᴛɪᴠᴀᴛɪɴɢ ʏᴏᴜʀ ɢʀᴏᴜᴘs.**
**➻ ᴡʀɪᴛᴛᴇɴ ɪɴ [ᴘʏᴛʜᴏɴ](https://www.python.org) ᴡɪᴛʜ [ᴍᴏɴɢᴏ-ᴅʙ](https://www.mongodb.com) ᴀs ᴀ ᴅᴀᴛᴀʙᴀsᴇ**
**──────────────**
**➻ ᴄʟɪᴄᴋ ᴏɴ ᴛʜᴇ ʙᴜᴛᴛᴏɴs ɢɪᴠᴇɴ ʙᴇʟᴏᴡ ғᴏʀ ɢᴇᴛᴛɪɴɢ ʙᴀsɪᴄ ʜᴇʟᴩ ᴀɴᴅ ɪɴғᴏ ᴀʙᴏᴜᴛ [{BOT_NAME}](https://t.me/{BOT_USERNAME})**
**➻ ᴄʟɪᴄᴋ ᴏɴ ᴛʜᴇ ʙᴜᴛᴛᴏɴs ɢɪᴠᴇɴ ʙᴇʟᴏᴡ ғᴏʀ ɢᴇᴛᴛɪɴɢ ʙᴀsɪᴄ ʜᴇʟᴩ ᴀɴᴅ ɪɴғᴏ ᴀʙᴏᴜᴛ [{MickeyBot.name}](https://t.me/{MickeyBot.username})**
"""
4 changes: 2 additions & 2 deletions Mickey/modules/ids.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from pyrogram import filters
from pyrogram.enums import ParseMode

from Mickey import dev
from Mickey import MickeyBot


@dev.on_message(filters.command("id"))
@MickeyBot.on_cmd("id")
async def getid(client, message):
chat = message.chat
your_id = message.from_user.id
Expand Down
6 changes: 3 additions & 3 deletions Mickey/modules/ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
from pyrogram.types import InlineKeyboardMarkup, Message

from config import IMG, OWNER_USERNAME, STICKER
from Mickey import BOT_NAME, dev
from Mickey import MickeyBot
from Mickey.database.chats import add_served_chat
from Mickey.database.users import add_served_user
from Mickey.modules.helpers import PNG_BTN


@dev.on_message(filters.command("ping", prefixes=["+", "/", "-", "?", "$", "&"]))
@MickeyBot.on_cmd("ping")
async def ping(_, message: Message):
await message.reply_sticker(sticker=random.choice(STICKER))
start = datetime.now()
Expand All @@ -30,7 +30,7 @@ async def ping(_, message: Message):

ms = (datetime.now() - start).microseconds / 1000
await loda.edit_text(
text=f"нey вαву!!\n{BOT_NAME} ιѕ alιve 🥀 αnd worĸιng ғιne wιтн a pιng oғ\n➥ `{ms}` ms\n\n<b>|| мαdє ωιтн ❣️ ву [ᴅᴇᴠ](https://t.me/{OWNER_USERNAME}) ||</b>",
text=f"нey вαву!!\n{MickeyBot.name} ιѕ alιve 🥀 αnd worĸιng ғιne wιтн a pιng oғ\n➥ `{ms}` ms\n\n<b>|| мαdє ωιтн ❣️ ву [ᴅᴇᴠ](https://t.me/{OWNER_USERNAME}) ||</b>",
reply_markup=InlineKeyboardMarkup(PNG_BTN),
)
if message.chat.type == ChatType.PRIVATE:
Expand Down
Loading

0 comments on commit 5b55ccc

Please sign in to comment.