Giter Site home page Giter Site logo

itabashi's Introduction

Itabashi (板橋) - Discord-IRC Bridge

Itabashi is a bot that syncs messages between a Discord and an IRC channel. It is written in Python, using the discord.py and gIRC libraries.

Itabashi was developed by the Bibliotheca Anonoma to coordinate operations between its Discord and IRC channels.

Dependencies

  • python3.4 (with venv)
  • gcc
  • libffi + development libraries

Debian/Ubuntu:

sudo apt-get install python3.4 python3.4-venv gcc libffi-dev

Fedora:

# dnf install python3 gcc libffi libffi-devel

Red Hat/CentOS:

Install Python34 as specified in this link: https://www.softwarecollections.org/en/scls/rhscl/rh-python34/

You will also need to fix the python34 package for pip as Red Hat forgot to include some files: http://stackoverflow.com/a/33767179

Setup

> Note: Itabashi requires Python 3.4 or above, as it uses the asyncio library.

Clone the repository and enter the folder:

$ git clone https://github.com/bibanon/itabashi.git
$ cd itabashi

Create a virtualenv and use it (this makes sure that your various installed packages don't conflict system-wide):

$ python3 -m venv env # for Debian/Ubuntu
$ pyvenv env          # for Fedora/CentOS/RHEL
$ source env/bin/activate

Install the dependencies:

$ pip3 install -r requirements.txt

Create a configuration file:

$ python3 create-config.py

Start using the bot!

$ python3 startlink.py connect

The bot will then connect to both IRC and Discord using the provided credentials and start relaying messages.

Systemd Daemon User

We can also create a systemd daemon user to control the bot.

$ cd /home
# git clone https://github.com/bibanon/itabashi.git
# useradd -s /bin/bash -d /home/itabashi -r itabashi
# chown -R itabashi:itabashi /home/itabashi

Then, set up the discord bot as usual, but as the daemon user.

# sudo -i -u itabashi
$ python3 -m venv env
$ source env/bin/activate
$ pip3 install -r requirements.txt
$ python3 create-config.py

Finally, use the command below to create a service.sh file for the systemd service to use:

$ nano /home/itabashi/service.sh

Put the following lines inside that file:

#!/bin/bash
# Systemd Service launcher for Itabashi that runs in Python virtualenv.
source env/bin/activate
python3 startlink.py connect

Then finish up by making that script executable, exit the daemon user, and disable login for the daemon user:

$ chmod +x /home/itabashi/service.sh
$ exit
# chsh -s /bin/false itabashi

Now we can create a systemd service file to use:

/etc/systemd/system/itabashi.service

[Unit]
Description=Itabashi Discord/IRC Bridge
After=multi-user.target

[Service]
ExecStart=/home/itabashi/service.sh

WorkingDirectory=/home/itabashi/

User=itabashi
Group=itabashi

[Install]
WantedBy=multi-user.target

To start or stop the discord bridge, use these commands:

# systemctl restart itabashi
# systemctl stop itabashi

To enable the service at every boot, use this command:

# systemctl enable itabashi

License

Copyright (C) 2016 Bibliotheca Anonoma

This file is part of Itabashi.

Itabashi is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.

Itabashi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Itabashi. If not, see <http://www.gnu.org/licenses/>.

itabashi's People

Contributors

antonizoon avatar danieloaks avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

itabashi's Issues

Discord: Convert IDs in messages to names

When you @ mention a user or put the name of a channel in a Discord chat, it gets converted to the ID when pushed out to IRC and such.

We should be outputting names there instead.

Allow pinging between Discord and IRC

If someone on IRC says: @Somecooldude yo what up

And there is someone on Discord who has that name, it should ping them in the message.

Discord -> IRC is not required as client highlighting is based on nick matching already, rather than the explicit name mentioning that Discord uses.

Create systemd Service

I've created an impromptu systemd service for itabashi to use:

It requires the user itabashi to be created on the system, with this git repo cloned into /home/itabashi/itabashi. Then it runs the the bot under the virtualenv using service.sh:

However, it's not altogether elegant. Maybe there could be an installation script and such. But either way it works for now.

/etc/systemd/system/itabashi.service

[Unit]
Description=Itabashi Discord/IRC Bridge
After=multi-user.target

[Service]
ExecStart=/home/itabashi/itabashi/service.sh

WorkingDirectory=/home/itabashi/itabashi/

User=itabashi
Group=itabashi

[Install]
WantedBy=multi-user.target

/home/itabashi/itabashi/service.sh

source env/bin/activate
python3 startlink.py connect

Needs to be upgraded for latest discord.py version

We're going to be moving servers in a month, and it seems like there is a gradually growing amount of community interest in this bot. So, we are going to need to update this app to work with the latest version of discord.py, preferably before Sep. 10th.

In addition, with some nifty systemd autorestart settings, Itabashi now works fine in practice on the BA IRC. So it's about ready for release, just needs upgrade and documentation.

Investigate how Discord.py / gIRC reconnect

We should optimally have the IM Managers reconnect automatically. I'm not 100% sure gIRC does this automagically yet, and I have absolutely no clue how Discord.py handles it, but we should see and correct this if they don't autoreconnect.

Yay logs from IRC:

irc: ita  -> ERROR :Closing Link: bibanon.discord.bouncer (Ping timeout: 240 seconds)
Connection closed
Task was destroyed but it is pending!
task: <Task pending coro=<run() running at /home/dan/itabashi/env/lib/python3.4/site-packages/websockets/protocol.py:302> wait_for=<Future pending cb=[Task._wakeup()]> cb=[_wait.<locals>._on_completion() at /usr/lib/python3.4/asyncio/tasks.py:394]>
Task was destroyed but it is pending!
task: <Task pending coro=<keep_alive_handler() running at /home/dan/itabashi/env/lib/python3.4/site-packages/discord/client.py:286> wait_for=<Future pending cb=[Task._wakeup()]>>
Task was destroyed but it is pending!
task: <Task pending coro=<get() running at /usr/lib/python3.4/asyncio/queues.py:186> wait_for=<Future pending cb=[Task._wakeup()]> cb=[_wait.<locals>._on_completion() at /usr/lib/python3.4/asyncio/tasks.py:394]>
Task was destroyed but it is pending!
task: <Task pending coro=<main_task() running at /home/dan/itabashi/itabashi/discord.py:37> wait_for=<Future pending cb=[Task._wakeup()]>>
(env) 

Degrading to one-way message passing

For some reason, after running a while Itabashi stopped sending messages from Discord to IRC, though messages still got sent in the other direction. No errors printed.

be33808 and b9a9325 should be able to help shed some light on this when it occurs again.

Improper text escaping

The text
if you didn't you'd replace the \s with [^\d]
on IRC shows in Discord as
if you didn't you'd replace the s with [^d]

Presumably some library is interpreting the backslashes as escape characters.

Improve config format

We can have an improved config format, since the one we inherited is slightly ugly and can be difficult to understand.

Initial work on this has started in the custom-config-format branch.

Allow IRC users to "mention" Discord users

On the Discord side of things, you can easily mention other users by typing their name in the following format:

@name#1111

with name being the screen name of the user, and 1111 being an example of a [server-specific] discriminator.

While Itabashi shows us the screen name of a client (when they are talking), we only know their screen name, not their discriminator. This makes it impossible for IRC users to "mention" a Discord user; that is, to cause the message to give that specific user a notification.

I have a solution in mind. When parsing a message from a bridged IRC channel, follow these steps (in addition to parsing it as normal):

  1. If it doesn't has a @ character in it, just parse it as normal and ignore the following steps.
  2. For each @ character in the message, parse the characters following it until we reach a whitespace character (there is an issue here, which I'll mention soon). Search through the list of members of the server and pick the user whose name exactly matches that string (should we be case-sensitive?). If there are multiple users with that screen name, we pick the one who most recently typed. (up for debate)
  3. Replace each @-string from the IRC message with a mention (following the example above) according the the details of that user (i.e. matching the screen name and discriminator). I'm not extremely familiar with the Discord chat API so I'm not sure if we will have to do anything else besides this to "mention" that user when Itabashi is sending the bridged message to the Discord channel, but Discord's UI uses the above format to do mentions internally.

We do have some potential issues though:

  • What if a Discord user's screen name has whitespace characters in it? Should we add a delimiter for it?
    • The # prefixing the discriminator effectively functions as one in the Discord universe.
  • Should we be case sensitive when trying to match up an IRC -> Discord mention to the correct Discord user?
    • We should probably find out if Discord is. I'd imagine that it is, but I'm not sure.
  • If multiple Discord users have the same screen name, how do we decide which to mention?

Logging system

As outlined in the design doc, we will create a logging system that works with our shared event manager.

Name mapping

It could be useful to map names back and forth when messages are sent, or at least let users do that.

For instance, map a Discord user's ID to a different name to match who they are in the IRC, etc.

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.