Skip to content

Commit

Permalink
Merge pull request #106 from TopRealm/conflict
Browse files Browse the repository at this point in the history
Resolve conflicts
  • Loading branch information
ZoruaFox authored Sep 23, 2024
2 parents fb3535d + b3269fc commit 9ddf660
Show file tree
Hide file tree
Showing 35 changed files with 158 additions and 200 deletions.
2 changes: 1 addition & 1 deletion bots/aiocqhttp/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
from bots.aiocqhttp.info import client_name
from bots.aiocqhttp.message import MessageSession, FetchTarget
from config import Config
from core.bot import load_prompt, init_async
from core.builtins import EnableDirtyWordCheck, PrivateAssets, Url
from core.parser.message import parser
from core.tos import tos_report
from core.types import MsgInfo, Session
from core.utils.bot import load_prompt, init_async
from core.utils.info import Info
from core.utils.i18n import Locale, default_locale
from database import BotDBUtil
Expand Down
2 changes: 1 addition & 1 deletion bots/aiogram/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
from bots.aiogram.client import dp, bot
from bots.aiogram.info import client_name
from bots.aiogram.message import MessageSession, FetchTarget
from core.bot import load_prompt, init_async
from core.builtins import PrivateAssets, Url
from core.parser.message import parser
from core.types import MsgInfo, Session
from core.utils.bot import load_prompt, init_async
from core.utils.info import Info

PrivateAssets.set('assets/private/aiogram')
Expand Down
2 changes: 1 addition & 1 deletion bots/api/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

sys.path.append(os.getcwd())

from core.bot import init_async, load_prompt # noqa: E402
from core.loader import ModulesManager # noqa: E402
from core.utils.i18n import Locale # noqa: E402
from core.utils.bot import init_async, load_prompt # noqa: E402
from core.extra.scheduler import load_extra_schedulers # noqa: E402
from config import Config # noqa: E402
from database import BotDBUtil # noqa: E402
Expand Down
2 changes: 1 addition & 1 deletion bots/discord/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
from bots.discord.info import client_name
from bots.discord.message import MessageSession, FetchTarget
from config import Config
from core.bot import init_async, load_prompt
from core.builtins import PrivateAssets, Url
from core.logger import Logger
from core.parser.message import parser
from core.types import MsgInfo, Session
from core.utils.bot import init_async, load_prompt
from core.utils.info import Info

PrivateAssets.set('assets/private/discord')
Expand Down
2 changes: 1 addition & 1 deletion bots/kook/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from bots.kook.info import client_name
from bots.kook.message import MessageSession, FetchTarget
from config import Config
from core.bot import load_prompt, init_async
from core.builtins import PrivateAssets, Url, EnableDirtyWordCheck
from core.parser.message import parser
from core.types import MsgInfo, Session
from core.utils.bot import load_prompt, init_async
from core.utils.info import Info

PrivateAssets.set('assets/private/kook')
Expand Down
2 changes: 1 addition & 1 deletion bots/matrix/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
from bots.matrix.client import bot
from bots.matrix.info import client_name
from bots.matrix.message import MessageSession, FetchTarget
from core.bot import load_prompt, init_async
from core.builtins import PrivateAssets, Url
from core.logger import Logger
from core.parser.message import parser
from core.types import MsgInfo, Session
from core.utils.bot import load_prompt, init_async
from core.utils.info import Info

PrivateAssets.set('assets/private/matrix')
Expand Down
2 changes: 1 addition & 1 deletion console.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
' bot will automatically create a SQLite database in the "./database/save.db")')

from bot import init_bot
from core.bot import init_async
from core.builtins import PrivateAssets, EnableDirtyWordCheck, Url
from core.console.message import MessageSession
from core.extra.scheduler import load_extra_schedulers
from core.parser.message import parser
from core.utils.bot import init_async
from core.types import MsgInfo, Session
from database import BotDBUtil, session
from database.tables import DBVersion
Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions core/queue.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import asyncio
from datetime import datetime
import traceback

import ujson as json

from core.builtins import Bot, Temp, MessageChain
from core.builtins import Bot, MessageChain
from core.logger import Logger
from core.utils.info import get_all_clients_name
from core.utils.ip import append_ip, fetch_ip_info
Expand Down
51 changes: 0 additions & 51 deletions core/rate_limit.py

This file was deleted.

16 changes: 8 additions & 8 deletions core/utils/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ def private_ip_check(url: str):
f'Attempt of requesting private IP addresses is not allowed, requesting {hostname}.')


