Giter Club home page Giter Club logo

black-hole's Introduction

black-hole

black-hole is a configurable XMPP ↔ Discord bridge written in Python 3.6.

It uses Discord.py@rewrite and aioxmpp.

Requirements

  • Python 3.6+ (Tested on Python 3.7)

Configuring

Here is a sample config.yaml:

# XMPP credentials (JID and password).
xmpp:
  jid: '[email protected]'
  password: 'ramen'

# black-hole supports multiple "rooms".
#
# The concept of a "room" in black-hole combines both a MUC and a Discord
# channel. They are linked together with a Discord bot, a Discord webhook,
# and an XMPP client.
rooms:
  - jid: '[email protected]' # The JID of the MUC.

    # The MUC's password. Omit if password-less.
    # password: 'spicy ramen'

    # The nickname to use when joining the MUC.
    nick: 'black hole'

    # The webhook URL to post to. (MUC → Discord)
    webhook: 'https://discordapp.com/api/webhooks/...'

    # The Discord channel's ID. (Discord → MUC)
    channel_id: 123456789012345678

    # Log any message sent in the MUC to standard out.
    log: false

    # Log any message sent in the linked Discord channel to standard out.
    discord_log: false
discord:
  # Discord bot token, used to receive messages.
  token: 'NDU...'

  # A list of Discord user IDs that will be able to manage the bot from
  # Discord.
  managers:
    - 123
    - 456

  # A map of JIDs to Discord user IDs.
  # Allows black-hole to specify the avatar URL of a JID's associated Discord
  # account when posting to the webhook.
  jid_map:
    '[email protected]': 123
    '[email protected]': 456

  # The delay in seconds between webhook sends (for maintaining message order).
  delay: 0.25

  # The delay in seconds before a cached avatar is invalidated and refetched,
  # in seconds. The default is 30 minutes.
  avatar_cache: 1800

Documentation

Message Transport

Webhooks are used to transfer messages from the MUC to Discord. The Discord bot listens for messages in the specified channel and transfers them to the MUC.

We use a webhook because it allows us to customize the "author" and avatar of the posted message, which makes mirrored messages easier to read.

To Discord

Mentions

Any message travelling from MUC to Discord are stripped of mentions.

Any role or user mention (including @everyone and @here) are escaped/stripped and do not mention anyone. Channel mentions are not, but you must send them in "raw" format (like <#123>).

Queueing

To preserve message order, MUC messages are pushed into a queue and a background consumer POSTs to the webhook with a (configurable) delay between requests.

To MUC

Attachments

Any attachment URLs are appended to the end of the message, separated by spaces.

Embeds

In the case of bots, the number of embeds present in the message is appended to the end of the message.

Message Edits

When a message is edited on Discord, the edited version will be resent to the MUC with an "(edited)" prefix. aioxmpp presumably has no XEP-0308 support, so we can't use it, and even if it did support it, it would still be quite clunky due to the way the XEP works.

Any edits made on the MUC are not reflected on Discord.

JID Map

The JID map allows the XMPP → Discord functionality to resolve the user's avatar to be displayed through the webhook. It can be managed manually through the config file or through the Discord bot.

Discord Management

Use these commands to manage the JID map from Discord:

# Map a JID to a Discord user. You can provide the user ID, mention, or a username.
@bot jid set <jid> <user>

# Deletes a JID from the JID map.
@bot jid del <jid>

# Shows the entire JID map.
@bot jid show

The set and del commands automatically save changes.

Disabling bridging

You can quickly toggle bridging using the Discord bot:

# Toggle the current room from being bridged.
@bot room toggle

# Toggle [email protected] from being bridged.
@bot room toggle [email protected]

This state persists between restarts (saved in configuration file).

black-hole's People

Contributors

lun-4 avatar mstrodl avatar slice avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

black-hole's Issues

Support edited XMPP messages

Currently, when an XMPP message is edited, we get a new message with an edited flag, but since the bridge code is unaware of that, it forwards it up to Discord without any flag of sorts. aioxmpp got support for that edited flag but investigation is required to see how do we access that flag.

@vvvvvvivi told me that webhooks now support PATCH, and I can see other people in the Discord API server also talking about it, so it looks legit enough. There aren't any docs, but Mason confirmed the feature: append /messages/{message_id} and watch the magic happen.

Implementation details are dependent on how aioxmpp provides edit info to us. If it's just a flag, I'm not sure how we could do it, but if it provides the old message content, we could create an in-memory dict of (jid, content) => message_id, do a lookup, patch, delete old key, add new key.

Keep in mind this does not equate to supporting edited Discord messages back to XMPP.

XMPP component support?

As a component for a XMPP server this bridge could create puppets for Discord users or at least spoof their usernames.

Thanks for looking into it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.