YUI is Multi-purpose Slack Bot.
- item4(owner)'s private slack
- 9xd
- xnuk fan club
- Git
- Slack bot permission for bot account
- Python 3.7 or higher
- Pipenv
$ git clone https://github.com/item4/yui.git
$ cd yui
$ mkdir log
$ pipenv install
Yui must require ~~~.config.toml
file for run. You must make config file before run.
Config key and value is below.
- TOKEN
string. Slack App Toekn
- PREFIX
string. Prefix for command. for example, if you set PREFIX to '=' and you want to run help command, you must type
=help
- RECEIVE_TIMEOUT
integer. timeout seconds for receiving data from Slask WebSocket. default is
300
(5min)- HANDLERS
list of str. Python module path of handlers. Yui import given paths automatically. You must use core handlers.
HANDLERS = [ 'yui.handlers.core' ]
- MODELS
list of str. Python module path of ORM Models. Yui import given path automatically. You can define ORM Model with SQLAlchemy (see this and use
yui.orm.Base
)Warning
Yui DO NOT make table automatically. You must need to run
yui migrate
to make migration andyui upgrade
to make tables.- CHANNELS
dictionary of str. Channel names used in code. it used for support same handler code with different server envrionment.
For example,
[CHANNELS] general = '_general' do_not_use_gif = ['dev', '_notice']
This config setting make you use yui.command.C and yui.command.Cs like this.
@box.comamnd('only-general', channel=only(C.general)) async def only_general(): # this will run only 'general' @box.command('gif', channel=not_(Cs.do_not_use_gif)) async def gif(): # this will not run at 'do_not_use_gif'
For using yui without change codes, You must set these channel keys like it.
[CHANNELS] general = '_general' game = 'game' game_and_test = ['game', 'test'] welcome = '_general'
- DATABASE_URL
string. URL to connect Database via SQLAlchemy.
- DATABASE_ECHO
bool. If you set it to true, you can see raw SQL in log
- OWNER
string. ID of owner. You can get ID value from this test page
- NAVER_CLIENT_ID
string. ID for using Naver API. Yui use it for searching book. You might visit Naver developer page
- NAVER_CLIENT_SECRET
string. SECRET Key for using Naver API. Do not upload this value on VCS.
- GOOGLE_API_TOKEN
string. API Token for using Google map API. You can generate this value on Google API Console and this activation page Do not upload this value on VCS.
- AQI_API_TOKEN
string. API Token for using AQI API. You can get this value on this request form Do not upload this value on VCS.
- DNF_API_KEY
string. API Key for using Neople API. Do not upload this value on VCS.
- WEBSOCKETDEBUGGERURL
string. URL of Chrome websocket debugger. This is using for access webpage via headless Chrome for bypass anti-DDoS tool such as CloudFlare.
WEBSOCKETDEBUGGERURL = 'http://localhost:9222/json/version'
You can launch headless chrome by this command.
docker run --rm --name headless-chrome -d -p 9222:9222 --cap-add=SYS_ADMIN yukinying/chrome-headless-browser
- LOGGING
complex dict. Python logging config. You can use default setting. But if you want to change some value, you can override below example.
[LOGGING] version = 1 disable_existing_loggers = false [LOGGING.formatters.brief] format = '%(message)s' [LOGGING.formatters.default] format = '%(asctime)s %(levelname)s %(name)s %(message)s' datefmt = '%Y-%m-%d %H:%M:%S' [LOGGING.handlers.console] class = 'logging.StreamHandler' formatter = 'brief' level = 'DEBUG' filters = [] stream = 'ext://sys.stdout' [LOGGING.handlers.file] class = 'logging.handlers.RotatingFileHandler' formatter = 'default' level = 'WARNING' filename = 'log/warning.log' maxBytes = 102400 backupCount = 3 [LOGGING.loggers.yui] handlers = ['console', 'file'] propagate = true level = 'DEBUG'
$ pipenv run yui run -c yui.config.toml
Yui CLI support most of command of Alembic. You can use command with yui
such as pipenv run yui revision --autogenerate -m "Test"
.
List of commands are below.
init_db
revision
migrate
(same asrevision
with--autogenerate
edit
merge
upgrade
downgrade
show
history
heads
branches
current
stamp
You can launch yui on docker-compose easily.
- Install Docker-compose.
Craete
docker-compose.yml
file.version: '3' services: bot_item4: image: item4/yui:latest volumes: - .:/yui/data environment: - YUI_CONFIG_FILE_PATH=data/yui.config.toml depends_on: - db links: - db command: ./data/run.sh db: image: postgres:alpine volumes: - ./postgres/data:/var/lib/postgresql/data environment: - POSTGRES_PASSWORD=MYSECRET healthcheck: test: "pg_isready -h localhost -p 5432 -q -U postgres" interval: 3s timeout: 1s retries: 10
Pull images
$ docker pull item4/yui $ docker pull postgres:alpine
Launch db container and create database
$ docker-compose up -d db $ docker ps # and see container name $ docker exec -it <CONTAINER_NAME_HERE> psql -U postgres # and typing create database dbname; for create db
- Create config file with db info
Launch Yui
$ docker-compose up -d
You can see example files on example
directory at this repo.
YUI must keep PEP-8 and some rules. So you must install lint deps by pipenv install --dev
and install pre-commit hook by below commands.
$ mkdir -p .git/hooks/
$ ln -s $(pwd)/hooks/pre-commit .git/hooks
AGPLv3 or higher