Compare commits
6 Commits
6973d1dced
...
master
Author | SHA1 | Date | |
---|---|---|---|
3386009590 | |||
372513cfdd | |||
34e0799c41 | |||
b0b7c643cc | |||
77c352c7ac | |||
5ffcdb8097 |
35
.drone.yml
35
.drone.yml
@ -1,36 +1,25 @@
|
|||||||
---
|
---
|
||||||
kind: pipeline
|
kind: pipeline
|
||||||
type: docker
|
type: exec
|
||||||
name: main
|
name: main
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
branch:
|
||||||
|
- master
|
||||||
|
|
||||||
|
platform:
|
||||||
|
os: linux
|
||||||
|
arch: amd64
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: build
|
- name: build
|
||||||
image: docker:latest
|
|
||||||
volumes:
|
|
||||||
- name: docker-socket
|
|
||||||
path: /var/run/docker.sock
|
|
||||||
commands:
|
commands:
|
||||||
- docker build -t registry.drone/minebot:latest .
|
- docker build -t registry.jfmonty2.com/minebot:latest .
|
||||||
when:
|
|
||||||
branch:
|
|
||||||
- master
|
|
||||||
|
|
||||||
- name: deploy
|
- name: deploy
|
||||||
image: docker:latest
|
|
||||||
volumes:
|
|
||||||
- name: docker-socket
|
|
||||||
path: /var/run/docker.sock
|
|
||||||
environment:
|
environment:
|
||||||
REGISTRY_PWD:
|
REGISTRY_PWD:
|
||||||
from_secret: registry_pwd
|
from_secret: registry_pwd
|
||||||
commands:
|
commands:
|
||||||
- echo $REGISTRY_PWD | docker login -u drone --password-stdin registry.drone
|
- echo $REGISTRY_PWD | docker login -u drone --password-stdin registry.jfmonty2.com
|
||||||
- docker push registry.drone/minebot:latest
|
- docker push registry.jfmonty2.com/minebot:latest
|
||||||
when:
|
|
||||||
branch:
|
|
||||||
- master
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
- name: docker-socket
|
|
||||||
host:
|
|
||||||
path: /var/run/docker.sock
|
|
||||||
|
41
README.md
Normal file
41
README.md
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
# Minebot
|
||||||
|
|
||||||
|
[](https://drone.jfmonty2.com/jfmonty2/minebot)
|
||||||
|
|
||||||
|
Discord bot for controlling a Heavynode minecraft server.
|
||||||
|
|
||||||
|
Currently implemented commands:
|
||||||
|
|
||||||
|
* `!add` - adds a player to the whitelist
|
||||||
|
* `!remove` - removes a player from the whitelist
|
||||||
|
|
||||||
|
# Developing
|
||||||
|
|
||||||
|
This bot is built on [discord.py](https://discordpy.readthedocs.io/en/latest/), a Python library for Discord bots.
|
||||||
|
Discord.py makes heavy use of asynchronous Python (via the [asyncio](https://docs.python.org/3/library/asyncio.html) module).
|
||||||
|
It's worth a look if you've never experimented with that side of Python.
|
||||||
|
|
||||||
|
# Running
|
||||||
|
|
||||||
|
To run the bot, first install its dependencies:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
pip install discord.py 'python-socketio>=4.0,<5.0'
|
||||||
|
```
|
||||||
|
|
||||||
|
It also expects the following environment variables:
|
||||||
|
|
||||||
|
* `DISCORD_TOKEN`: Discord API token
|
||||||
|
* `DISCORD_SERVER_ID` (Optional, may be excluded if the bot is only joined to one server)
|
||||||
|
* `HEAVYNODE_TOKEN`: Heavynode API token
|
||||||
|
* `HEAVYNODE_COOKIE_NAME`: Name of Heavynode `remember_web` cookie
|
||||||
|
* `HEAVYNODE_COOKIE_VALUE`: Value of Heavynode `remember_web` cookie
|
||||||
|
|
||||||
|
Any of these items may be read from a file instead of the environment, by appending `_FILE` to the environment variable
|
||||||
|
and setting its value to the path of the file. E.g. `export DISCORD_TOKEN_FILE=/path/to/token/file`
|
||||||
|
|
||||||
|
You can then run the bot directly:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
python bot.py
|
||||||
|
```
|
7
bot.py
7
bot.py
@ -13,6 +13,7 @@ import heavynode
|
|||||||
|
|
||||||
|
|
||||||
DISCORD_TOKEN = lib.getconfig('DISCORD_TOKEN')
|
DISCORD_TOKEN = lib.getconfig('DISCORD_TOKEN')
|
||||||
|
DISCORD_SERVER_ID = int(lib.getconfig('DISCORD_SERVER_ID', 0))
|
||||||
HEAVYNODE_TOKEN = lib.getconfig('HEAVYNODE_TOKEN')
|
HEAVYNODE_TOKEN = lib.getconfig('HEAVYNODE_TOKEN')
|
||||||
COOKIE_NAME = lib.getconfig('HEAVYNODE_COOKIE_NAME')
|
COOKIE_NAME = lib.getconfig('HEAVYNODE_COOKIE_NAME')
|
||||||
COOKIE_VALUE = lib.getconfig('HEAVYNODE_COOKIE_VALUE')
|
COOKIE_VALUE = lib.getconfig('HEAVYNODE_COOKIE_VALUE')
|
||||||
@ -30,7 +31,11 @@ bot.add_cleanup(hn.shutdown)
|
|||||||
|
|
||||||
async def is_admin(ctx):
|
async def is_admin(ctx):
|
||||||
user = ctx.message.author
|
user = ctx.message.author
|
||||||
member = bot.guilds[0].get_member(user.id)
|
if DISCORD_SERVER_ID != 0:
|
||||||
|
guild = discord.utils.get(bot.guilds, id=DISCORD_SERVER_ID)
|
||||||
|
else:
|
||||||
|
guild = bot.guilds[0]
|
||||||
|
member = guild.get_member(user.id)
|
||||||
if member is not None:
|
if member is not None:
|
||||||
for role in member.roles:
|
for role in member.roles:
|
||||||
if role.name == 'Admin' or role.name == 'Mod':
|
if role.name == 'Admin' or role.name == 'Mod':
|
||||||
|
5
lib.py
5
lib.py
@ -26,13 +26,14 @@ class MineBot(commands.Bot):
|
|||||||
await super().close()
|
await super().close()
|
||||||
|
|
||||||
|
|
||||||
def getconfig(key, default=None):
|
nodefault = object()
|
||||||
|
def getconfig(key, default=nodefault):
|
||||||
if key in os.environ:
|
if key in os.environ:
|
||||||
return os.environ[key]
|
return os.environ[key]
|
||||||
elif f'{key}_FILE' in os.environ:
|
elif f'{key}_FILE' in os.environ:
|
||||||
p = os.environ[f'{key}_FILE']
|
p = os.environ[f'{key}_FILE']
|
||||||
return pathlib.Path(p).read_text()
|
return pathlib.Path(p).read_text()
|
||||||
elif default != None:
|
elif default is not nodefault:
|
||||||
return default
|
return default
|
||||||
else:
|
else:
|
||||||
raise ConfigError('Missing config:', key)
|
raise ConfigError('Missing config:', key)
|
Reference in New Issue
Block a user