Skip to content

Commit a2b2cd1

Browse files
committed
Initial commit: Article Command Plugin v1.0.0
0 parents  commit a2b2cd1

9 files changed

Lines changed: 1307 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Update Official Plugins List
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
update-list:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout official-plugins-list repository
12+
uses: actions/checkout@v3
13+
with:
14+
repository: blockmineJS/official-plugins-list
15+
token: ${{ secrets.PAT }}
16+
17+
- name: Update plugin version
18+
run: |
19+
PLUGIN_ID="${{ github.repository }}"
20+
PLUGIN_ID=${PLUGIN_ID#*/}
21+
22+
NEW_TAG="${{ github.event.release.tag_name }}"
23+
24+
sudo apt-get install -y jq
25+
26+
jq --arg id "$PLUGIN_ID" --arg tag "$NEW_TAG" '(.[] | select(.id == $id) | .latestTag) |= $tag' index.json > tmp.json && mv tmp.json index.json
27+
28+
echo "Updated $PLUGIN_ID to version $NEW_TAG"
29+
30+
- name: Commit and push changes
31+
run: |
32+
git config --global user.name 'github-actions[bot]'
33+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
34+
git add index.json
35+
if git diff --staged --quiet; then
36+
echo "No changes to commit."
37+
else
38+
git commit -m "Update ${{ github.repository }} to version ${{ github.event.release.tag_name }}"
39+
git push
40+
fi

.gitignore

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Dependencies
2+
node_modules/
3+
npm-debug.log*
4+
yarn-debug.log*
5+
yarn-error.log*
6+
7+
# Runtime data
8+
pids
9+
*.pid
10+
*.seed
11+
*.pid.lock
12+
13+
# Coverage directory used by tools like istanbul
14+
coverage/
15+
16+
# nyc test coverage
17+
.nyc_output
18+
19+
# Grunt intermediate storage
20+
.grunt
21+
22+
# Bower dependency directory
23+
bower_components
24+
25+
# node-waf configuration
26+
.lock-wscript
27+
28+
# Compiled binary addons
29+
build/Release
30+
31+
# Dependency directories
32+
jspm_packages/
33+
34+
# Optional npm cache directory
35+
.npm
36+
37+
# Optional REPL history
38+
.node_repl_history
39+
40+
# Output of 'npm pack'
41+
*.tgz
42+
43+
# Yarn Integrity file
44+
.yarn-integrity
45+
46+
# dotenv environment variables file
47+
.env
48+
49+
# IDE files
50+
.vscode/
51+
.idea/
52+
*.swp
53+
*.swo
54+
55+
# OS generated files
56+
.DS_Store
57+
.DS_Store?
58+
._*
59+
.Spotlight-V100
60+
.Trashes
61+
ehthumbs.db
62+
Thumbs.db

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## Описание
2+
3+
Этот плагин добавляет команду, которая позволяет игрокам получать случайную статью Уголовного Кодекса РФ. Каждый игрок может использовать команду только один раз в день, получая уникальную статью.
4+
5+
## Функциональность
6+
7+
- Команда `/article` для получения случайной статьи УК РФ
8+
- Ограничение: один раз в день на игрока
9+
- Настраиваемые сообщения для первого использования и повторного использования
10+
- Автоматическое сохранение данных о выданных статьях
11+
12+
## Настройки
13+
14+
### Сообщения
15+
16+
- **firstTimeMessage** - сообщение при первом использовании за день
17+
- **repeatMessage** - сообщение при повторном использовании
18+
19+
### Плейсхолдеры
20+
21+
- `{user}` - имя пользователя
22+
- `{articleNumber}` - номер статьи
23+
- `{articleTitle}` - название статьи

commands/ArticleCommand.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const { PLUGIN_OWNER_ID, PERMISSION_NAME } = require('../constants');
2+
3+
module.exports = (Command, articleManager, settings) => {
4+
5+
const format = (template, values) => {
6+
return Object.entries(values).reduce(
7+
(acc, [key, value]) => acc.replace(new RegExp(`{${key}}`, 'g'), value),
8+
template
9+
);
10+
};
11+
12+
return class ArticleCommand extends Command {
13+
constructor() {
14+
super({
15+
name: "статья",
16+
description: "Назначает случайную статью на день.",
17+
permissions: PERMISSION_NAME,
18+
owner: PLUGIN_OWNER_ID,
19+
cooldown: 10,
20+
allowedChatTypes: ["clan", "chat"],
21+
});
22+
}
23+
24+
async handler(bot, typeChat, user) {
25+
const result = await articleManager.getTodaysArticle(user.username);
26+
27+
if (!result.article) {
28+
bot.api.sendMessage(typeChat, "&cСписок статей пуст. Обратитесь к администратору.", user.username);
29+
return;
30+
}
31+
32+
const messageTemplate = result.isNew ? settings.firstTimeMessage : settings.repeatMessage;
33+
34+
const message = format(messageTemplate, {
35+
user: user.username,
36+
articleNumber: result.article.number,
37+
articleTitle: result.article.title
38+
});
39+
40+
bot.api.sendMessage(typeChat, message, user.username);
41+
}
42+
}
43+
};

0 commit comments

Comments
 (0)