Skip to content

Commit

Permalink
Merge pull request #289 from AnimeKaizoku/KigyoDev
Browse files Browse the repository at this point in the history
merge fixes
  • Loading branch information
Dank-del authored Apr 3, 2024
2 parents 617ce04 + 7055cb1 commit c89dc14
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion tg_bot/modules/sibylsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

if SIBYL_KEY and __name__.split(".")[-1] in ALL_MODULES:
try:
sibylClient = PsychoPass(SIBYL_KEY)
sibylClient = PsychoPass(token=SIBYL_KEY, host='https://psychopass.kaizoku.cyou')
LOGGER.info("Connected to @SibylSystem")
except Exception as e:
sibylClient = None
Expand Down
2 changes: 0 additions & 2 deletions tg_bot/modules/sticker_blacklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ def add_blackliststicker(update: Update, context: CallbackContext):
added = 0
for trigger in to_blacklist:
try:
get = bot.getStickerSet(trigger)
sql.add_to_stickers(chat_id, trigger.lower())
added += 1
except BadRequest:
Expand Down Expand Up @@ -135,7 +134,6 @@ def add_blackliststicker(update: Update, context: CallbackContext):
send_message(update.effective_message, "Sticker is invalid!")
return
try:
get = bot.getStickerSet(trigger)
sql.add_to_stickers(chat_id, trigger.lower())
added += 1
except BadRequest:
Expand Down
29 changes: 16 additions & 13 deletions tg_bot/modules/stickers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@
from urllib.error import HTTPError

from PIL import Image
from telegram import (InlineKeyboardButton, InlineKeyboardMarkup, ParseMode,
from telegram import (Bot, InlineKeyboardButton, InlineKeyboardMarkup, ParseMode,
TelegramError, Update)
from telegram.ext import CallbackContext
from telegram.utils.helpers import mention_html
from tg_bot.modules.helper_funcs.decorators import kigcmd, rate_limit

def get_sticker_count(bot: Bot, packname: str) -> int:
resp = bot._request.post(
f"{bot.base_url}/getStickerSet",
{
"name": packname,
},
)
return len(resp["stickers"])

@kigcmd(command='stickerid')
@rate_limit(40, 60)
Expand All @@ -37,24 +45,19 @@ def stickerid(update: Update, context: CallbackContext):
@kigcmd(command='getsticker')
@rate_limit(40, 60)
def getsticker(update: Update, context: CallbackContext):
bot = context.bot
msg = update.effective_message
chat_id = update.effective_chat.id
if msg.reply_to_message and msg.reply_to_message.sticker:
file_id = msg.reply_to_message.sticker.file_id
# Check if it's an animated file
is_animated = msg.reply_to_message.sticker.is_animated
bot = context.bot
# Get the file and put it into a memory buffer
new_file = bot.get_file(file_id)
sticker_data = new_file.download(out=BytesIO())
# go back to the start of the buffer
sticker_data.seek(0)
# Reply with the document. Telegram INSISTS on making anything
# that ends in .tgs become an animated sticker so we'll have to
# rename it to something the user should know how to handle.
filename = "sticker.png"
if is_animated:
filename = "animated_sticker.tgs.rename_me"
filename = "animated_sticker.tgs.rename_me" if is_animated else "sticker.png"
chat_id = update.effective_chat.id
# Send the document
bot.send_document(chat_id,
document=sticker_data,
Expand Down Expand Up @@ -100,8 +103,7 @@ def kang(update: Update, context: CallbackContext): # sourcery no-metrics
while True:
last_set = False
try:
stickerset = context.bot.get_sticker_set(packname)
if len(stickerset.stickers) >= max_stickers:
if get_sticker_count(context.bot, packname) >= max_stickers:
packnum += 1
if is_animated:
packname = f"animated{packnum}_{user.id}_by_{context.bot.username}"
Expand Down Expand Up @@ -232,8 +234,7 @@ def kang(update: Update, context: CallbackContext): # sourcery no-metrics
# Find if the pack is full already
while not packname_found:
try:
stickerset = context.bot.get_sticker_set(packname)
if len(stickerset.stickers) >= max_stickers:
if get_sticker_count(context.bot, packname) >= max_stickers:
packnum += 1
if is_animated:
packname = f"animated{packnum}_{user.id}_by_{context.bot.username}"
Expand All @@ -248,6 +249,8 @@ def kang(update: Update, context: CallbackContext): # sourcery no-metrics
packname_found = True
# we will need to create the sticker pack
invalid = True
else:
raise

# if the image isn't animated, ensure it's the right size/format with PIL
if not is_animated and not is_video:
Expand Down

0 comments on commit c89dc14

Please sign in to comment.