Skip to content

Commit

Permalink
✨ 添加 Rule 判断有无配置
Browse files Browse the repository at this point in the history
  • Loading branch information
KomoriDev committed Jul 29, 2024
1 parent a74ee8d commit 3242d88
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
19 changes: 17 additions & 2 deletions nonebot_plugin_wakatime/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from urllib.parse import parse_qs

from nonebot import require
from nonebot.rule import Rule
from nonebot.log import logger
from httpx import ConnectTimeout
from sqlalchemy.exc import InterfaceError
Expand All @@ -18,9 +19,10 @@
from .apis import API
from . import migrations
from .models import User
from .config import Config
from .shema import WakaTime
from .render_pic import render
from .config import Config, config
from .config import config as wakatime_config

__plugin_meta__ = PluginMetadata(
name="谁是卷王",
Expand All @@ -37,13 +39,26 @@
},
)

if wakatime_config.client_id == "" or wakatime_config.client_secret == "":
logger.warning("未配置 client_id 或 client_secret")


def is_enable() -> Rule:

def _rule() -> bool:
return wakatime_config.client_id != "" and wakatime_config.client_secret != ""

return Rule(_rule)


wakatime = on_alconna(
Alconna(
"wakatime",
Args["target?", At | int],
Option("-b|--bind|bind", Args["code?", str], help_text="绑定 wakatime"),
),
aliases={"waka"},
rule=is_enable(),
use_cmd_start=True,
)

Expand Down Expand Up @@ -101,7 +116,7 @@ async def _(

if not code.available:
auth_url = (
f"https://wakatime.com/oauth/authorize?client_id={config.client_id}&response_type=code"
f"https://wakatime.com/oauth/authorize?client_id={wakatime_config.client_id}&response_type=code"
f"&redirect_uri=https://wakatime.com/dashboard"
)

Expand Down
4 changes: 2 additions & 2 deletions nonebot_plugin_wakatime/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

class ScopedConfig(BaseModel):

client_id: str
client_id: str = ""
"""Your App ID from https://wakatime.com/apps"""
client_secret: str
client_secret: str = ""
"""Your App Secret from https://wakatime.com/apps"""
api_url: str = "https://wakatime.com/api/v1"
"""wakatime api"""
Expand Down

0 comments on commit 3242d88

Please sign in to comment.