Skip to content

Commit

Permalink
🐳 chore: 不再强制要求 nbtlib
Browse files Browse the repository at this point in the history
仅在 NBT 模式下要求 nbtlib 前置
  • Loading branch information
alex3236 committed Oct 1, 2022
1 parent 274856b commit b6b677f
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 6 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/pack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Dev packages

on:
push:
pull_request:

jobs:
pack:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
working-directory: ./src
run: |
python -m pip install --upgrade pip
python -m pip install mcdreforged
[[ -f requirements.txt ]] && pip install -r requirements.txt
- name: Pack the plugin
run: python -m mcdreforged pack -i src -o dist
- uses: actions/upload-artifact@v2
with:
name: pack-artifacts
path: dist/
65 changes: 65 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Release

on:
release:
types:
- published
workflow_dispatch:
inputs:
target_release_tag:
description: The tag of the release you want to append the artifact to
required: true

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9

- uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
working-directory: ./src
run: |
python -m pip install --upgrade pip
python -m pip install mcdreforged
[[ -f requirements.txt ]] && pip install -r requirements.txt
- name: Pack plugin
run: python -m mcdreforged pack -o dist

- name: Find tag name
id: release_info
run: |
if [ $GITHUB_EVENT_NAME == 'release' ]
then
echo "::set-output name=tag_name::" # leave an empty value here so softprops/action-gh-release will use the default value
elif [ $GITHUB_EVENT_NAME == 'workflow_dispatch' ]
then
echo "::set-output name=tag_name::${{ github.event.inputs.target_release_tag }}"
else
echo Unknown github event name $GITHUB_EVENT_NAME
exit 1
fi
- name: Find packed plugin
id: findplugin
run: |
output="$(ls dist)"
echo "::set-output name=pluginname::$output"
- name: Upload to Github Release
uses: softprops/action-gh-release@v1
with:
files: dist/${{ steps.findplugin.outputs.pluginname }}
tag_name: ${{ steps.release_info.outputs.tag_name }}
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ MCDR插件,获取和输出服务器开服时间。

```python
mcdreforged>=2.2.0
nbtlib>=2.0.0
```

## 📝 使用说明
Expand All @@ -25,7 +24,13 @@ nbtlib>=2.0.0
如你所见,在输出字符串中,请用 `{day}` 代表开服天数,使用 `{{``}}` 来描述单个 `{``}`
### 📡 NBT 模式

daycount-NBT 默认即 NBT 模式,且一般无需进行任何配置,到手即用。
使用 NBT 模式需要额外安装以下前置模块:

```python
nbtlib>=2.0.0
```

daycount-NBT 默认即 NBT 模式,一般无需进行任何配置,到手即用。

如果您服务器的 `level.dat` 并非位于 `server/world/level.dat`,则需配置文件中的 `nbt_file`

Expand Down
8 changes: 6 additions & 2 deletions src/daycount_nbt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
from datetime import datetime
from traceback import print_exc
from typing import List
import nbtlib
import importlib

nbtlib = None

class Configure(Serializable):
commands: List[str] = ['!!day', '!!days']
Expand All @@ -21,10 +22,13 @@ def getday() -> int:
Returns:
`int`: Integer number of days, or `-1` if an error occurs
"""
global nbtlib
try:
if config.nbt_mode:
if nbtlib == None:
nbtlib = importlib.import_module("nbtlib")
return int(nbtlib.load(config.nbt_file)['Data']['Time'] / 1728000)
return (datetime.now() - datetime.strptime(config.start_date, '%Y-%m-%d')).days
return (datetime.now() - datetime.strptime(config.start_date, r'%Y-%m-%d')).days
except:
print_exc()
return -1
Expand Down
2 changes: 1 addition & 1 deletion src/mcdreforged.plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "daycount_nbt",
"version": "2.2.0",
"version": "2.2.1",
"name": "DayCount NBT",
"description": {
"en_us": ":calendar: Get and export server opening times.",
Expand Down
1 change: 0 additions & 1 deletion src/requirements.txt

This file was deleted.

0 comments on commit b6b677f

Please sign in to comment.