Add easy way to retrieve bot invite URL

Fixes #38
master
Tristan Gosselin-Hane 6 years ago
parent ededae195a
commit 9384b8539b
No known key found for this signature in database
GPG Key ID: 86886FC44C72EAA1
  1. 26
      minecraft_discord_bridge/minecraft_discord_bridge.py

@ -51,6 +51,8 @@ class MinecraftDiscordBridge():
self.database_session = DatabaseSession() self.database_session = DatabaseSession()
self.logger = logging.getLogger("bridge") self.logger = logging.getLogger("bridge")
self.database_session.initialize(self.config) self.database_session.initialize(self.config)
self.bot_perms = discord.Permissions()
self.bot_perms.update(manage_messages=True, manage_webhooks=True)
# We need to import twisted after setting up the logger because twisted hijacks our logging # We need to import twisted after setting up the logger because twisted hijacks our logging
from . import auth_server from . import auth_server
auth_server.DATABASE_SESSION = self.database_session auth_server.DATABASE_SESSION = self.database_session
@ -64,6 +66,8 @@ class MinecraftDiscordBridge():
@self.discord_bot.event @self.discord_bot.event
async def on_ready(): # pylint: disable=W0612 async def on_ready(): # pylint: disable=W0612
self.logger.info("Discord bot logged in as %s (%s)", self.discord_bot.user.name, self.discord_bot.user.id) self.logger.info("Discord bot logged in as %s (%s)", self.discord_bot.user.name, self.discord_bot.user.id)
self.logger.info("Discord bot invite link: %s", discord.utils.oauth_url(
client_id=self.discord_bot.user.id, permissions=self.bot_perms))
await self.discord_bot.change_presence(activity=discord.Game("mc!help for help")) await self.discord_bot.change_presence(activity=discord.Game("mc!help for help"))
self.webhooks = [] self.webhooks = []
session = self.database_session.get_session() session = self.database_session.get_session()
@ -261,6 +265,27 @@ class MinecraftDiscordBridge():
await error_msg.delete() await error_msg.delete()
return return
elif message.content.startswith("mc!botlink"):
send_channel = message.channel
try:
if isinstance(message.channel, discord.abc.GuildChannel):
await message.delete()
dm_channel = message.author.dm_channel
if not dm_channel:
await message.author.create_dm()
send_channel = message.author.dm_channel
msg = "Use the following link to invite this bot to a guild:\n{}".format(discord.utils.oauth_url(
client_id=self.discord_bot.user.id, permissions=self.bot_perms))
await send_channel.send(msg)
return
except discord.errors.Forbidden:
if isinstance(message.author, discord.abc.User):
msg = "{}, please allow private messages from this bot.".format(message.author.mention)
error_msg = await message.channel.send(msg)
await asyncio.sleep(3)
await error_msg.delete()
return
elif message.content.startswith("mc!"): elif message.content.startswith("mc!"):
# Catch-all # Catch-all
send_channel = message.channel send_channel = message.channel
@ -463,6 +488,7 @@ class MinecraftDiscordBridge():
"User commands:\n" "User commands:\n"
"`mc!tab`: Sends you the content of the server's player/tab list\n" "`mc!tab`: Sends you the content of the server's player/tab list\n"
"`mc!register`: Starts the minecraft account registration process\n" "`mc!register`: Starts the minecraft account registration process\n"
"`mc!botlink`: Sends you the link to invite this bot to a guild\n"
"To start chatting on the minecraft server, please register your account using `mc!register`.") "To start chatting on the minecraft server, please register your account using `mc!register`.")
return help_str return help_str

Loading…
Cancel
Save