Skip to content

Commit

Permalink
Merge pull request #17 from SantioMC/santio/refactor/cleanup
Browse files Browse the repository at this point in the history
Santio/refactor/cleanup
  • Loading branch information
SantioMC authored Dec 11, 2024
2 parents d269d7f + 66149ee commit 73738d2
Show file tree
Hide file tree
Showing 66 changed files with 1,377 additions and 1,373 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
max_line_length = 120
tab_width = 4
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
TOKEN=
LOG_CHANNEL=
64 changes: 32 additions & 32 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
name: Docker
on:
push:
branches: [master]
tags: ['v*.*.*']
push:
branches: [ master ]
tags: [ 'v*.*.*' ]

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v2
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ bin/
### Bot Specific ###
*.env
!.env.example
*.db
*.db
data/
14 changes: 7 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
FROM gradle:7.6.3-jdk11-alpine
FROM gradle:8.11.1-jdk21 AS base
LABEL author="Santio"
WORKDIR /app

WORKDIR /build
FROM base AS build

COPY . .
RUN gradle shadowJar
RUN gradle shadowJar --no-daemon

FROM openjdk:17-jdk-slim
LABEL author="Santio"
FROM base AS runtime
COPY --from=build /app/build/libs/*.jar app.jar

WORKDIR /app
COPY --from=0 /build/build/libs/*.jar app.jar
USER 1000

ENTRYPOINT ["java", "-jar", "app.jar"]
80 changes: 34 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,17 @@
* [Introduction](#introduction)
* [Getting Started](#getting-started)
* [Installation](#installation)
* [Setup](#setup)
* [Marketplace](#marketplace)
* [Advertisements](#advertise)
* [Cooldowns](#cooldowns)
* [Logs](#logs)
* [Setup](#setup)
* [Marketplace](#marketplace)
* [Logs](#logs)
* [Environment Variables](#environment-variables)
* [Contributing](#contributing)

## Introduction

MinehutUtils is a community made discord bot for [discord.gg/Minehut](https://discord.gg/Minehut).
It is made with [Kotlin](https://kotlinlang.org/), [JDA](https://github.com/DV8FromTheWorld/JDA)
and [Coffee](https://github.com/SantioMC/Coffee). For the full list of dependencies check out the
MinehutUtils is a community made discord bot for [discord.gg/Minehut](https://discord.gg/Minehut).
It is made with [Kotlin](https://kotlinlang.org/), [JDA](https://github.com/DV8FromTheWorld/JDA)
and [Iron](https://github.com/ingotgg/iron). For the full list of dependencies check out the
[dependency graph](https://github.com/SantioMC/MinehutUtils/network/dependencies).

MinehutUtils is what's currently being used in the [Minehut Official Discord](https://discord.gg/Minehut) and
Expand All @@ -49,18 +47,20 @@ The following is a full list of commands that MinehutUtils provides:
| `server` | Displays information about a Minehut Server ||
| `network` | Displays information about the Minehut Network ||
| `status` | Calculates the status of core Minehut services ||
| `advertise` | Advertises a Minehut server ||
| `marketplace` | Either request or offer your services ||
| `cooldown info` | View server and your cooldown ||
| `cooldown view` | View server and your cooldown ||
| `cooldown` | Manage user's cooldowns ||
| `settings` | Change the bot settings or behaviour ||

## Getting Started

### Installation

This guide assumes you've already made a [Discord Bot](https://discord.com/developers/applications)
and retrieved your bot token.

#### Docker

Running the bot with docker is the easiest way to get started and recommended for most users.

1. Pull the docker image from github packages
Expand All @@ -76,17 +76,18 @@ Running the bot with docker is the easiest way to get started and recommended fo
```

> Note: Since the bot uses a database to store cooldowns and settings, you'll need to mount a volume
> to store the database. You can do this by adding a mount for `/app` to the docker container.
> to store the database. You can do this by adding a mount for `/data` to the docker container.
#### Docker Compose
If you want to run the bot with docker-compose, you can use the predefined docker-compose.yml file
(or create your own).
1. Download the docker-compose.yml file
```shell
curl -O https://raw.githubusercontent.com/SantioMC/MinehutUtils/master/docker-compose.yml
```
2. Create a `.env` and attach your bot token.
```properties
TOKEN=your bot token
Expand All @@ -95,8 +96,9 @@ If you want to run the bot with docker-compose, you can use the predefined docke
```shell
docker compose up -d
```
#### Manual Installation
If you want to run the bot without a container, you can do so by following these steps:
1. Clone the repository
Expand All @@ -108,61 +110,47 @@ If you want to run the bot without a container, you can do so by following these
```shell
./gradlew shadowJar
```
3. Run the jar file
```shell
java -jar build/libs/MinehutUtils-<version>.jar
```
### Setup
The bot by default should now have most things working, however a bit of configuration is needed
to get both the marketplace and advertisement commands setup. By default, if the [environment variables](#environment-variables)
are not setup for `MARKET_CHANNEL` or `ADVERT_CHANNEL` their respective commands won't work and will be disabled.
## Setup
#### Marketplace
To get the marketplace working, you should first create a channel for it if you haven't already.
Once you have a channel created, set `MARKET_CHANNEL` to the ID of the channel.
After that, users should be able to post both offers and requests in the channel.
#### Advertise
To get advertisements working, you should first create a channel for it if you haven't already.
Once you have a channel created, set `ADVERT_CHANNEL` to the ID of the channel.

After that, users should be able to post advertisements in the channel.

#### Cooldowns
Cooldowns are pretty simple to set up and by default will fall back to 24 hours if they aren't
specified. Setting a custom duration can be done by setting `MARKET_COOLDOWN` or `ADVERT_COOLDOWN`
to a duration. Durations follow the format shown below.
Valid Examples: `10s`, `10m`, `10h`, `10d`
The bot by default should now have most things working, however a bit of configuration is needed
to get both the marketplace setup. You can use the settings command to configure how the marketplace works.
Start with using `/settings channel marketplace channel:` to configure which channel marketplace postings are sent
to. You can then use `/settings cooldown marketplace cooldown:` to configure the cooldown for the marketplace command.
The cooldown is applied per listing kind per user.
#### Logs
By default, the bot will log to any channel appropriately named `#logs`, however this channel can be
overridden by setting the `LOG_CHANNEL` environment variable. Logging can be disabled by setting this to
any non-existent channel, a good example of this is `LOG_CHANNEL=.` *(Channels can not contain a dot)*.
## Environment Variables
Below are a list of all possible environment variables that can be set to configure the bot.
| Variable | Description | Default |
|-----------------|----------------------------------------------------|---------|
| DB_FILE | What should the database file be named | data.db |
| TOKEN | The bot token | |
| LOG_CHANNEL | The channel to post logs to *(without the #)* | logs |
| MARKET_CHANNEL | The channel to where marketplace postings are sent | |
| ADVERT_CHANNEL | The channel to where advertisements are sent | |
| MARKET_COOLDOWN | The cooldown for the marketplace command | 24h |
| ADVERT_COOLDOWN | The cooldown for the advertisement command | 24h |
| Variable | Description | Default |
|-----------------|-----------------------------------------------|-----------------|
| DB_FILE | Where the sqlite file is located | data/minehut.db |
| TOKEN | The bot token | |
| LOG_CHANNEL | The channel to post logs to *(without the #)* | logs |
## Contributing
Thanks for everyone who has already contributed, and anyone willing to. This is a community bot and
your contributions are what makes it great. If you aren't able to make a pull request, you can
always open an issue with a bug report or feature request [here on github](https://github.com/SantioMC/MinehutUtils/issues)
always open an issue with a bug report or feature
request [here on github](https://github.com/SantioMC/MinehutUtils/issues)

### Creating a pull request

1. Fork the repository
2. Clone your fork
```shell
Expand All @@ -175,4 +163,4 @@ always open an issue with a bug report or feature request [here on github](https
git commit -m "Your commit message"
git push
```
5. Create a pull request at https://github.com/SantioMC/MinehutUtils/pulls
5. Create a pull request at https://github.com/SantioMC/MinehutUtils/pulls
Loading

0 comments on commit 73738d2

Please sign in to comment.