update
This commit is contained in:
parent
9ed0ea5946
commit
3b2ff2b5e6
5 changed files with 50 additions and 4 deletions
|
@ -1,5 +1,6 @@
|
|||
import asyncio
|
||||
from datetime import datetime
|
||||
from config import Config
|
||||
from datetime import datetime, timedelta
|
||||
from typing import List
|
||||
|
||||
from core.builtins.message.chain import *
|
||||
|
@ -10,6 +11,7 @@ from core.builtins.utils import confirm_command
|
|||
from core.exceptions import WaitCancelException
|
||||
from core.types.message import MessageSession as MessageSessionT, MsgInfo, Session
|
||||
from core.utils.i18n import Locale
|
||||
from core.utils.text import parse_time_string
|
||||
from database import BotDBUtil
|
||||
|
||||
|
||||
|
@ -29,6 +31,8 @@ class MessageSession(MessageSessionT):
|
|||
self.locale = Locale(self.data.locale)
|
||||
self.timestamp = datetime.now()
|
||||
self.tmp = {}
|
||||
self.timezone_offset = parse_time_string(self.options.get(
|
||||
'timezone_offset', Config('timezone_offset', '+08:00')))
|
||||
|
||||
async def wait_confirm(self, message_chain=None, quote=True, delete=True, append_instruction=True) -> bool:
|
||||
send = None
|
||||
|
|
|
@ -67,7 +67,7 @@ class MessageSession:
|
|||
"""
|
||||
__slots__ = (
|
||||
"target", "session", "trigger_msg", "parsed_msg", "matched_msg", "sent", "prefixes", "options",
|
||||
"enabled_modules", "muted", "custom_admins", "data", "locale", "timestamp", "tmp")
|
||||
"enabled_modules", "muted", "custom_admins", "data", "locale", "timestamp", "tmp", "timezone")
|
||||
|
||||
parsed_msg: Dict[str, Union[str, list]]
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import sys
|
||||
import datetime
|
||||
from typing import TypeVar
|
||||
|
||||
T = TypeVar("T", str, bytes, bytearray)
|
||||
|
@ -15,3 +16,17 @@ else:
|
|||
|
||||
def remove_prefix(string: T, prefix: T) -> T:
|
||||
return string[len(prefix):] if string.startswith(prefix) else string
|
||||
|
||||
|
||||
def parse_time_string(time_str):
|
||||
try:
|
||||
negative = False
|
||||
if time_str[0] == '+':
|
||||
time_str = time_str[1:]
|
||||
elif time_str[0] == '-':
|
||||
negative = True
|
||||
time_str = time_str[1:]
|
||||
hour, minute = map(int, time_str.split(':'))
|
||||
return datetime.timedelta(hours=hour if not negative else -hour, minutes=minute if not negative else -minute)
|
||||
except ValueError:
|
||||
return datetime.timedelta()
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import platform
|
||||
import time
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import datetime, timedelta, tzinfo
|
||||
|
||||
import jwt
|
||||
import psutil
|
||||
|
@ -201,6 +201,23 @@ async def _(msg: Bot.MessageSession):
|
|||
await msg.finish(msg.locale.t('core.message.toggle.check.disable'))
|
||||
|
||||
|
||||
@tog.command('timeoffset <offset>')
|
||||
async def _(msg: Bot.MessageSession):
|
||||
offset = msg.parsed_msg['<offset>']
|
||||
try:
|
||||
if offset[0] == '+':
|
||||
offset = offset[1:]
|
||||
elif offset[0] == '-':
|
||||
offset = offset[1:]
|
||||
hour, minute = map(int, offset.split(':'))
|
||||
if hour > 12 or minute > 60:
|
||||
raise ValueError
|
||||
except ValueError:
|
||||
await msg.finish(msg.locale.t('core.message.toggle.timeoffset.invalid'))
|
||||
msg.data.edit_option('timezone_offset', offset)
|
||||
await msg.finish(msg.locale.t('core.message.toggle.timeoffset.success', offset=offset))
|
||||
|
||||
|
||||
mute = module('mute', developers=['Dianliang233'], base=True, required_admin=True,
|
||||
desc='{core.help.mute}')
|
||||
|
||||
|
|
|
@ -12,6 +12,16 @@ from core.utils.ip import IP
|
|||
async def mcv(msg):
|
||||
try:
|
||||
data = json.loads(await get_url('https://piston-meta.mojang.com/mc/game/version_manifest.json', 200))
|
||||
release = data['latest']['release']
|
||||
snapshot = data['latest']['snapshot']
|
||||
time_release = None
|
||||
time_snapshot = None
|
||||
for v in data['versions']:
|
||||
if v['id'] == release:
|
||||
time_release = v['releaseTime']
|
||||
elif v['id'] == snapshot:
|
||||
time_snapshot = v['releaseTime']
|
||||
|
||||
message1 = msg.locale.t(
|
||||
"mcv.message.mcv.launcher",
|
||||
release=data['latest']['release'],
|
||||
|
|
Reference in a new issue