nonebot 自定义签到插件

通过 time.localtime(time.time())实现每天更新排名

import time
import json
from nonebot import on_command, CommandSession
from nonebot import on_natural_language, NLPSession, IntentCommand

from nonebot import *


from jieba import posseg
# from .data_source import *



@on_command('qiandao', aliases=('签到','签个到'))

async def qd(session: CommandSession):
    time_tuple = time.localtime(time.time())
    last_time = f'{time_tuple[0]}年{time_tuple[1]}月{time_tuple[2]}日'

    path = r'date_check.txt'
    fi = open(path, 'r+', encoding='utf-8')
    data = fi.read()
    print(data)
    print(last_time)
    if data != last_time:
        fi.seek(0)
        fi.truncate()
        fi.write(str(last_time))
        _f = open(r'count.txt', 'r+', encoding='utf-8')
        _f.seek(0)
        _f.truncate()
        _f.write('0')

    _f = open(r'count.txt', 'r+', encoding='utf-8')
    cnt = _f.readline()
    cnt = int(cnt)
    cnt = cnt + 1
    # print(cnt)
    # cnt = cnt + 1
    _f.seek(0)
    _f.truncate()
    _f.write(str(cnt))
    _f.close()
    msg = '签到成功\n'+'今日签到排名:{}'.format(cnt)
    
    await session.send(msg,at_sender=True)

@on_natural_language(keywords = {'签到','签个到'}, only_to_me = False)
async def _(session: NLPSession):
    return IntentCommand(90.0, 'qiandao')
posted @ 2023-07-24 20:07  N0zoM1z0  阅读(22)  评论(0编辑  收藏  举报