mirror of
https://github.com/yasirarism/MissKatyPyro.git
synced 2026-01-03 19:14:51 +00:00
Added currency and uvloop (#38)
This commit is contained in:
parent
fca1ff40e1
commit
e4d889c36a
11 changed files with 127 additions and 38 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -1 +1,2 @@
|
||||||
.vscode
|
.vscode
|
||||||
|
__pycache__
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
from logging import ERROR, INFO, FileHandler, StreamHandler, basicConfig, getLogger, handlers
|
import uvloop
|
||||||
|
from logging import ERROR, INFO, StreamHandler, basicConfig, getLogger, handlers
|
||||||
|
|
||||||
import pyromod.listen
|
import pyromod.listen
|
||||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||||
|
|
@ -10,13 +11,15 @@ from pyrogram import Client
|
||||||
|
|
||||||
from misskaty.vars import API_HASH, API_ID, BOT_TOKEN, DATABASE_URI, USER_SESSION, TZ
|
from misskaty.vars import API_HASH, API_ID, BOT_TOKEN, DATABASE_URI, USER_SESSION, TZ
|
||||||
|
|
||||||
basicConfig(filename="MissKatyLogs.txt", format="%(asctime)s - %(name)s.%(funcName)s - %(levelname)s - %(message)s", level=INFO)
|
basicConfig(
|
||||||
|
level=INFO,
|
||||||
logger = getLogger()
|
format="[%(asctime)s - %(levelname)s] - %(name)s.%(funcName)s - %(message)s",
|
||||||
# handler logging dengan batasan 100 baris
|
datefmt="%d-%b-%y %H:%M:%S",
|
||||||
handler = handlers.RotatingFileHandler("MissKatyLogs.txt", maxBytes=1024 * 1024)
|
handlers=[
|
||||||
handler.setLevel(INFO)
|
handlers.RotatingFileHandler("MissKatyLogs.txt", mode="w+", maxBytes=1000000),
|
||||||
logger.addHandler(handler)
|
StreamHandler(),
|
||||||
|
],
|
||||||
|
)
|
||||||
getLogger("pyrogram").setLevel(ERROR)
|
getLogger("pyrogram").setLevel(ERROR)
|
||||||
getLogger("openai").setLevel(ERROR)
|
getLogger("openai").setLevel(ERROR)
|
||||||
|
|
||||||
|
|
@ -26,6 +29,8 @@ HELPABLE = {}
|
||||||
cleanmode = {}
|
cleanmode = {}
|
||||||
botStartTime = time.time()
|
botStartTime = time.time()
|
||||||
|
|
||||||
|
uvloop.install()
|
||||||
|
|
||||||
# Pyrogram Bot Client
|
# Pyrogram Bot Client
|
||||||
app = Client(
|
app = Client(
|
||||||
"MissKatyBot",
|
"MissKatyBot",
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ if __name__ == "__main__":
|
||||||
pass
|
pass
|
||||||
except Exception:
|
except Exception:
|
||||||
err = traceback.format_exc()
|
err = traceback.format_exc()
|
||||||
LOGGER.error(err)
|
print(err)
|
||||||
finally:
|
finally:
|
||||||
loop.stop()
|
loop.stop()
|
||||||
print("------------------------ Stopped Services ------------------------")
|
print("------------------------ Stopped Services ------------------------")
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
import ast
|
import ast
|
||||||
|
import os
|
||||||
|
import traceback
|
||||||
|
from typing import List, Optional
|
||||||
|
|
||||||
|
|
||||||
# We dont modify locals VVVV ; this lets us keep the message available to the user-provided function
|
# We dont modify locals VVVV ; this lets us keep the message available to the user-provided function
|
||||||
|
|
@ -7,7 +10,7 @@ async def meval(code, globs, **kwargs):
|
||||||
# Note to self: please don't set globals here as they will be lost.
|
# Note to self: please don't set globals here as they will be lost.
|
||||||
# Don't clutter locals
|
# Don't clutter locals
|
||||||
locs = {}
|
locs = {}
|
||||||
# Restore globals later
|
# Restore globals latertypes
|
||||||
globs = globs.copy()
|
globs = globs.copy()
|
||||||
# This code saves __name__ and __package into a kwarg passed to the function.
|
# This code saves __name__ and __package into a kwarg passed to the function.
|
||||||
# It is set before the users code runs to make sure relative imports work
|
# It is set before the users code runs to make sure relative imports work
|
||||||
|
|
@ -98,11 +101,6 @@ async def meval(code, globs, **kwargs):
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
import os
|
|
||||||
import traceback
|
|
||||||
from typing import List, Optional
|
|
||||||
|
|
||||||
|
|
||||||
def format_exception(exp: BaseException, tb: Optional[List[traceback.FrameSummary]] = None) -> str:
|
def format_exception(exp: BaseException, tb: Optional[List[traceback.FrameSummary]] = None) -> str:
|
||||||
"""Formats an exception traceback as a string, similar to the Python interpreter."""
|
"""Formats an exception traceback as a string, similar to the Python interpreter."""
|
||||||
|
|
||||||
|
|
|
||||||
48
misskaty/plugins/currency.py
Normal file
48
misskaty/plugins/currency.py
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
from pyrogram import filters, Client
|
||||||
|
from pyrogram.types import Message
|
||||||
|
from misskaty import app
|
||||||
|
import logging
|
||||||
|
from misskaty.helper.http import http
|
||||||
|
from misskaty.core.message_utils import kirimPesan
|
||||||
|
from misskaty.vars import COMMAND_HANDLER, CURRENCY_API
|
||||||
|
|
||||||
|
|
||||||
|
__MODULE__ = "Currency"
|
||||||
|
__HELP__ = """
|
||||||
|
/currency - Send structure message Telegram in JSON using Pyrogram Style.
|
||||||
|
"""
|
||||||
|
|
||||||
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@app.on_message(filters.command(["currency"], COMMAND_HANDLER))
|
||||||
|
async def currency(c: Client, m: Message):
|
||||||
|
if CURRENCY_API is None:
|
||||||
|
return await kirimPesan(m, f"<code>Oops!!get the API from</code> " "<a href='https://app.exchangerate-api.com/sign-up'>HERE</a> " "<code>& add it to config vars</code> (<code>CURRENCY_API</code>)", disable_web_page_preview=True)
|
||||||
|
if len(m.text.split()) == 4:
|
||||||
|
teks = m.text.split()
|
||||||
|
amount = teks[1]
|
||||||
|
currency_from = teks[2]
|
||||||
|
currency_to = teks[3]
|
||||||
|
else:
|
||||||
|
return await kirimPesan(m, f"Use format /{m.command[0]} [amount] [currency_from] [currency_to] to convert currency.")
|
||||||
|
|
||||||
|
if amount.isdigit():
|
||||||
|
url = f"https://v6.exchangerate-api.com/v6/{CURRENCY_API}/" f"pair/{currency_from}/{currency_to}/{amount}"
|
||||||
|
try:
|
||||||
|
res = await http.get(url)
|
||||||
|
data = res.json()
|
||||||
|
try:
|
||||||
|
conversion_rate = data["conversion_rate"]
|
||||||
|
conversion_result = data["conversion_result"]
|
||||||
|
target_code = data["target_code"]
|
||||||
|
base_code = data["base_code"]
|
||||||
|
last_update = data["time_last_update_utc"]
|
||||||
|
except KeyError:
|
||||||
|
return await kirimPesan(m, "<code>Invalid response from api !</i>")
|
||||||
|
|
||||||
|
await kirimPesan(m, "**CURRENCY EXCHANGE RATE RESULT:**\n\n" f"`{amount}` **{target_code}** = `{round(conversion_result)}` **{base_code}**\n" f"<b>Rate Today</b> = `{round(conversion_rate)}`\n" f"<b>Last Update:</b> {last_update}")
|
||||||
|
except:
|
||||||
|
await kirimPesan(m, "Failed convert currency, maybe you give wrong currency format or api down.")
|
||||||
|
else:
|
||||||
|
await kirimPesan(m, r"<code>This seems to be some alien currency, which I can't convert right now.. (⊙_⊙;)</code>")
|
||||||
|
|
@ -3,6 +3,7 @@ import io
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
import html
|
||||||
import pickle
|
import pickle
|
||||||
import json
|
import json
|
||||||
import traceback
|
import traceback
|
||||||
|
|
@ -90,6 +91,15 @@ async def server_stats(c, m):
|
||||||
"""
|
"""
|
||||||
Give system stats of the server.
|
Give system stats of the server.
|
||||||
"""
|
"""
|
||||||
|
if os.path.exists(".git"):
|
||||||
|
botVersion = (await shell_exec("git log -1 --date=format:v%y.%m%d.%H%M --pretty=format:%cd"))[0]
|
||||||
|
else:
|
||||||
|
botVersion = "v2.49"
|
||||||
|
try:
|
||||||
|
serverinfo = await http.get("https://ipinfo.io/json")
|
||||||
|
org = serverinfo.json()["org"]
|
||||||
|
except:
|
||||||
|
org = "N/A"
|
||||||
currentTime = get_readable_time(time() - botStartTime)
|
currentTime = get_readable_time(time() - botStartTime)
|
||||||
total, used, free = disk_usage(".")
|
total, used, free = disk_usage(".")
|
||||||
total = get_readable_file_size(total)
|
total = get_readable_file_size(total)
|
||||||
|
|
@ -97,22 +107,23 @@ async def server_stats(c, m):
|
||||||
free = get_readable_file_size(free)
|
free = get_readable_file_size(free)
|
||||||
neofetch = (await shell_exec("neofetch --stdout"))[0]
|
neofetch = (await shell_exec("neofetch --stdout"))[0]
|
||||||
caption = f"""
|
caption = f"""
|
||||||
**{BOT_NAME} is Up and Running successfully.**
|
**{BOT_NAME} {botVersion} is Up and Running successfully.**
|
||||||
Bot Uptime: `{currentTime}`
|
<b>Bot Uptime:</b> `{currentTime}`
|
||||||
Total Disk Space: `{total}`
|
<b>Server:</b> <code>{org}</code>
|
||||||
Used: `{used}({disk_usage_percent("/").percent}%)`
|
<b>Total Disk Space:</b> `{total}`
|
||||||
Free: `{free}`
|
<b>Used:</b> `{used}({disk_usage_percent("/").percent}%)`
|
||||||
CPU Usage: `{cpu_percent()}%`
|
<b>Free:</b> `{free}`
|
||||||
RAM Usage: `{virtual_memory().percent}%`
|
<b>CPU Usage:</b> `{cpu_percent()}%`
|
||||||
|
<b>RAM Usage:</b> `{virtual_memory().percent}%`
|
||||||
|
|
||||||
`{neofetch}`
|
`{neofetch}`
|
||||||
"""
|
"""
|
||||||
await kirimPesan(m, caption)
|
await kirimPesan(m, caption)
|
||||||
|
|
||||||
|
|
||||||
@app.on_message(filters.command(["shell", "sh"], COMMAND_HANDLER) & filters.user(SUDO))
|
@app.on_message(filters.command(["shell", "sh", "term"], COMMAND_HANDLER) & filters.user(SUDO))
|
||||||
@app.on_edited_message(filters.command(["shell", "sh"], COMMAND_HANDLER) & filters.user(SUDO))
|
@app.on_edited_message(filters.command(["shell", "sh", "term"], COMMAND_HANDLER) & filters.user(SUDO))
|
||||||
@user.on_message(filters.command(["shell", "sh"], ".") & filters.me)
|
@user.on_message(filters.command(["shell", "sh", "term"], ".") & filters.me)
|
||||||
@use_chat_lang()
|
@use_chat_lang()
|
||||||
async def shell(_, m, strings):
|
async def shell(_, m, strings):
|
||||||
cmd = m.text.split(" ", 1)
|
cmd = m.text.split(" ", 1)
|
||||||
|
|
@ -125,7 +136,7 @@ async def shell(_, m, strings):
|
||||||
doc.name = "shell_output.txt"
|
doc.name = "shell_output.txt"
|
||||||
await m.reply_document(
|
await m.reply_document(
|
||||||
document=doc,
|
document=doc,
|
||||||
caption="<code>cmd[1][: 4096 // 4 - 1]</code>",
|
caption=f"<code>{cmd[1][: 4096 // 4 - 1]}</code>",
|
||||||
file_name=doc.name,
|
file_name=doc.name,
|
||||||
reply_markup=InlineKeyboardMarkup(
|
reply_markup=InlineKeyboardMarkup(
|
||||||
[
|
[
|
||||||
|
|
@ -142,7 +153,7 @@ async def shell(_, m, strings):
|
||||||
elif len(shell) != 0:
|
elif len(shell) != 0:
|
||||||
await edit_or_reply(
|
await edit_or_reply(
|
||||||
m,
|
m,
|
||||||
text=shell,
|
text=html.escape(shell),
|
||||||
parse_mode=enums.ParseMode.HTML,
|
parse_mode=enums.ParseMode.HTML,
|
||||||
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton(text=strings("cl_btn"), callback_data=f"close#{m.from_user.id}")]]),
|
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton(text=strings("cl_btn"), callback_data=f"close#{m.from_user.id}")]]),
|
||||||
)
|
)
|
||||||
|
|
@ -152,9 +163,9 @@ async def shell(_, m, strings):
|
||||||
await m.reply(strings("no_reply"))
|
await m.reply(strings("no_reply"))
|
||||||
|
|
||||||
|
|
||||||
@app.on_message((filters.command(["ev", "run"], COMMAND_HANDLER) | filters.regex(r"app.run\(\)$")) & filters.user(SUDO))
|
@app.on_message((filters.command(["ev", "run", "myeval"], COMMAND_HANDLER) | filters.regex(r"app.run\(\)$")) & filters.user(SUDO))
|
||||||
@app.on_edited_message((filters.command(["ev", "run"]) | filters.regex(r"app.run\(\)$")) & filters.user(SUDO))
|
@app.on_edited_message((filters.command(["ev", "run", "myeval"]) | filters.regex(r"app.run\(\)$")) & filters.user(SUDO))
|
||||||
@user.on_message(filters.command(["ev", "run"], ".") & filters.me)
|
@user.on_message(filters.command(["ev", "run", "myeval"], ".") & filters.me)
|
||||||
@use_chat_lang()
|
@use_chat_lang()
|
||||||
async def cmd_eval(self, message: types.Message, strings) -> Optional[str]:
|
async def cmd_eval(self, message: types.Message, strings) -> Optional[str]:
|
||||||
if (message.command and len(message.command) == 1) or message.text == "app.run()":
|
if (message.command and len(message.command) == 1) or message.text == "app.run()":
|
||||||
|
|
@ -217,19 +228,24 @@ async def cmd_eval(self, message: types.Message, strings) -> Optional[str]:
|
||||||
if not out_buf.getvalue() or result is not None:
|
if not out_buf.getvalue() or result is not None:
|
||||||
print(result, file=out_buf)
|
print(result, file=out_buf)
|
||||||
el_us = after - before
|
el_us = after - before
|
||||||
el_str = get_readable_time(el_us)
|
try:
|
||||||
|
el_str = get_readable_time(el_us)
|
||||||
|
except:
|
||||||
|
el_str = "1s"
|
||||||
|
if el_str == "" or el_str is None:
|
||||||
|
el_str = "0.1s"
|
||||||
|
|
||||||
out = out_buf.getvalue()
|
out = out_buf.getvalue()
|
||||||
# Strip only ONE final newline to compensate for our message formatting
|
# Strip only ONE final newline to compensate for our message formatting
|
||||||
if out.endswith("\n"):
|
if out.endswith("\n"):
|
||||||
out = out[:-1]
|
out = out[:-1]
|
||||||
final_output = f"{prefix}<b>INPUT:</b>\n<pre language='python'>{code}</pre>\n<b>OUTPUT:</b>\n<pre language='python'>{out}</pre>\nExecuted Time: {el_str}"
|
final_output = f"{prefix}<b>INPUT:</b>\n<pre language='python'>{html.escape(code)}</pre>\n<b>OUTPUT:</b>\n<pre language='python'>{html.escape(out)}</pre>\nExecuted Time: {el_str}"
|
||||||
if len(final_output) > 4096:
|
if len(final_output) > 4096:
|
||||||
with io.BytesIO(str.encode(out)) as out_file:
|
with io.BytesIO(str.encode(out)) as out_file:
|
||||||
out_file.name = "MissKatyEval.txt"
|
out_file.name = "MissKatyEval.txt"
|
||||||
await message.reply_document(
|
await message.reply_document(
|
||||||
document=out_file,
|
document=out_file,
|
||||||
caption="<code>code[: 4096 // 4 - 1]</code>",
|
caption=f"<code>{code[: 4096 // 4 - 1]}</code>",
|
||||||
disable_notification=True,
|
disable_notification=True,
|
||||||
thumb="assets/thumb.jpg",
|
thumb="assets/thumb.jpg",
|
||||||
reply_markup=InlineKeyboardMarkup(
|
reply_markup=InlineKeyboardMarkup(
|
||||||
|
|
|
||||||
|
|
@ -96,6 +96,8 @@ async def downvote(_, message):
|
||||||
return
|
return
|
||||||
if not message.from_user:
|
if not message.from_user:
|
||||||
return
|
return
|
||||||
|
if message.reply_to_message.from_user.is_bot:
|
||||||
|
return
|
||||||
if message.reply_to_message.from_user.id == message.from_user.id:
|
if message.reply_to_message.from_user.id == message.from_user.id:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -108,4 +108,4 @@ DETAILS
|
||||||
)
|
)
|
||||||
await process.delete()
|
await process.delete()
|
||||||
except IndexError:
|
except IndexError:
|
||||||
return await kirimPesan(message, strings("mediainfo_help").format(help=message.command[0]))
|
return await kirimPesan(message, strings("mediainfo_help").format(cmd=message.command[0]))
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
* Copyright @YasirPedia All rights reserved
|
* Copyright @YasirPedia All rights reserved
|
||||||
"""
|
"""
|
||||||
import time
|
import time
|
||||||
|
import os
|
||||||
from asyncio import Lock
|
from asyncio import Lock
|
||||||
from re import MULTILINE, findall
|
from re import MULTILINE, findall
|
||||||
from subprocess import run as srun
|
from subprocess import run as srun
|
||||||
|
|
@ -15,19 +16,30 @@ from pyrogram import filters
|
||||||
from misskaty import app, botStartTime
|
from misskaty import app, botStartTime
|
||||||
from misskaty.core.decorator.ratelimiter import ratelimiter
|
from misskaty.core.decorator.ratelimiter import ratelimiter
|
||||||
from misskaty.helper.human_read import get_readable_time
|
from misskaty.helper.human_read import get_readable_time
|
||||||
|
from misskaty.helper.http import http
|
||||||
|
from .dev import shell_exec
|
||||||
from misskaty.vars import COMMAND_HANDLER
|
from misskaty.vars import COMMAND_HANDLER
|
||||||
|
|
||||||
|
|
||||||
@app.on_message(filters.command(["ping"], COMMAND_HANDLER))
|
@app.on_message(filters.command(["ping"], COMMAND_HANDLER))
|
||||||
@ratelimiter
|
@ratelimiter
|
||||||
async def ping(_, message):
|
async def ping(_, message):
|
||||||
|
if os.path.exists(".git"):
|
||||||
|
botVersion = (await shell_exec("git log -1 --date=format:v%y.%m%d.%H%M --pretty=format:%cd"))[0]
|
||||||
|
else:
|
||||||
|
botVersion = "v2.49"
|
||||||
|
try:
|
||||||
|
serverinfo = await http.get("https://ipinfo.io/json")
|
||||||
|
org = serverinfo.json()["org"]
|
||||||
|
except:
|
||||||
|
org = "N/A"
|
||||||
currentTime = get_readable_time(time.time() - botStartTime)
|
currentTime = get_readable_time(time.time() - botStartTime)
|
||||||
start_t = time.time()
|
start_t = time.time()
|
||||||
rm = await message.reply_text("🐱 Pong!!...")
|
rm = await message.reply_text("🐱 Pong!!...")
|
||||||
end_t = time.time()
|
end_t = time.time()
|
||||||
time_taken_s = round(end_t - start_t, 3)
|
time_taken_s = round(end_t - start_t, 3)
|
||||||
try:
|
try:
|
||||||
await rm.edit(f"<b>🐈 MissKatyBot online.</b>\n\n<b>Ping:</b> <code>{time_taken_s} detik</code>\n<b>Uptime:</b> <code>{currentTime}</code>")
|
await rm.edit(f"<b>🐈 MissKatyBot {botVersion} online.</b>\n\n<b>Ping:</b> <code>{time_taken_s} detik</code>\n<b>Uptime:</b> <code>{currentTime}</code>\nHosted by <code>{org}</code>")
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -177,7 +177,13 @@ async def stream_extract(bot, update, strings):
|
||||||
progress_args=(strings("up_str"), update.message, c_time),
|
progress_args=(strings("up_str"), update.message, c_time),
|
||||||
)
|
)
|
||||||
await hapusPesan(update.message)
|
await hapusPesan(update.message)
|
||||||
os.remove(namafile)
|
try:
|
||||||
|
os.remove(namafile)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
os.remove(namafile)
|
try:
|
||||||
|
os.remove(namafile)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
await editPesan(update.message, strings("fail_extr_sub").format(link=link, e=e))
|
await editPesan(update.message, strings("fail_extr_sub").format(link=link, e=e))
|
||||||
|
|
|
||||||
|
|
@ -84,3 +84,4 @@ BLOCKED_EXTENSIONS = list(
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
MINIMUM_FILE_SIZE = environ.get("MINIMUM_FILE_SIZE", None)
|
MINIMUM_FILE_SIZE = environ.get("MINIMUM_FILE_SIZE", None)
|
||||||
|
CURRENCY_API = environ.get("CURRENCY_API", None)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue