forked from Teahouse-Studios/akari-bot
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from TopRealm/conflict
Resolve conflicts
- Loading branch information
Showing
35 changed files
with
158 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.