1
0
Fork 0
mirror of https://github.com/myned/watcher.git synced 2024-11-01 12:22:38 +00:00
watcher/README.md

130 lines
3.7 KiB
Markdown
Raw Permalink Normal View History

2022-06-07 21:22:48 +00:00
# Watcher
2022-06-09 01:59:15 +00:00
An experimental [Hikari](https://www.hikari-py.dev) Discord bot for assigning active and inactive roles based on member activity
## Prerequisites
2023-03-07 03:45:09 +00:00
Linux is used for the following commands\
2022-06-09 01:59:15 +00:00
[WSL](https://docs.microsoft.com/en-us/windows/wsl) can be used to run Linux on Windows, but is not required to run the bot
## Requirements
[Git](https://git-scm.com/downloads)\
[Python](https://www.python.org) 3.10+\
[Poetry](https://python-poetry.org/docs/master)
## Installing
2023-03-07 03:45:09 +00:00
1. Clone repository
2022-06-09 01:59:15 +00:00
```
2023-03-17 06:16:20 +00:00
git clone https://github.com/Myned/watcher.git
2022-06-09 01:59:15 +00:00
```
2023-03-07 03:45:09 +00:00
2. Go to project folder
2022-06-09 01:59:15 +00:00
```
2023-03-17 06:16:20 +00:00
cd watcher
2022-06-09 01:59:15 +00:00
```
2023-03-07 03:45:09 +00:00
3. Create a virtual environment and install dependencies
2022-06-09 01:59:15 +00:00
```
poetry install
```
## Usage
2023-03-07 03:45:09 +00:00
1. Go to project folder
2022-06-09 01:59:15 +00:00
```
2023-03-17 06:16:20 +00:00
cd watcher
2022-06-09 01:59:15 +00:00
```
2023-03-07 03:45:09 +00:00
2. Run with optimizations
2022-06-09 01:59:15 +00:00
```
poetry run python -OO run.py
```
## Setup
2023-03-16 08:06:39 +00:00
### Starting
2022-06-09 01:59:15 +00:00
Run to create `config.toml`\
The file will automatically generate if it does not exist
```
client = 0 # bot application id
token = "" # bot token
activity = "you" # bot status
db = "watcher.db" # sqlite3 db filepath
guild = 0 # guild id to watch
active = 0 # active role id
inactive = 0 # inactive role id
duration = 0 # time in seconds before considered inactive
```
2023-03-16 08:06:39 +00:00
### Inviting
1. Setup a bot application at Discord's [developer portal](https://discord.com/developers/applications)
2. Under General Information, paste `APPLICATION ID` into `config.toml` > `client`
3. Under Bot, click `Add Bot`
4. Under Bot, enable `SERVER MEMBERS INTENT` (necessary for limbo command)
5. Under Bot, paste `TOKEN` into `config.toml` > `token`
2023-03-23 10:50:28 +00:00
6. Under OAuth2 > URL Generator, check `SCOPES` > `bot` and `BOT PERMISSIONS` > `Manage Roles` and `Read Messages/View Channels`
2023-03-16 08:06:39 +00:00
7. Paste generated URL into a browser to invite the bot
2023-03-07 03:45:09 +00:00
### systemd service
Run in the background on most Linux machines\
2023-03-17 06:16:20 +00:00
This assumes that the project folder is located at `~/.git/watcher`\
2023-03-07 03:45:09 +00:00
Change the `WorkingDirectory` path in `watcher.service` if this is not the case
1. Go to project folder
```
2023-03-17 06:16:20 +00:00
cd watcher
2023-03-07 03:45:09 +00:00
```
2. Copy user service file
```
cp watcher.service ~/.config/systemd/user
```
3. Replace `user` in `WorkingDirectory` with current user
```
sed -i "s|\(WorkingDirectory=/home/\)user|\1$(whoami)|" ~/.config/systemd/user/watcher.service
```
4. Reload user daemon
2023-03-07 03:45:09 +00:00
```
systemctl --user daemon-reload
```
5. Start and enable service on login
2023-03-07 03:45:09 +00:00
```
systemctl --user enable --now watcher
```
6. Enable lingering to start user services on boot
2023-03-07 03:45:09 +00:00
```
2023-03-23 09:56:38 +00:00
sudo loginctl enable-linger $(whoami)
2023-03-07 03:45:09 +00:00
```
2022-06-09 01:59:15 +00:00
## Updating
2023-03-07 03:45:09 +00:00
1. Go to project folder
2022-06-09 01:59:15 +00:00
```
2023-03-17 06:16:20 +00:00
cd watcher
2022-06-09 01:59:15 +00:00
```
2023-03-07 03:45:09 +00:00
2. Pull changes from repository
2022-06-09 01:59:15 +00:00
```
git pull
```
2023-03-07 03:45:09 +00:00
3. Update virtual environment
2022-06-09 01:59:15 +00:00
```
poetry update
```
2023-03-07 04:00:40 +00:00
4. Restart systemd user service
```
systemctl --user restart watcher
```
2022-06-09 01:59:15 +00:00
## Uninstalling
2023-03-07 03:45:09 +00:00
1. Stop and disable systemd user service
```
systemctl --user disable --now watcher
```
2. Remove systemd user service file
```
rm ~/.config/systemd/user/watcher.service
```
3. Optionally disable lingering
```
sudo loginctl disable-linger username
```
4. Remove project folder
2022-06-09 01:59:15 +00:00
```
2023-03-17 06:16:20 +00:00
rm -rf watcher
2022-06-09 01:59:15 +00:00
```
## Contributing
1. [Fork](https://docs.github.com/en/get-started/quickstart/fork-a-repo) this repository on GitHub
2. Make changes to the code
3. Format the code with [Black](https://black.readthedocs.io/en/stable) inside the project folder
```
2023-03-16 21:54:59 +00:00
poetry run black .
2022-06-09 01:59:15 +00:00
```
4. [Commit](https://github.com/git-guides/git-commit) the changes to the fork
5. Create a [pull request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request) from the fork
## Credits
[hikari](https://github.com/hikari-py/hikari)\
2022-07-05 22:23:20 +00:00
[hikari-lightbulb](https://github.com/tandemdude/hikari-lightbulb)\
2022-07-05 22:22:03 +00:00
[hikari-miru](https://github.com/HyperGH/hikari-miru)