From 1bd2e399aeb56de4027aca704b12cf18f8688b94 Mon Sep 17 00:00:00 2001 From: Tristan Gosselin-Hane Date: Sun, 14 Oct 2018 17:19:33 -0400 Subject: [PATCH] Migrate to the "rewrite" branch of discord.py This branch contains new additions we need such as webhook management --- Pipfile | 2 +- Pipfile.lock | 11 ++--------- webhook-bridge.py | 22 ++++++++++++---------- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/Pipfile b/Pipfile index a036c52..7c9b3a1 100644 --- a/Pipfile +++ b/Pipfile @@ -10,10 +10,10 @@ minecraft = {git = "https://github.com/ammaraskar/pyCraft.git"} requests = "*" cryptography = "*" future = "*" -"discord.py" = {git = "https://github.com/Rapptz/discord.py.git"} sqlalchemy = "*" mcstatus = "*" quarry = "*" +discord-py = {git = "https://github.com/Rapptz/discord.py.git", ref = "rewrite"} [requires] python_version = "3.6" diff --git a/Pipfile.lock b/Pipfile.lock index 77f86db..c97006d 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "45a63e42d93560ed412ddaeed6b5962c849eeaf9424c12f63e4a6c3aea903377" + "sha256": "a940822d36bbfcc2e6b46e68636b5c40b0cf43ab2ed80166ba84ccf1b24dd06b" }, "pipfile-spec": 6, "requires": { @@ -129,10 +129,7 @@ }, "discord-py": { "git": "https://github.com/Rapptz/discord.py.git", - "ref": "1863a1c6636f53592519320a173ec9573c090c0b" - }, - "discord.py": { - "git": "https://github.com/Rapptz/discord.py.git" + "ref": "860d6a9ace8248dfeec18b8b159e7b757d9f56bb" }, "dnspython": { "hashes": [ @@ -206,10 +203,6 @@ ], "version": "==2.19" }, - "pycraft": { - "git": "https://github.com/ammaraskar/pyCraft.git", - "ref": "48e1003f4264c1f7d6ecc3ac59022738a29ebe21" - }, "pyhamcrest": { "hashes": [ "sha256:6b672c02fdf7470df9674ab82263841ce8333fb143f32f021f6cb26f0e512420", diff --git a/webhook-bridge.py b/webhook-bridge.py index ba1881a..ff4d3db 100755 --- a/webhook-bridge.py +++ b/webhook-bridge.py @@ -246,7 +246,11 @@ def main(): if message.author == discord_bot.user: return this_channel = message.channel.id - if message.channel.is_private: + if isinstance(message.channel, discord.abc.PrivateChannel): + if message.content.startswith("mc!help"): + return + if message.content.startswith("mc!somethingelse"): + return if message.content.startswith("mc!register"): session = database_session.get_session() discord_account = session.query(DiscordAccount).filter_by(discord_id=message.author.id).first() @@ -262,17 +266,16 @@ def main(): session.add(account_link_token) session.commit() msg = "Please connect your minecraft account to `{}.{}:{}` in order to link it to this bridge!".format(new_token, config.auth_dns, config.auth_port) - await discord_bot.send_message(message.channel, msg) session.close() + await message.channel.send(msg) return else: msg = "Unknown command, type `mc!help` for a list of commands." - await discord_bot.send_message(message.channel, msg) + await message.channel.send(msg) return if message.content.startswith("mc!chathere"): session = database_session.get_session() channels = session.query(DiscordChannel).filter_by(channel_id=this_channel).all() - logging.info(channels) if not channels: new_channel = DiscordChannel(this_channel) session.add(new_channel) @@ -280,10 +283,10 @@ def main(): session.close() del session msg = "The bot will now start chatting here! To stop this, run `mc!stopchathere`." - await discord_bot.send_message(message.channel, msg) + await message.channel.send(msg) else: msg = "The bot is already chatting in this channel! To stop this, run `mc!stopchathere`." - await discord_bot.send_message(message.channel, msg) + await message.channel.send(msg) return elif message.content.startswith("mc!stopchathere"): @@ -292,18 +295,17 @@ def main(): deleted = session.query(DiscordChannel).filter_by(channel_id=this_channel).delete() session.commit() session.close() - logging.info(deleted) if deleted < 1: msg = "The bot was not chatting here!" - await discord_bot.send_message(message.channel, msg) + await message.channel.send(msg) return else: msg = "The bot will no longer here!" - await discord_bot.send_message(message.channel, msg) + await message.channel.send(msg) return elif not message.author.bot: - await discord_bot.delete_message(message) + await message.delete() packet = serverbound.play.ChatPacket() packet.message = "{}: {}".format(message.author.name, message.content) connection.write_packet(packet)