Compare commits
2 commits
34c81b98a7
...
aa8c5d5d8b
Author | SHA1 | Date | |
---|---|---|---|
aa8c5d5d8b | |||
488c8e1b32 |
2 changed files with 55 additions and 19 deletions
48
app.py
48
app.py
|
@ -19,12 +19,9 @@ async def on_ready():
|
|||
@client.event
|
||||
async def on_message(message):
|
||||
# Only allow chats in DM or whitelisted channels
|
||||
# TODO: FIX
|
||||
if not (isinstance(message.channel, discord.channel.DMChannel)) and not (message.channel.id in config['bot']['channels']):
|
||||
print(isinstance(message.channel, discord.channel.DMChannel))
|
||||
print(message.channel.id)
|
||||
return
|
||||
# print(message.channel.name)
|
||||
|
||||
# Handle own messages
|
||||
if message.author == client.user:
|
||||
return
|
||||
|
@ -41,11 +38,6 @@ async def on_message(message):
|
|||
await message.channel.send(f"{message.author.mention} 👋")
|
||||
return
|
||||
|
||||
# if message.content == f"{client.user.mention} version":
|
||||
# logger.info(f"Version by {message.author.name}")
|
||||
# await message.channel.send(f"{message.author.mention} ")
|
||||
# return
|
||||
|
||||
# Handle @Bot mention
|
||||
messagearray = message.content.split()
|
||||
if messagearray[0] == client.user.mention:
|
||||
|
@ -53,39 +45,57 @@ async def on_message(message):
|
|||
else:
|
||||
return
|
||||
|
||||
if messagearray[0] == "help":
|
||||
command = messagearray[0].lower()
|
||||
|
||||
# message starts with "help"
|
||||
if command == "help":
|
||||
logger.info(f"Help by {message.author.name}")
|
||||
await message.channel.send(BuildHelpList())
|
||||
return
|
||||
if messagearray[0] in ["list", "info"]:
|
||||
logger.info(f"{messagearray[0]} by {message.author.name}")
|
||||
|
||||
# message starts with "list" or "info"
|
||||
if command in ["list", "info"]:
|
||||
logger.info(f"{command} by {message.author.name}")
|
||||
await message.channel.send(BuildGameList())
|
||||
return
|
||||
|
||||
if messagearray[0] in ["start", "stop", "restart"] and len(messagearray) >= 2:
|
||||
if command in ["start", "stop", "restart"]:
|
||||
if len(messagearray) != 2:
|
||||
logger.error(
|
||||
f"{command} with invalid numer of arguments by {message.author.name}. Command: \"{message.content}\"")
|
||||
await message.add_reaction("❌")
|
||||
await message.channel.send(f"Invalid number of arguments")
|
||||
return
|
||||
game = GetGameByGameSlug(messagearray[1])
|
||||
if not game:
|
||||
logger.error(
|
||||
f"{messagearray[0]} for invalid Game \"{messagearray[1]}\" by {message.author.name}")
|
||||
f"{command} for invalid Game \"{messagearray[1]}\" by {message.author.name}")
|
||||
await message.add_reaction("❌")
|
||||
await message.channel.send(f"Invalid game: {messagearray[1]}")
|
||||
return
|
||||
logger.info(
|
||||
f"{messagearray[0]} by {message.author.name}, Game: {messagearray[1]}")
|
||||
success = HandleSystemdService(game, messagearray[0])
|
||||
f"{command} by {message.author.name}, Game: {messagearray[1]}")
|
||||
success = HandleSystemdService(game, command)
|
||||
|
||||
# :white_check_mark: :x:
|
||||
if success:
|
||||
logger.info(
|
||||
f"{messagearray[0]} by {message.author.name}, Game: {messagearray[1]} was SUCESSFUL")
|
||||
f"{command} by {message.author.name}, Game: {messagearray[1]} was SUCESSFUL")
|
||||
await message.add_reaction("✅")
|
||||
await message.channel.send(f"Successfully started {game['displayname']}! Happy gaming! 🎮")
|
||||
else:
|
||||
logger.error(
|
||||
f"{messagearray[0]} by {message.author.name}, Game: {messagearray[1]} FAILED!")
|
||||
f"{command} by {message.author.name}, Game: {messagearray[1]} FAILED!")
|
||||
await message.add_reaction("❌")
|
||||
await message.channel.send(f"Sorry {message.author.mention}, that didn't work. Ping @lauralani")
|
||||
|
||||
if messagearray[0] == "status":
|
||||
if command == "status":
|
||||
if len(messagearray) != 2:
|
||||
logger.error(
|
||||
f"Status with invalid numer of arguments by {message.author.name}. Command: \"{message.content}\"")
|
||||
await message.add_reaction("❌")
|
||||
await message.channel.send(f"Invalid number of arguments")
|
||||
return
|
||||
status = BuildSingleGameStatus(messagearray[1])
|
||||
if not status:
|
||||
logger.error(
|
||||
|
|
26
config.example.py
Normal file
26
config.example.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
config = {
|
||||
"bot": {
|
||||
|
||||
"token": "aslkjdasjldjsaldjasl",
|
||||
"channels": [
|
||||
12873281371823821328193, # laura lol, bot-test
|
||||
21302918421093801832 # LiLa Network Clubhaus, game-control
|
||||
],
|
||||
"whitelist": [
|
||||
"username"
|
||||
]
|
||||
|
||||
},
|
||||
"games": [
|
||||
{
|
||||
"displayname": "Minecraft Vanilla Server",
|
||||
"slug": "mc-v",
|
||||
"systemd": "minecraft-vanilla01.service"
|
||||
},
|
||||
{
|
||||
"displayname": "Minecraft AllTheMods 8",
|
||||
"slug": "mc-atm8",
|
||||
"systemd": "minecraft-allthemods8.service"
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in a new issue