async def get_url(url: str, status_code: int = False, headers: dict = None, params: dict = None, fmt=None, timeout=20,
attempt=3,
request_private_ip=False, logging_err_resp=True, cookies=None):
async def get_url(url: str, status_code: int = False, headers: dict = None, params: dict = None, fmt: str = None, timeout: int = 20,
attempt: int = 3,
request_private_ip: bool = False, logging_err_resp: bool = True, cookies: dict = None):
"""利用AioHttp获取指定url的内容。
:param url: 需要获取的url。
Expand Down Expand Up @@ -100,8 +100,8 @@ async def get_():
return await get_()


async def post_url(url: str, data: any = None, status_code: int = False, headers: dict = None, fmt=None, timeout=20,
attempt=3, request_private_ip=False, logging_err_resp=True, cookies=None):
async def post_url(url: str, data: any = None, status_code: int = False, headers: dict = None, fmt: str = None, timeout: int = 20,
attempt: int = 3, request_private_ip: bool = False, logging_err_resp: bool = True, cookies: dict = None):
'''利用AioHttp发送POST请求。
:param url: 需要发送的url。
Expand Down Expand Up @@ -159,9 +159,9 @@ async def _post():
return await _post()


async def download(url: str, filename=None, path=None, status_code: int = False, method="GET", post_data=None,
headers: dict = None, timeout=20, attempt=3, request_private_ip=False,
logging_err_resp=True) -> Union[str, bool]:
async def download(url: str, filename: str = None, path: str = None, status_code: int = False, method: str = "GET", post_data: any = None,
headers: dict = None, timeout: int = 20, attempt: int = 3, request_private_ip: bool = False,
logging_err_resp: bool = True) -> Union[str, bool]:
'''利用AioHttp下载指定url的内容,并保存到指定目录。
:param url: 需要获取的url。
Expand Down
2 changes: 1 addition & 1 deletion core/utils/ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class IP:
country = None


def append_ip(ip_info):
def append_ip(ip_info: dict):
Secret.add(ip_info['ip'])
IP.country = ip_info['country']
IP.address = ip_info['ip']
Expand Down
184 changes: 101 additions & 83 deletions core/petal.py → core/utils/petal.py
Original file line number Diff line number Diff line change
@@ -1,83 +1,101 @@
from datetime import datetime, timedelta, timezone

from config import Config
from core.builtins import Bot
from core.utils.storedata import get_stored_list, update_stored_list


async def gained_petal(msg: Bot.MessageSession, amount: int):
'''增加花瓣。
:param msg: 消息会话。
:param amount: 增加的花瓣数量。
:returns: 增加花瓣的提示消息。
'''
if Config('enable_petal', False) and Config('enable_get_petal', False):
limit = Config('gained_petal_limit', 0)
amount = limit if amount > limit and limit > 0 else amount
p = get_stored_list(msg.target.client_name, 'gainedpetal')
if not p:
p = [{}]
p = p[0]
now = datetime.now(timezone.utc) + msg.timezone_offset
expired = datetime.combine((now + timedelta(days=1)).date(), datetime.min.time())
if msg.target.sender_id not in p or not p[msg.target.sender_id].get(
'expired') or now.timestamp() > p[msg.target.sender_id]['expired']:
p[msg.target.sender_id] = {'time': now.timestamp(),
'expired': expired.timestamp(),
'amount': amount
}
p = [p]
msg.info.modify_petal(amount)
update_stored_list(msg.target.client_name, 'gainedpetal', p)
return msg.locale.t('petal.message.gained.success', amount=amount)
else:
if limit > 0:
if p[msg.target.sender_id]['amount'] >= limit:
return msg.locale.t('petal.message.gained.limit')
elif p[msg.target.sender_id]['amount'] + amount > limit:
amount = limit - p[msg.target.sender_id]['amount']
p[msg.target.sender_id]['amount'] += amount
p = [p]
msg.info.modify_petal(amount)
update_stored_list(msg.target.client_name, 'gainedpetal', p)
return msg.locale.t('petal.message.gained.success', amount=amount)


async def lost_petal(msg: Bot.MessageSession, amount: int):
'''减少花瓣。
:param msg: 消息会话。
:param amount: 减少的花瓣数量。
:returns: 减少花瓣的提示消息。
'''
if Config('enable_petal', False) and Config('enable_get_petal', False):
limit = Config('lost_petal_limit', 0)
amount = limit if amount > limit and limit > 0 else amount
p = get_stored_list(msg.target.client_name, 'lostpetal')
if not p:
p = [{}]
p = p[0]
now = datetime.now(timezone.utc) + msg.timezone_offset
expired = datetime.combine((now + timedelta(days=1)).date(), datetime.min.time())
if msg.target.sender_id not in p or not p[msg.target.sender_id].get(
'expired') or now.timestamp() > p[msg.target.sender_id]['expired']:
p[msg.target.sender_id] = {'time': now.timestamp(),
'expired': expired.timestamp(),
'amount': amount
}
p = [p]
msg.info.modify_petal(-amount)
update_stored_list(msg.target.client_name, 'lostpetal', p)
return msg.locale.t('petal.message.lost.success', amount=amount)
else:
if limit > 0:
if p[msg.target.sender_id]['amount'] >= limit:
return msg.locale.t('petal.message.lost.limit')
elif p[msg.target.sender_id]['amount'] + amount > limit:
amount = limit - p[msg.target.sender_id]['amount']
p[msg.target.sender_id]['amount'] += amount
p = [p]
msg.info.modify_petal(-amount)
update_stored_list(msg.target.client_name, 'lostpetal', p)
return msg.locale.t('petal.message.lost.success', amount=amount)
from datetime import datetime, timedelta, timezone

from config import Config
from core.builtins import Bot
from core.utils.storedata import get_stored_list, update_stored_list


async def gained_petal(msg: Bot.MessageSession, amount: int):
'''增加花瓣。
:param msg: 消息会话。
:param amount: 增加的花瓣数量。
:returns: 增加花瓣的提示消息。
'''
if Config('enable_petal', False) and Config('enable_get_petal', False):
limit = Config('gained_petal_limit', 0)
amount = limit if amount > limit and limit > 0 else amount
p = get_stored_list(msg.target.client_name, 'gainedpetal')
if not p:
p = [{}]
p = p[0]
now = datetime.now(timezone.utc) + msg.timezone_offset
expired = datetime.combine((now + timedelta(days=1)).date(), datetime.min.time())
if msg.target.sender_id not in p or not p[msg.target.sender_id].get(
'expired') or now.timestamp() > p[msg.target.sender_id]['expired']:
p[msg.target.sender_id] = {'time': now.timestamp(),
'expired': expired.timestamp(),
'amount': amount
}
p = [p]
msg.info.modify_petal(amount)
update_stored_list(msg.target.client_name, 'gainedpetal', p)
return msg.locale.t('petal.message.gained.success', amount=amount)
else:
if limit > 0:
if p[msg.target.sender_id]['amount'] >= limit:
return msg.locale.t('petal.message.gained.limit')
elif p[msg.target.sender_id]['amount'] + amount > limit:
amount = limit - p[msg.target.sender_id]['amount']
p[msg.target.sender_id]['amount'] += amount
p = [p]
msg.info.modify_petal(amount)
update_stored_list(msg.target.client_name, 'gainedpetal', p)
return msg.locale.t('petal.message.gained.success', amount=amount)


async def lost_petal(msg: Bot.MessageSession, amount: int):
'''减少花瓣。
:param msg: 消息会话。
:param amount: 减少的花瓣数量。
:returns: 减少花瓣的提示消息。
'''
if Config('enable_petal', False) and Config('enable_get_petal', False):
limit = Config('lost_petal_limit', 0)
amount = limit if amount > limit and limit > 0 else amount
p = get_stored_list(msg.target.client_name, 'lostpetal')
if not p:
p = [{}]
p = p[0]
now = datetime.now(timezone.utc) + msg.timezone_offset
expired = datetime.combine((now + timedelta(days=1)).date(), datetime.min.time())
if msg.target.sender_id not in p or not p[msg.target.sender_id].get(
'expired') or now.timestamp() > p[msg.target.sender_id]['expired']:
p[msg.target.sender_id] = {'time': now.timestamp(),
'expired': expired.timestamp(),
'amount': amount
}
p = [p]
msg.info.modify_petal(-amount)
update_stored_list(msg.target.client_name, 'lostpetal', p)
return msg.locale.t('petal.message.lost.success', amount=amount)
else:
if limit > 0:
if p[msg.target.sender_id]['amount'] >= limit:
return msg.locale.t('petal.message.lost.limit')
elif p[msg.target.sender_id]['amount'] + amount > limit:
amount = limit - p[msg.target.sender_id]['amount']
p[msg.target.sender_id]['amount'] += amount
p = [p]
msg.info.modify_petal(-amount)
update_stored_list(msg.target.client_name, 'lostpetal', p)
return msg.locale.t('petal.message.lost.success', amount=amount)


async def cost_petal(msg: Bot.MessageSession, amount: int) -> bool:
'''花费花瓣。
:param msg: 消息会话。
:param amount: 花费的花瓣数量。
:returns: 是否成功处理。
'''
if Config('enable_petal', False):
if amount > msg.petal:
await msg.send_message(msg.locale.t('petal.message.cost.not_enough'))
return False
else:
msg.info.modify_petal(-amount)
return True
else:
return True
Loading

0 comments on commit 9ddf660

Please sign in to comment.