Replace environment variable for TW instance ID with optional parameter

This commit is contained in:
Ske 2018-12-11 20:52:43 +01:00
parent 270b21e9fd
commit ea07e931fc
2 changed files with 10 additions and 5 deletions

View File

@ -11,7 +11,6 @@ services:
- CLIENT_ID - CLIENT_ID
- TOKEN - TOKEN
- LOG_CHANNEL - LOG_CHANNEL
- TUPPERWARE_ID
- "DATABASE_USER=postgres" - "DATABASE_USER=postgres"
- "DATABASE_PASS=postgres" - "DATABASE_PASS=postgres"
- "DATABASE_NAME=postgres" - "DATABASE_NAME=postgres"

View File

@ -1,4 +1,3 @@
import os
from datetime import datetime from datetime import datetime
from pluralkit.bot.commands import * from pluralkit.bot.commands import *
@ -13,12 +12,19 @@ async def import_tupperware(ctx: CommandContext):
# Check if there's a Tupperware bot on the server # Check if there's a Tupperware bot on the server
# Main instance of TW has that ID, at least # Main instance of TW has that ID, at least
tupperware_id = 431544605209788416 tupperware_id = 431544605209788416
if "TUPPERWARE_ID" in os.environ: if ctx.has_next():
tupperware_id = int(os.environ["TUPPERWARE_ID"]) try:
id_str = ctx.pop_str()
tupperware_id = int(id_str)
except ValueError:
raise CommandError("'{}' is not a valid ID.".format(id_str))
tupperware_member = ctx.message.guild.get_member(tupperware_id) tupperware_member = ctx.message.guild.get_member(tupperware_id)
if not tupperware_member: if not tupperware_member:
raise CommandError("This command only works in a server where the Tupperware bot is also present.") raise CommandError(
"""This command only works in a server where the Tupperware bot is also present.
If you're trying to import from a Tupperware instance other than the main one (which has the ID 431544605209788416), pass the ID of that instance as a parameter.""")
# Make sure at the bot has send/read permissions here # Make sure at the bot has send/read permissions here
channel_permissions = ctx.message.channel.permissions_for(tupperware_member) channel_permissions = ctx.message.channel.permissions_for(tupperware_member)