PagerMaid_Plugins_Pyro/autochangename/main.py

67 lines
1.7 KiB
Python
Raw Permalink Normal View History

""" Module to automate message deletion. """
import traceback
from datetime import datetime, timedelta, timezone
2024-09-28 14:35:08 +00:00
from pagermaid.dependence import scheduler
from pagermaid.services import bot
from pagermaid.utils import pip_install, logs
pip_install("emoji")
from emoji import emojize
auto_change_name_init = False
2023-07-01 12:18:58 +00:00
dizzy = emojize(":dizzy:", language="alias")
cake = emojize(":cake:", language="alias")
all_time_emoji_name = [
"clock12",
"clock1230",
"clock1",
"clock130",
"clock2",
"clock230",
"clock3",
"clock330",
"clock4",
"clock430",
"clock5",
"clock530",
"clock6",
"clock630",
"clock7",
"clock730",
"clock8",
"clock830",
"clock9",
"clock930",
"clock10",
"clock1030",
"clock11",
"clock1130",
]
2023-07-01 12:18:58 +00:00
time_emoji_symb = [emojize(f":{s}:", language="alias") for s in all_time_emoji_name]
@scheduler.scheduled_job("cron", second=0, id="autochangename")
async def change_name_auto():
try:
2023-07-01 12:18:58 +00:00
time_cur = (
datetime.utcnow()
.replace(tzinfo=timezone.utc)
.astimezone(timezone(timedelta(hours=8)))
.strftime("%H:%M:%S:%p:%a")
)
hour, minu, seco, p, abbwn = time_cur.split(":")
shift = 1 if int(minu) > 30 else 0
hsym = time_emoji_symb[(int(hour) % 12) * 2 + shift]
_last_name = f"{hour}:{minu} {p} UTC+8 {hsym}"
await bot.update_profile(last_name=_last_name)
me = await bot.get_me()
if me.last_name != _last_name:
raise Exception("修改 last_name 失败")
except Exception as e:
trac = "\n".join(traceback.format_exception(e))
await logs.info(f"更新失败! \n{trac}")