Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Commit

Permalink
Nana: Fix and Re-enable kang (Sourcery refactored) (#33)
Browse files Browse the repository at this point in the history
* Nana: Fix and Re-enable kang

Signed-off-by: wulan17 <[email protected]>

* 'Refactored by Sourcery'

Co-authored-by: wulan17 <[email protected]>
Co-authored-by: Sourcery AI <>
Signed-off-by: ポキ <[email protected]>
  • Loading branch information
2 people authored and CustomIcon committed Oct 25, 2020
1 parent 9c7a8d8 commit 2681579
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 128 deletions.
216 changes: 102 additions & 114 deletions nana/assistant/stickers.py
Original file line number Diff line number Diff line change
@@ -1,123 +1,111 @@
# #
# # Settings For Sticker
# #
# import asyncio
# from .settings import get_text_settings, get_button_settings
# from pyrogram import filters
# from pyrogram.types import ReplyKeyboardMarkup, Message
#
# Settings For Sticker
#
import asyncio
from .settings import get_text_settings, get_button_settings
from pyrogram import filters
from pyrogram.types import ReplyKeyboardMarkup, Message

# from nana import setbot, AdminSettings, DB_AVAILABLE, app, Owner, NANA_IMG
# from nana.assistant.database.stickers_db import set_sticker_set, set_stanim_set
# from nana.assistant.__main__ import dynamic_data_filter
from nana import setbot, AdminSettings, DB_AVAILABLE, app, Owner, NANA_IMG
from nana.assistant.database.stickers_db import set_sticker_set, set_stanim_set
from nana.assistant.__main__ import dynamic_data_filter

# TEMP_KEYBOARD = []
# USER_SET = {}
# TODEL = {}
TEMP_KEYBOARD = []
USER_SET = {}
TODEL = {}


# @setbot.on_message(filters.user(AdminSettings) & filters.command(["setsticker"]))
# async def get_stickers(_client, message):
# if not DB_AVAILABLE:
# await message.edit("Your database is not avaiable!")
# return
# global TEMP_KEYBOARD, USER_SET
# await app.send_message("@Stickers", "/stats")
# # app.read_history("@Stickers")
# await asyncio.sleep(0.2)
# keyboard = await app.get_history("@Stickers", limit=1)
# keyboard = keyboard[0].reply_markup.keyboard
# for x in keyboard:
# for y in x:
# TEMP_KEYBOARD.append(y)
# await app.send_message("@Stickers", "/cancel")
# msg = await message.reply("Select your stickers for set as kang sticker",
# reply_markup=ReplyKeyboardMarkup(keyboard))
# USER_SET[message.from_user.id] = msg.message_id
# USER_SET["type"] = 1
@setbot.on_message(filters.user(AdminSettings) & filters.command(["setsticker"]))
async def get_stickers(client, message):
if not DB_AVAILABLE:
await message.edit("Your database is not avaiable!")
return
global TEMP_KEYBOARD, USER_SET
await app.send_message("@Stickers", "/stats")
await asyncio.sleep(0.2)
keyboard = await app.get_history("@Stickers", limit=1)
keyboard = keyboard[0].reply_markup.keyboard
for x in keyboard:
for y in x:
TEMP_KEYBOARD.append(y)
await app.send_message("@Stickers", "/cancel")
msg = await message.reply("Select your stickers for set as kang sticker",
reply_markup=ReplyKeyboardMarkup(keyboard))
USER_SET[message.from_user.id] = msg.message_id
USER_SET["type"] = 1

@setbot.on_message(filters.user(AdminSettings) & filters.command(["setanimation"]))
async def get_stickers_animation(client, message):
if not DB_AVAILABLE:
await message.edit("Your database is not avaiable!")
return
global TEMP_KEYBOARD, USER_SET
await app.send_message("@Stickers", "/stats")
await asyncio.sleep(0.2)
keyboard = await app.get_history("@Stickers", limit=1)
keyboard = keyboard[0].reply_markup.keyboard
for x in keyboard:
for y in x:
TEMP_KEYBOARD.append(y)
await app.send_message("@Stickers", "/cancel")
msg = await message.reply("Select your stickers for set as kang animation sticker",
reply_markup=ReplyKeyboardMarkup(keyboard))
USER_SET[message.from_user.id] = msg.message_id
USER_SET["type"] = 2

# # app.read_history("@Stickers")
def get_stickerlist(client,message):
if not DB_AVAILABLE:
return
global TEMP_KEYBOARD, USER_SET
if message.from_user and message.from_user.id in list(USER_SET):
return True
else:
TEMP_KEYBOARD = []
USER_SET = {}

# @setbot.on_message(filters.user(AdminSettings) & filters.command(["setanimation"]))
# async def get_stickers_animation(_client, message):
# if not DB_AVAILABLE:
# await message.edit("Your database is not avaiable!")
# return
# global TEMP_KEYBOARD, USER_SET
# await app.send_message("@Stickers", "/stats")
# # app.read_history("@Stickers")
# await asyncio.sleep(0.2)
# keyboard = await app.get_history("@Stickers", limit=1)
# keyboard = keyboard[0].reply_markup.keyboard
# for x in keyboard:
# for y in x:
# TEMP_KEYBOARD.append(y)
# await app.send_message("@Stickers", "/cancel")
# msg = await message.reply("Select your stickers for set as kang animation sticker",
# reply_markup=ReplyKeyboardMarkup(keyboard))
# USER_SET[message.from_user.id] = msg.message_id
# USER_SET["type"] = 2
@setbot.on_message(get_stickerlist)
async def set_stickers(client, message):
if not DB_AVAILABLE:
await message.edit("Your database is not avaiable!")
return
global TEMP_KEYBOARD, USER_SET
if message.text in TEMP_KEYBOARD:
await client.delete_messages(message.chat.id, USER_SET[message.from_user.id])
if USER_SET["type"] == 1:
set_sticker_set(message.from_user.id, message.text)
elif USER_SET["type"] == 2:
set_stanim_set(message.from_user.id, message.text)
status = "Ok, sticker was set to `{}`".format(message.text)
else:
status = "Invalid pack selected."
TEMP_KEYBOARD = []
USER_SET = {}
text = await get_text_settings()
text += "\n{}".format(status)
button = await get_button_settings()
await setbot.send_photo(message.chat.id, NANA_IMG, caption=text, reply_markup=button)


# # app.read_history("@Stickers")

# def get_stickerlist(message):
# if not DB_AVAILABLE:
# return
# global TEMP_KEYBOARD, USER_SET
# if message.from_user and message.from_user.id in list(USER_SET):
# return True
# else:
# TEMP_KEYBOARD = []
# USER_SET = {}


# @setbot.on_message(get_stickerlist)
# async def set_stickers(client, message):
# if not DB_AVAILABLE:
# await message.edit("Your database is not avaiable!")
# return
# global TEMP_KEYBOARD, USER_SET
# if message.text in TEMP_KEYBOARD:
# await client.delete_messages(message.chat.id, USER_SET[message.from_user.id])
# if USER_SET["type"] == 1:
# set_sticker_set(message.from_user.id, message.text)
# elif USER_SET["type"] == 2:
# set_stanim_set(message.from_user.id, message.text)
# status = "Ok, sticker was set to `{}`".format(message.text)
# TEMP_KEYBOARD = []
# USER_SET = {}
# else:
# status = "Invalid pack selected."
# TEMP_KEYBOARD = []
# USER_SET = {}
# text = await get_text_settings()
# text += "\n{}".format(status)
# button = await get_button_settings()
# await setbot.send_photo(message.chat.id, NANA_IMG, caption=text, reply_markup=button)


# @setbot.on_callback_query(dynamic_data_filter("setsticker"))
# async def settings_sticker(_client, message):
# if not DB_AVAILABLE:
# await message.edit("Your database is not avaiable!")
# return
# global TEMP_KEYBOARD, USER_SET
# await app.send_message("@Stickers", "/stats")
# # app.read_history("@Stickers")
# await asyncio.sleep(0.2)
# try:
# keyboard = await app.get_history("@Stickers", limit=1)
# keyboard = keyboard[0].reply_markup.keyboard
# except:
# await message.edit("You dont have any sticker pack!\nAdd stickers pack in @Stickers ")
# return
# for x in keyboard:
# for y in x:
# TEMP_KEYBOARD.append(y)
# await app.send_message("@Stickers", "/cancel")
# await message.delete()
# msg = await setbot.send_message(Owner, "Select your stickers for set as kang animation sticker",
# reply_markup=ReplyKeyboardMarkup(keyboard))
# USER_SET[message.from_user.id] = msg.message_id
# USER_SET["type"] = 2
@setbot.on_callback_query(dynamic_data_filter("setsticker"))
async def settings_sticker(client, message):
if not DB_AVAILABLE:
await message.edit("Your database is not avaiable!")
return
global TEMP_KEYBOARD, USER_SET
await app.send_message("@Stickers", "/stats")
await asyncio.sleep(0.2)
try:
keyboard = await app.get_history("@Stickers", limit=1)
keyboard = keyboard[0].reply_markup.keyboard
except:
await message.edit("You dont have any sticker pack!\nAdd stickers pack in @Stickers ")
return
for x in keyboard:
for y in x:
TEMP_KEYBOARD.append(y)
await app.send_message("@Stickers", "/cancel")
await message.delete()
msg = await setbot.send_message(Owner, "Select your stickers for set as kang animation sticker",
reply_markup=ReplyKeyboardMarkup(keyboard))
USER_SET[message.from_user.id] = msg.message_id
USER_SET["type"] = 2
24 changes: 10 additions & 14 deletions nana/modules/stickers.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ async def kang_stickers(client, message):
await client.download_media(message.reply_to_message.sticker, file_name="nana/cache/sticker.png")
elif message.reply_to_message and message.reply_to_message.photo:
await client.download_media(message.reply_to_message.photo, file_name="nana/cache/sticker.png")
elif message.reply_to_message and message.reply_to_message.document and message.reply_to_message.document.mime_type == "image/png":
elif (
message.reply_to_message
and message.reply_to_message.document
and message.reply_to_message.document.mime_type
in ["image/png", "image/jpeg"]
):
await client.download_media(message.reply_to_message.document, file_name="nana/cache/sticker.png")
else:
await edrep(message, text="Reply a sticker or photo to kang it!\nCurrent sticker pack is: {}\nCurrent animation pack is: {}".format(
Expand Down Expand Up @@ -91,13 +96,11 @@ async def kang_stickers(client, message):
im.save("nana/cache/sticker.png", 'PNG')

await client.send_message("@Stickers", "/addsticker")
await client.read_history("@Stickers")
time.sleep(0.2)
if message.reply_to_message.sticker and message.reply_to_message.sticker.mime_type == "application/x-tgsticker":
await client.send_message("@Stickers", animation_pack.sticker)
else:
await client.send_message("@Stickers", sticker_pack)
await client.read_history("@Stickers")
time.sleep(0.2)
checkfull = await app.get_history("@Stickers", limit=1)
if checkfull[
Expand All @@ -112,19 +115,13 @@ async def kang_stickers(client, message):
else:
await client.send_document("@Stickers", 'nana/cache/sticker.png')
os.remove('nana/cache/sticker.png')
try:
if len(message.text.split(None,1)) > 1:
ic = message.text.split(None, 1)[1]
except Exception as e:
print(e)
try:
ic = message.reply_to_message.sticker.emoji
except Exception as err:
print(err)
ic = "🤔"
if ic is None:
elif message.reply_to_message.sticker:
ic = message.reply_to_message.sticker.emoji
else:
ic = "🤔"
await client.send_message("@Stickers", ic)
await client.read_history("@Stickers")
time.sleep(1)
await client.send_message("@Stickers", "/done")
if message.reply_to_message.sticker and message.reply_to_message.sticker.mime_type == "application/x-tgsticker":
Expand All @@ -134,4 +131,3 @@ async def kang_stickers(client, message):
else:
await edrep(message, text="**Sticker added!**\nYour sticker has been saved on [This sticker pack](https://t.me/addstickers/{})".format(
sticker_pack))
await client.read_history("@Stickers")

0 comments on commit 2681579

Please sign in to comment.