2020-05-09 17:45:07 +00:00
|
|
|
import inspect
|
2020-05-09 04:39:28 +00:00
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
|
|
|
|
from discord.ext import commands
|
|
|
|
|
2020-05-13 01:23:22 +00:00
|
|
|
import lib
|
2020-05-09 04:39:28 +00:00
|
|
|
import heavynode
|
|
|
|
|
|
|
|
|
2020-05-13 01:23:22 +00:00
|
|
|
DISCORD_TOKEN = os.environ['discord_token']
|
|
|
|
HEAVYNODE_TOKEN = os.environ['heavynode_token']
|
2020-05-09 05:58:27 +00:00
|
|
|
|
|
|
|
|
2020-05-09 04:39:28 +00:00
|
|
|
logging.basicConfig()
|
2020-05-09 05:58:27 +00:00
|
|
|
|
2020-05-13 01:23:22 +00:00
|
|
|
bot = lib.MineBot(command_prefix='!')
|
|
|
|
hn = heavynode.Client(HEAVYNODE_TOKEN)
|
2020-05-09 17:45:07 +00:00
|
|
|
bot.add_cleanup(hn.shutdown)
|
2020-05-09 04:39:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
@bot.command()
|
2020-05-09 06:32:30 +00:00
|
|
|
@commands.has_any_role('Admin', 'Mod')
|
2020-05-09 04:39:28 +00:00
|
|
|
async def add(ctx, player):
|
2020-05-09 06:32:30 +00:00
|
|
|
"""Add a player to the server whitelist. Must use exact Minecraft name."""
|
2020-05-13 01:23:22 +00:00
|
|
|
await hn.send_command(f'whitelist add {player}')
|
2020-05-09 04:39:28 +00:00
|
|
|
await ctx.send(f'"{player}" added to whitelist.')
|
|
|
|
|
|
|
|
|
|
|
|
@bot.command()
|
2020-05-09 06:32:30 +00:00
|
|
|
@commands.has_any_role('Admin', 'Mod')
|
2020-05-09 04:39:28 +00:00
|
|
|
async def remove(ctx, player):
|
|
|
|
"""Remove a player from the server whitelist. Must use exact Minecraft name."""
|
2020-05-13 01:23:22 +00:00
|
|
|
await hn.send_command(f'whitelist remove {player}')
|
2020-05-09 04:39:28 +00:00
|
|
|
await ctx.send(f'"{player}" removed from whitelist.')
|
|
|
|
|
|
|
|
|
|
|
|
@add.error
|
|
|
|
@remove.error
|
|
|
|
async def whitelist_error(ctx, error):
|
|
|
|
if isinstance(error, commands.CheckFailure):
|
|
|
|
await ctx.send('You must be a server admin to use this command.')
|
2020-05-13 01:23:22 +00:00
|
|
|
elif isinstance(error, heavynode.HttpError):
|
|
|
|
await ctx.send('Failed to communicate with server.')
|
2020-05-09 04:39:28 +00:00
|
|
|
else:
|
|
|
|
raise error
|
|
|
|
|
|
|
|
|
2020-05-13 01:23:22 +00:00
|
|
|
bot.run(DISCORD_TOKEN, reconnect=True)
|