mirror of
https://github.com/PaiGramTeam/PamGram.git
synced 2024-11-16 12:02:16 +00:00
🎨 Update get_args
This commit is contained in:
parent
29446e3443
commit
80b96d4c51
@ -9,7 +9,7 @@ from core.baseplugin import BasePlugin
|
|||||||
from core.plugin import Plugin, handler
|
from core.plugin import Plugin, handler
|
||||||
from metadata.genshin import AVATAR_DATA
|
from metadata.genshin import AVATAR_DATA
|
||||||
from metadata.shortname import roleToId, roleToName
|
from metadata.shortname import roleToId, roleToName
|
||||||
from utils.bot import get_all_args
|
from utils.bot import get_args
|
||||||
from utils.decorators.error import error_callable
|
from utils.decorators.error import error_callable
|
||||||
from utils.decorators.restricts import restricts
|
from utils.decorators.restricts import restricts
|
||||||
from utils.log import logger
|
from utils.log import logger
|
||||||
@ -45,7 +45,7 @@ class BirthdayPlugin(Plugin, BasePlugin):
|
|||||||
+ "_"
|
+ "_"
|
||||||
+ rm_starting_str(datetime.now().strftime("%d"), "0")
|
+ rm_starting_str(datetime.now().strftime("%d"), "0")
|
||||||
)
|
)
|
||||||
args = get_all_args(context)
|
args = get_args(context)
|
||||||
if len(args) >= 1:
|
if len(args) >= 1:
|
||||||
msg = args[0]
|
msg = args[0]
|
||||||
logger.info(f"用户 {user.full_name}[{user.id}] 查询角色生日命令请求 || 参数 {msg}")
|
logger.info(f"用户 {user.full_name}[{user.id}] 查询角色生日命令请求 || 参数 {msg}")
|
||||||
|
@ -32,7 +32,7 @@ from core.template import TemplateService
|
|||||||
from core.template.models import FileType, RenderGroupResult
|
from core.template.models import FileType, RenderGroupResult
|
||||||
from core.user.error import UserNotFoundError
|
from core.user.error import UserNotFoundError
|
||||||
from metadata.genshin import AVATAR_DATA, HONEY_DATA
|
from metadata.genshin import AVATAR_DATA, HONEY_DATA
|
||||||
from utils.bot import get_all_args
|
from utils.bot import get_args
|
||||||
from utils.decorators.admins import bot_admins_rights_check
|
from utils.decorators.admins import bot_admins_rights_check
|
||||||
from utils.decorators.error import error_callable
|
from utils.decorators.error import error_callable
|
||||||
from utils.decorators.restricts import restricts
|
from utils.decorators.restricts import restricts
|
||||||
@ -211,7 +211,7 @@ class DailyMaterial(Plugin, BasePlugin):
|
|||||||
async def daily_material(self, update: Update, context: CallbackContext):
|
async def daily_material(self, update: Update, context: CallbackContext):
|
||||||
user = update.effective_user
|
user = update.effective_user
|
||||||
message = update.effective_message
|
message = update.effective_message
|
||||||
args = get_all_args(context)
|
args = get_args(context)
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -20,7 +20,7 @@ from modules.apihelper.hyperion import GachaInfo, GachaInfoObject
|
|||||||
from modules.gacha.banner import BannerType, GachaBanner
|
from modules.gacha.banner import BannerType, GachaBanner
|
||||||
from modules.gacha.player.info import PlayerGachaInfo
|
from modules.gacha.player.info import PlayerGachaInfo
|
||||||
from modules.gacha.system import BannerSystem
|
from modules.gacha.system import BannerSystem
|
||||||
from utils.bot import get_all_args
|
from utils.bot import get_args
|
||||||
from utils.decorators.error import error_callable
|
from utils.decorators.error import error_callable
|
||||||
from utils.decorators.restricts import restricts
|
from utils.decorators.restricts import restricts
|
||||||
from utils.log import logger
|
from utils.log import logger
|
||||||
@ -169,7 +169,7 @@ class Gacha(Plugin, BasePlugin):
|
|||||||
async def command_start(self, update: Update, context: CallbackContext) -> None:
|
async def command_start(self, update: Update, context: CallbackContext) -> None:
|
||||||
message = update.effective_message
|
message = update.effective_message
|
||||||
user = update.effective_user
|
user = update.effective_user
|
||||||
args = get_all_args(context)
|
args = get_args(context)
|
||||||
gacha_name = "角色活动"
|
gacha_name = "角色活动"
|
||||||
if len(args) >= 1:
|
if len(args) >= 1:
|
||||||
gacha_name = args[0]
|
gacha_name = args[0]
|
||||||
@ -245,7 +245,7 @@ class Gacha(Plugin, BasePlugin):
|
|||||||
async def set_wish(self, update: Update, context: CallbackContext) -> None:
|
async def set_wish(self, update: Update, context: CallbackContext) -> None:
|
||||||
message = update.effective_message
|
message = update.effective_message
|
||||||
user = update.effective_user
|
user = update.effective_user
|
||||||
args = get_all_args(context)
|
args = get_args(context)
|
||||||
try:
|
try:
|
||||||
gacha_base_info = await self.handle.gacha_base_info("武器活动")
|
gacha_base_info = await self.handle.gacha_base_info("武器活动")
|
||||||
except GachaNotFound:
|
except GachaNotFound:
|
||||||
|
@ -30,7 +30,7 @@ from modules.gacha_log.error import (
|
|||||||
)
|
)
|
||||||
from modules.gacha_log.helpers import from_url_get_authkey
|
from modules.gacha_log.helpers import from_url_get_authkey
|
||||||
from modules.gacha_log.log import GachaLog
|
from modules.gacha_log.log import GachaLog
|
||||||
from utils.bot import get_all_args
|
from utils.bot import get_args
|
||||||
from utils.decorators.admins import bot_admins_rights_check
|
from utils.decorators.admins import bot_admins_rights_check
|
||||||
from utils.decorators.error import error_callable
|
from utils.decorators.error import error_callable
|
||||||
from utils.decorators.restricts import restricts
|
from utils.decorators.restricts import restricts
|
||||||
@ -150,7 +150,7 @@ class GachaLogPlugin(Plugin.Conversation, BasePlugin.Conversation):
|
|||||||
async def command_start(self, update: Update, context: CallbackContext) -> int:
|
async def command_start(self, update: Update, context: CallbackContext) -> int:
|
||||||
message = update.effective_message
|
message = update.effective_message
|
||||||
user = update.effective_user
|
user = update.effective_user
|
||||||
args = get_all_args(context)
|
args = get_args(context)
|
||||||
logger.info(f"用户 {user.full_name}[{user.id}] 导入抽卡记录命令请求")
|
logger.info(f"用户 {user.full_name}[{user.id}] 导入抽卡记录命令请求")
|
||||||
authkey = from_url_get_authkey(args[0] if args else "")
|
authkey = from_url_get_authkey(args[0] if args else "")
|
||||||
if not args:
|
if not args:
|
||||||
@ -269,7 +269,7 @@ class GachaLogPlugin(Plugin.Conversation, BasePlugin.Conversation):
|
|||||||
@bot_admins_rights_check
|
@bot_admins_rights_check
|
||||||
async def command_gacha_log_force_delete(self, update: Update, context: CallbackContext):
|
async def command_gacha_log_force_delete(self, update: Update, context: CallbackContext):
|
||||||
message = update.effective_message
|
message = update.effective_message
|
||||||
args = get_all_args(context)
|
args = get_args(context)
|
||||||
if not args:
|
if not args:
|
||||||
await message.reply_text("请指定用户ID")
|
await message.reply_text("请指定用户ID")
|
||||||
return
|
return
|
||||||
@ -335,7 +335,7 @@ class GachaLogPlugin(Plugin.Conversation, BasePlugin.Conversation):
|
|||||||
message = update.effective_message
|
message = update.effective_message
|
||||||
user = update.effective_user
|
user = update.effective_user
|
||||||
pool_type = BannerType.CHARACTER1
|
pool_type = BannerType.CHARACTER1
|
||||||
if args := get_all_args(context):
|
if args := get_args(context):
|
||||||
if "武器" in args:
|
if "武器" in args:
|
||||||
pool_type = BannerType.WEAPON
|
pool_type = BannerType.WEAPON
|
||||||
elif "常驻" in args:
|
elif "常驻" in args:
|
||||||
@ -383,7 +383,7 @@ class GachaLogPlugin(Plugin.Conversation, BasePlugin.Conversation):
|
|||||||
user = update.effective_user
|
user = update.effective_user
|
||||||
pool_type = BannerType.CHARACTER1
|
pool_type = BannerType.CHARACTER1
|
||||||
all_five = False
|
all_five = False
|
||||||
if args := get_all_args(context):
|
if args := get_args(context):
|
||||||
if "武器" in args:
|
if "武器" in args:
|
||||||
pool_type = BannerType.WEAPON
|
pool_type = BannerType.WEAPON
|
||||||
elif "常驻" in args:
|
elif "常驻" in args:
|
||||||
|
@ -7,7 +7,7 @@ from telegram.ext import filters
|
|||||||
|
|
||||||
from core.baseplugin import BasePlugin
|
from core.baseplugin import BasePlugin
|
||||||
from core.plugin import Plugin, handler
|
from core.plugin import Plugin, handler
|
||||||
from utils.bot import get_all_args
|
from utils.bot import get_args
|
||||||
from utils.decorators.error import error_callable
|
from utils.decorators.error import error_callable
|
||||||
from utils.decorators.restricts import restricts
|
from utils.decorators.restricts import restricts
|
||||||
from utils.log import logger
|
from utils.log import logger
|
||||||
@ -27,7 +27,7 @@ class HilichurlsPlugin(Plugin, BasePlugin):
|
|||||||
async def command_start(self, update: Update, context: CallbackContext) -> None:
|
async def command_start(self, update: Update, context: CallbackContext) -> None:
|
||||||
message = update.effective_message
|
message = update.effective_message
|
||||||
user = update.effective_user
|
user = update.effective_user
|
||||||
args = get_all_args(context)
|
args = get_args(context)
|
||||||
if len(args) >= 1:
|
if len(args) >= 1:
|
||||||
msg = args[0]
|
msg = args[0]
|
||||||
else:
|
else:
|
||||||
|
@ -15,7 +15,7 @@ from core.plugin import Plugin, handler
|
|||||||
from core.template.services import RenderResult, TemplateService
|
from core.template.services import RenderResult, TemplateService
|
||||||
from core.user.error import UserNotFoundError
|
from core.user.error import UserNotFoundError
|
||||||
from core.user.services import UserService
|
from core.user.services import UserService
|
||||||
from utils.bot import get_all_args
|
from utils.bot import get_args
|
||||||
from utils.decorators.error import error_callable
|
from utils.decorators.error import error_callable
|
||||||
from utils.decorators.restricts import restricts
|
from utils.decorators.restricts import restricts
|
||||||
from utils.helpers import get_genshin_client
|
from utils.helpers import get_genshin_client
|
||||||
@ -30,7 +30,7 @@ def get_now() -> datetime:
|
|||||||
def check_ledger_month(context: CallbackContext) -> int:
|
def check_ledger_month(context: CallbackContext) -> int:
|
||||||
now_time = get_now()
|
now_time = get_now()
|
||||||
month = now_time.month
|
month = now_time.month
|
||||||
args = get_all_args(context)
|
args = get_args(context)
|
||||||
if len(args) >= 1:
|
if len(args) >= 1:
|
||||||
month = args[0].replace("月", "")
|
month = args[0].replace("月", "")
|
||||||
if re_data := re.findall(r"\d+", str(month)):
|
if re_data := re.findall(r"\d+", str(month)):
|
||||||
|
@ -6,7 +6,7 @@ from core.baseplugin import BasePlugin
|
|||||||
from core.game.services import GameMaterialService
|
from core.game.services import GameMaterialService
|
||||||
from core.plugin import Plugin, handler
|
from core.plugin import Plugin, handler
|
||||||
from metadata.shortname import roleToName
|
from metadata.shortname import roleToName
|
||||||
from utils.bot import get_all_args
|
from utils.bot import get_args
|
||||||
from utils.decorators.error import error_callable
|
from utils.decorators.error import error_callable
|
||||||
from utils.decorators.restricts import restricts
|
from utils.decorators.restricts import restricts
|
||||||
from utils.helpers import url_to_file
|
from utils.helpers import url_to_file
|
||||||
@ -28,7 +28,7 @@ class Material(Plugin, BasePlugin):
|
|||||||
async def command_start(self, update: Update, context: CallbackContext) -> None:
|
async def command_start(self, update: Update, context: CallbackContext) -> None:
|
||||||
message = update.effective_message
|
message = update.effective_message
|
||||||
user = update.effective_user
|
user = update.effective_user
|
||||||
args = get_all_args(context)
|
args = get_args(context)
|
||||||
if len(args) >= 1:
|
if len(args) >= 1:
|
||||||
character_name = args[0]
|
character_name = args[0]
|
||||||
else:
|
else:
|
||||||
|
@ -31,7 +31,7 @@ from core.user import UserService
|
|||||||
from core.user.error import UserNotFoundError
|
from core.user.error import UserNotFoundError
|
||||||
from metadata.shortname import roleToName
|
from metadata.shortname import roleToName
|
||||||
from modules.playercards.helpers import ArtifactStatsTheory, fix_skills_level_data
|
from modules.playercards.helpers import ArtifactStatsTheory, fix_skills_level_data
|
||||||
from utils.bot import get_all_args
|
from utils.bot import get_args
|
||||||
from utils.decorators.error import error_callable
|
from utils.decorators.error import error_callable
|
||||||
from utils.decorators.restricts import restricts
|
from utils.decorators.restricts import restricts
|
||||||
from utils.helpers import url_to_file
|
from utils.helpers import url_to_file
|
||||||
@ -68,7 +68,7 @@ class PlayerCards(Plugin, BasePlugin):
|
|||||||
async def player_cards(self, update: Update, context: CallbackContext) -> None:
|
async def player_cards(self, update: Update, context: CallbackContext) -> None:
|
||||||
user = update.effective_user
|
user = update.effective_user
|
||||||
message = update.effective_message
|
message = update.effective_message
|
||||||
args = get_all_args(context)
|
args = get_args(context)
|
||||||
await message.reply_chat_action(ChatAction.TYPING)
|
await message.reply_chat_action(ChatAction.TYPING)
|
||||||
try:
|
try:
|
||||||
user_info = await self.user_service.get_user_by_id(user.id)
|
user_info = await self.user_service.get_user_by_id(user.id)
|
||||||
|
@ -27,7 +27,7 @@ from core.sign.services import SignServices
|
|||||||
from core.user.error import UserNotFoundError
|
from core.user.error import UserNotFoundError
|
||||||
from core.user.services import UserService
|
from core.user.services import UserService
|
||||||
from modules.apihelper.hyperion import Verification
|
from modules.apihelper.hyperion import Verification
|
||||||
from utils.bot import get_all_args
|
from utils.bot import get_args
|
||||||
from utils.decorators.error import error_callable
|
from utils.decorators.error import error_callable
|
||||||
from utils.decorators.restricts import restricts
|
from utils.decorators.restricts import restricts
|
||||||
from utils.helpers import get_genshin_client
|
from utils.helpers import get_genshin_client
|
||||||
@ -345,7 +345,7 @@ class Sign(Plugin, BasePlugin):
|
|||||||
async def command_start(self, update: Update, context: CallbackContext) -> None:
|
async def command_start(self, update: Update, context: CallbackContext) -> None:
|
||||||
user = update.effective_user
|
user = update.effective_user
|
||||||
message = update.effective_message
|
message = update.effective_message
|
||||||
args = get_all_args(context)
|
args = get_args(context)
|
||||||
validate: Optional[str] = None
|
validate: Optional[str] = None
|
||||||
if len(args) >= 1:
|
if len(args) >= 1:
|
||||||
msg = None
|
msg = None
|
||||||
|
@ -9,7 +9,7 @@ from core.baseplugin import BasePlugin
|
|||||||
from core.game.services import GameStrategyService
|
from core.game.services import GameStrategyService
|
||||||
from core.plugin import Plugin, handler
|
from core.plugin import Plugin, handler
|
||||||
from metadata.shortname import roleToName
|
from metadata.shortname import roleToName
|
||||||
from utils.bot import get_all_args
|
from utils.bot import get_args
|
||||||
from utils.decorators.error import error_callable
|
from utils.decorators.error import error_callable
|
||||||
from utils.decorators.restricts import restricts
|
from utils.decorators.restricts import restricts
|
||||||
from utils.helpers import url_to_file
|
from utils.helpers import url_to_file
|
||||||
@ -31,7 +31,7 @@ class StrategyPlugin(Plugin, BasePlugin):
|
|||||||
async def command_start(self, update: Update, context: CallbackContext) -> None:
|
async def command_start(self, update: Update, context: CallbackContext) -> None:
|
||||||
message = update.effective_message
|
message = update.effective_message
|
||||||
user = update.effective_user
|
user = update.effective_user
|
||||||
args = get_all_args(context)
|
args = get_args(context)
|
||||||
if len(args) >= 1:
|
if len(args) >= 1:
|
||||||
character_name = args[0]
|
character_name = args[0]
|
||||||
else:
|
else:
|
||||||
|
@ -10,7 +10,7 @@ from core.wiki.services import WikiService
|
|||||||
from metadata.genshin import honey_id_to_game_id
|
from metadata.genshin import honey_id_to_game_id
|
||||||
from metadata.shortname import weaponToName
|
from metadata.shortname import weaponToName
|
||||||
from modules.wiki.weapon import Weapon
|
from modules.wiki.weapon import Weapon
|
||||||
from utils.bot import get_all_args
|
from utils.bot import get_args
|
||||||
from utils.decorators.error import error_callable
|
from utils.decorators.error import error_callable
|
||||||
from utils.decorators.restricts import restricts
|
from utils.decorators.restricts import restricts
|
||||||
from utils.helpers import url_to_file
|
from utils.helpers import url_to_file
|
||||||
@ -39,7 +39,7 @@ class WeaponPlugin(Plugin, BasePlugin):
|
|||||||
async def command_start(self, update: Update, context: CallbackContext) -> None:
|
async def command_start(self, update: Update, context: CallbackContext) -> None:
|
||||||
message = update.effective_message
|
message = update.effective_message
|
||||||
user = update.effective_user
|
user = update.effective_user
|
||||||
args = get_all_args(context)
|
args = get_args(context)
|
||||||
if len(args) >= 1:
|
if len(args) >= 1:
|
||||||
weapon_name = args[0]
|
weapon_name = args[0]
|
||||||
else:
|
else:
|
||||||
|
@ -12,7 +12,7 @@ from core.sign import SignServices
|
|||||||
from core.user import UserService
|
from core.user import UserService
|
||||||
from core.user.error import UserNotFoundError
|
from core.user.error import UserNotFoundError
|
||||||
from modules.gacha_log.log import GachaLog
|
from modules.gacha_log.log import GachaLog
|
||||||
from utils.bot import get_all_args, get_chat as get_chat_with_cache
|
from utils.bot import get_args, get_chat as get_chat_with_cache
|
||||||
from utils.decorators.admins import bot_admins_rights_check
|
from utils.decorators.admins import bot_admins_rights_check
|
||||||
from utils.helpers import get_genshin_client
|
from utils.helpers import get_genshin_client
|
||||||
from utils.log import logger
|
from utils.log import logger
|
||||||
@ -111,7 +111,7 @@ class GetChat(Plugin):
|
|||||||
user = update.effective_user
|
user = update.effective_user
|
||||||
logger.info(f"用户 {user.full_name}[{user.id}] get_chat 命令请求")
|
logger.info(f"用户 {user.full_name}[{user.id}] get_chat 命令请求")
|
||||||
message = update.effective_message
|
message = update.effective_message
|
||||||
args = get_all_args(context)
|
args = get_args(context)
|
||||||
if not args:
|
if not args:
|
||||||
await message.reply_text("参数错误,请指定群 id !")
|
await message.reply_text("参数错误,请指定群 id !")
|
||||||
return
|
return
|
||||||
|
@ -10,7 +10,7 @@ from telegram.ext import CallbackContext, CommandHandler
|
|||||||
|
|
||||||
from core.bot import bot
|
from core.bot import bot
|
||||||
from core.plugin import handler, Plugin
|
from core.plugin import handler, Plugin
|
||||||
from utils.bot import get_all_args
|
from utils.bot import get_args
|
||||||
from utils.decorators.admins import bot_admins_rights_check
|
from utils.decorators.admins import bot_admins_rights_check
|
||||||
from utils.helpers import execute
|
from utils.helpers import execute
|
||||||
from utils.log import logger
|
from utils.log import logger
|
||||||
@ -42,7 +42,7 @@ class UpdatePlugin(Plugin):
|
|||||||
async def update(self, update: Update, context: CallbackContext):
|
async def update(self, update: Update, context: CallbackContext):
|
||||||
user = update.effective_user
|
user = update.effective_user
|
||||||
message = update.effective_message
|
message = update.effective_message
|
||||||
args = get_all_args(context)
|
args = get_args(context)
|
||||||
logger.info(f"用户 {user.full_name}[{user.id}] update命令请求")
|
logger.info(f"用户 {user.full_name}[{user.id}] update命令请求")
|
||||||
if self._lock.locked():
|
if self._lock.locked():
|
||||||
await message.reply_text("程序正在更新 请勿重复操作")
|
await message.reply_text("程序正在更新 请勿重复操作")
|
||||||
|
12
utils/bot.py
12
utils/bot.py
@ -25,13 +25,21 @@ async def get_chat(chat_id: Union[str, int], ttl: int = 86400) -> Chat:
|
|||||||
return chat_info
|
return chat_info
|
||||||
|
|
||||||
|
|
||||||
def get_all_args(context: CallbackContext) -> List[str]:
|
def get_args(context: CallbackContext) -> List[str]:
|
||||||
args = context.args
|
args = context.args
|
||||||
match = context.match
|
match = context.match
|
||||||
if args is None:
|
if args is None:
|
||||||
if match is not None:
|
if match is not None:
|
||||||
groups = match.groups()
|
groups = match.groups()
|
||||||
return list(groups)
|
command = groups[0]
|
||||||
|
if command:
|
||||||
|
temp = []
|
||||||
|
command_parts = command.split(" ")
|
||||||
|
for command_part in command_parts:
|
||||||
|
if command_part:
|
||||||
|
temp.append(command_part)
|
||||||
|
return temp
|
||||||
|
return []
|
||||||
else:
|
else:
|
||||||
if len(args) >= 1:
|
if len(args) >= 1:
|
||||||
return args
|
return args
|
||||||
|
Loading…
Reference in New Issue
Block a user