Compare commits

...

6 Commits

Author SHA1 Message Date
trueold89 6977bd58a0
Update README.md 2024-06-03 21:39:53 +03:00
trueold89 7b130b4bc7
Init Dockerfile and docker-compose.yml 2024-06-03 21:39:24 +03:00
trueold89 f26f8cdd9a
Buffix in ENV class
- CIRCLES_COUNT now returns int
2024-06-03 20:57:29 +03:00
trueold89 015d939bd5
Init setup.py 2024-06-03 19:10:34 +03:00
trueold89 9d10ffc70f
Update bot.py
- Add new intents
- Add new function 'on_ready'
2024-06-03 19:02:19 +03:00
trueold89 b07af72901
Update ENV class
- Add CLIENT_ID property
2024-06-03 19:01:44 +03:00
6 changed files with 216 additions and 3 deletions

154
README.md
View File

@ -1,3 +1,155 @@
# HellMBot # HellMBot
Discord bot that will wake your friends up from full mute by putting them through 9 circles of hell ### Discord bot that will wake your friends up from full mute by putting them through 9 circles of hell
![](https://cdn.orudo.ru/.work/trueold89/git/hellm/Header.png)
## Source code:
[<img src="https://cdn.orudo.ru/.work/trueold89/git/hellm/orudo.svg" alt="SVG Image" width="300" height="102" style="padding-right: 10px">](https://git.orudo.ru/trueold89/HellMBot)
[<img src="https://cdn.orudo.ru/.work/trueold89/git/hellm/github.svg" alt="SVG Image" width="300" height="102" style="padding-right: 10px">](https://github.com/Trueold89/HellMBot)
***
![](https://cdn.orudo.ru/.work/trueold89/git/hellm/example.gif)
***
## Usage:
![](https://cdn.orudo.ru/.work/trueold89/git/hellm/faq.png)
---
- **Add bot to your server**
- **Update the bot's permissions to prevent unnecessary people from using its commands (optional)**
- **Type /create in any text chat you want**
- **Write `/create` in whatever text chat you want**
- **Move any user (or yourself, if you're a masochist) to any of the channels in the group created by bot**
- **Have fun!**
## Deploy:
***
### Python venv:
![](https://cdn.orudo.ru/.work/trueold89/git/hellm/python.png)
- **Install python package from [git.orudo.ru](https://git.orudo.ru/trueold89/HellMBot/packages)**:
```shell
pip install pip install --extra-index-url https://git.orudo.ru/api/packages/trueold89/pypi/simple/ HellMBot
```
- **Or build your own package from sources**:
*Clone source code repo:*
```shell
git clone https://git.orudo.ru/trueold89/HellMBot.git && cd HellMBot
```
*Install build deps:*
```shell
pip install setuptools
```
*Build package:*
```shell
python3 setup.py sdist
```
*Install built package:*
```shell
pip install dist/*
```
---
- **Set [system environment variables](#available-system-environment-variables): (Linux bash example)**
```bash
export BOT_TOKEN=insertyourbottokenhere
```
```bash
export CLIENT_ID=insertyourclientidhere
```
---
- **Start bot:**
```shell
heelm
```
***
### Docker:
![](https://cdn.orudo.ru/.work/trueold89/git/hellm/docker.png)
- **Pull image from [git.orudo.ru](https://git.orudo.ru/trueold89/HellMBot/packages)**:
```shell
docker pull git.orudo.ru/trueold89/hellmbot:latest
```
- **Or build your own image:**
*Clone source code repo:*
```shell
git clone https://git.orudo.ru/trueold89/HellMBot.git && cd HellMBot/docker
```
*Edit the Dockerfile with your changes (Optional)*
*Build image:*
```shell
docker build -t hellmbot .
```
---
- **Create docker volume that will use to store DataBase:**
```shell
docker volume create hellm_db
```
---
- **Deploy using docker-cli:**
```shell
docker run \
--name HellMBot\
--restart=unless-stopped \
-v hellm_db:/etc/hellmbot/
-e BOT_TOKEN="insertyourbottokenhere" \
-e CLIENT_ID="insertyourclientidhere" \
-d git.orudo.ru/trueold89/hellmbot:latest
```
- **Or using docker-compose:**
```yml
services:
qbitdl_bot:
image: git.orudo.ru/trueold89/hellmbot:latest
container_name: HellMBot
volumes:
- hellm_db:/etc/hellmbot
restart: 'unless-stopped'
environment:
BOT_TOKEN: "insertyourbottokenhere"
CLIENT_ID: "insertyourclientidhere"
```
```shell
docker compose up -d
```
***
## Available system environment variables
***
- `BOT_TOKEN` - **Discord Bot TOKEN** *[(How to get)](https://discordjs.guide/preparations/setting-up-a-bot-application.html#creating-your-bot)*
- `CLIENT_ID` - **Discord Application ID** *[(How to get)](https://docs.discordadvertising.com/getting-your-application-id)*
- `DB_PATH` - **Path to SQLite DataBase file** *(Optional | Highly recommended to change when running bot on Windows systems) (Default Value: "/etc/hellmbot/database.sqlite")*
- `CIRCLES_COUNT` - **Number of channels the bot creates when the "/create" command is activated.** *(Optional)* *(Default value: 9)*

6
docker/Dockerfile Normal file
View File

@ -0,0 +1,6 @@
FROM alpine:latest
RUN apk update && apk add python3 py3-pip
ENV DB_PATH="/etc/hellmbot/database.sqlite"
RUN pip install --extra-index-url https://git.orudo.ru/api/packages/trueold89/pypi/simple/ HellMBot --break-system-packages
WORKDIR /etc/hellmbot
ENTRYPOINT ["hellm"]

10
docker/docker-compose.yml Normal file
View File

@ -0,0 +1,10 @@
services:
qbitdl_bot:
image: git.orudo.ru/trueold89/hellmbot:latest
container_name: HellMBot
volumes:
- hellm_db:/etc/hellmbot
restart: 'unless-stopped'
environment:
BOT_TOKEN: "insertyourbottokenhere"
CLIENT_ID: "insertyourclientidhere"

View File

@ -2,7 +2,8 @@
from hellmbot.env import ENV from hellmbot.env import ENV
from hellmbot.db import ServersDB from hellmbot.db import ServersDB
from discord import Intents, Member, VoiceState from discord import Intents, Member, VoiceState, Permissions
from discord.utils import oauth_url
from discord.ext import commands from discord.ext import commands
@ -17,6 +18,7 @@ def init_bot() -> commands.Bot:
:return: Bot class object :return: Bot class object
""" """
intents = Intents.default() intents = Intents.default()
intents.members = True
intents.message_content = True intents.message_content = True
return commands.Bot(command_prefix="/", intents=intents) return commands.Bot(command_prefix="/", intents=intents)
@ -32,6 +34,19 @@ def start() -> None:
bot.run(ENV.BOT_TOKEN.fget(None)) bot.run(ENV.BOT_TOKEN.fget(None))
@bot.event
async def on_ready() -> None:
"""
Displays a link to add a bot to the server
"""
client_id = ENV.CLIENT_ID.fget(None)
invite = oauth_url(client_id, permissions=Permissions(
manage_channels=True,
move_members=True
))
print(f"Your bot invite link: {invite}")
@bot.command() @bot.command()
async def create(ctx: commands.Context) -> None: async def create(ctx: commands.Context) -> None:
""" """
@ -54,7 +69,7 @@ user_before_channels = {}
@bot.event @bot.event
async def on_voice_state_update(member: Member, before: VoiceState, after: VoiceState): async def on_voice_state_update(member: Member, before: VoiceState, after: VoiceState) -> None:
""" """
Moves the user through the group channels if the user has been connected to one of them Moves the user through the group channels if the user has been connected to one of them

View File

@ -45,4 +45,17 @@ class ENV(object):
env = environ.get("CIRCLES_COUNT") env = environ.get("CIRCLES_COUNT")
if env is None: if env is None:
env = 9 env = 9
return int(env)
@property
def CLIENT_ID(self) -> str:
"""
Gets the Discord Client ID from the system environment
:return: Discord Client ID
"""
env = environ.get("CLIENT_ID")
if env is None:
raise ValueError("client id is not set\nTry to install the system ENV CLIENT_ID\n(export "
"CLIENT_ID=insertyourclientidhere)")
return env return env

17
setup.py Normal file
View File

@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
from setuptools import setup
setup(
name="HellMBot",
version="0.1",
url="https://git.orudo.ru/trueold89/HellMBot",
author="trueold89",
author_email="trueold89@orudo.ru",
description="Discord bot that will wake your friends up from full mute by putting them through 9 circles of hell",
packages=["hellmbot"],
long_description=open("README.md").read(),
install_requires=["discord.py"],
entry_points={
"console_scripts": ["hellm = hellmbot.bot:main"]
}
)