summaryrefslogtreecommitdiff
path: root/ATRI/plugins/funny.py
blob: 39a691d43a77955953ec60022cc7b26f6058ed9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
'''
File: funny.py
Created Date: 2021-02-04 21:17:21
Author: Kyomotoi
Email: [email protected]
License: GPLv3
Project: https://github.com/Kyomotoi/ATRI
--------
Last Modified: Sunday, 7th March 2021 3:13:19 pm
Modified By: Kyomotoi ([email protected])
--------
Copyright (c) 2021 Kyomotoi
'''

from pathlib import Path
from random import choice, randint

from nonebot.adapters.cqhttp import Bot, MessageEvent
from nonebot.plugin import on_command, on_message

from ATRI.rule import (
    is_in_banlist,
    is_in_dormant,
    is_in_service
)


__plugin_name__ = "laugh"

get_laugh = on_command(
    "来句笑话",
    rule=is_in_banlist() & is_in_dormant()
    & is_in_service(__plugin_name__)
)

@get_laugh.handle()
async def _get_laugh(bot: Bot, event: MessageEvent) -> None:
    user_name = event.sender.nickname
    laugh_list = []
    
    FILE = Path('.') / 'ATRI' / 'data' / 'database' / 'funny' / 'laugh.txt'
    with open(FILE, 'r', encoding='utf-8') as r:
        for line in r:
            laugh_list.append(line.strip('\n'))
    
    result = choice(laugh_list)
    await get_laugh.finish(result.replace("%name", user_name))


__plugin_name__ = "wty"

me_to_you = on_message(
    rule=is_in_banlist() & is_in_dormant() & is_in_service(__plugin_name__)
)

@me_to_you.handle()
async def _me_to_you(bot: Bot, event: MessageEvent) -> None:
    if randint(0, 5) == 5:
        msg = str(event.message)
        if "我" in msg and "CQ" not in msg:
            await me_to_you.finish(msg.replace("我", "你"))