Giter Club home page Giter Club logo

discord-irc-sync's Introduction

Discord-IRC Synchronization

Description

Python3.5+ implementation of a synchronization between IRC and Discord

discordirc

Requirements

  • Python 3.5+
  • Discord Bot

Discord Bot

  1. Go to Discord developer application
  2. Add a new application
  3. Create a Bot User
  4. Follow https://discordapp.com/oauth2/authorize?&client_id=CLIENT_ID&scope=bot&permissions=0 with your application Client ID
  5. Choose your server

Then, enable Message Content Intent by navigating to your bot page (https://discord.com/developers/applications then choose your bot), under the bot menu, enable the Message Content Intent parameter so the bot can read messages and transfer them to IRC.

Initialization

git clone [email protected]:Hackndo/discord-irc-sync.git
cd discord-irc-sync
mkvirtualenv discordirc -p $(which python3)
pip install -r requirements.txt

Configuration

Copy configuration template

cp config/config.json.dist config/config.json

Configuration file looks like this

{
    "irc": {
        "server": "irc.server.com",                 // IRC Server
        "port": "6667",                             // IRC Port
        "ssl": false,                               // Use SSL
        "channel": "#channel",                      // IRC Channel
        "nickname": "h_bot",                        // Bot Nickname
        "owner": "username",                        // Bot Owner Nickname (admin commands)
        "cmd_prefix": "!",                          // Channel commands prefix (if any)
        "output_msg": "<:username:> :message:",     // Message format when IRC message is received
        "output_cmd": "CMD by :username:",          // Message format when IRC command is received
        "log_events": true                          // Send part/join/kick/quit to discord
    },
    "discord": {
        "server": <server id>,                      // Discord Server ID
        "channel": <channel id>,                    // Discord Channel ID
        "token": "<bot token>",                     // Discord Bot Token
        "owner": "username",                        // Discord Bot Owner username (admin commands)
        "cmd_prefix": "!",                          // Channel commands prefix (if any)
        "output_msg": "<:username:> :message:",     // Message format when Discord message is received
        "output_cmd": "CMD by :username:",          // Message format when Discord command is received
        "log_events": true                          // Send part/join/kick/quit to IRC
    },
    "formatting": {
        "irc_to_discord": false,                    // Keep bold|underline|italic from IRC to Discord
        "discord_to_irc": true                      // Keep bold|underline|italic from Discord to IRC
    }
}

Usage

(discordirc) pixis@kali:~/Tools/discord-irc-sync $ python discord-irc-sync.py 
[IRC] Logged in as:
[IRC] hacknbot
[Discord] Logged in as:
[Discord] irc-sync
[Discord] <pixis> : Can you hear me IRC Tom? 😃
[IRC] <pixis> : Yes, I can

TODO

  • Format message from Discord to IRC
  • Format message from IRC to Discord : Difficult because not everything is possible, especially when formatting is overlapping
  • Multi channel
  • Multi server
  • Dynamically relaod conf when changed
  • Change conf with IRC or Discord commands

discord-irc-sync's People

Contributors

hackndo avatar julienpalard avatar t00sh avatar th3l5d 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

discord-irc-sync's Issues

Message too long

We got an exception when a Discord user tried to send a long message:

traceback
Apr 16 05:40:48 deb2 python[1681532]: [2023-04-16 05:40:48] [ERROR   ] discord.client: Ignoring exception in on_message
Apr 16 05:40:48 deb2 python[1681532]: Traceback (most recent call last):
Apr 16 05:40:48 deb2 python[1681532]:   File "/home/discord-irc-sync/venv/lib/python3.11/site-packages/discord/client.py", line 441, in _run_ev>
Apr 16 05:40:48 deb2 python[1681532]:     await coro(*args, **kwargs)
Apr 16 05:40:48 deb2 python[1681532]:   File "/home/discord-irc-sync/src/src/discordclient.py", line 178, in on_message
Apr 16 05:40:48 deb2 python[1681532]:     self.h_send_to_irc(username, self.h_format_text(c.strip()))
Apr 16 05:40:48 deb2 python[1681532]:   File "/home/discord-irc-sync/src/src/discordclient.py", line 313, in h_send_to_irc
Apr 16 05:40:48 deb2 python[1681532]:     self.h_send_notification('message', None, content, username)
Apr 16 05:40:48 deb2 python[1681532]:   File "/home/discord-irc-sync/src/src/discordclient.py", line 324, in h_send_notification
Apr 16 05:40:48 deb2 python[1681532]:     connector.get_notification(notif)
Apr 16 05:40:48 deb2 python[1681532]:   File "/home/discord-irc-sync/src/src/ircclient.py", line 201, in get_notification
Apr 16 05:40:48 deb2 python[1681532]:     self.callback[notif.n_type][notif.subtype](notif)
Apr 16 05:40:48 deb2 python[1681532]:   File "/home/discord-irc-sync/src/src/ircclient.py", line 207, in h_send_message
Apr 16 05:40:48 deb2 python[1681532]:     self.h_connection.privmsg(self.h_channel,notif.message)
Apr 16 05:40:48 deb2 python[1681532]:   File "/home/discord-irc-sync/venv/lib/python3.11/site-packages/irc/client.py", line 564, in privmsg
Apr 16 05:40:48 deb2 python[1681532]:     self.send_items('PRIVMSG', target, ':' + text)
Apr 16 05:40:48 deb2 python[1681532]:   File "/home/discord-irc-sync/venv/lib/python3.11/site-packages/irc/client.py", line 595, in send_items
Apr 16 05:40:48 deb2 python[1681532]:     self.send_raw(' '.join(filter(None, items)))
Apr 16 05:40:48 deb2 python[1681532]:   File "/home/discord-irc-sync/venv/lib/python3.11/site-packages/irc/client.py", line 606, in send_raw
Apr 16 05:40:48 deb2 python[1681532]:     sender(self._prep_message(string))
Apr 16 05:40:48 deb2 python[1681532]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^
Apr 16 05:40:48 deb2 python[1681532]:   File "/home/discord-irc-sync/venv/lib/python3.11/site-packages/irc/client.py", line 588, in _prep_messa>
Apr 16 05:40:48 deb2 python[1681532]:     raise MessageTooLong(msg)
Apr 16 05:40:48 deb2 python[1681532]: irc.client.MessageTooLong: Messages limited to 512 bytes including CR/LF
Apr 16 06:01:11 deb2 python[1681532]: [Discord] <aster30999> https://wyz.fr/5P-R6 dans ce code je ne comprends pas pourquoi ma liste_primes est>
Apr 16 06:01:11 deb2 python[1681532]: [2023-04-16 06:01:11] [ERROR   ] discord.client: Ignoring exception in on_message
Apr 16 06:01:11 deb2 python[1681532]: Traceback (most recent call last):
Apr 16 06:01:11 deb2 python[1681532]:   File "/home/discord-irc-sync/venv/lib/python3.11/site-packages/discord/client.py", line 441, in _run_ev>
Apr 16 06:01:11 deb2 python[1681532]:     await coro(*args, **kwargs)
Apr 16 06:01:11 deb2 python[1681532]:   File "/home/discord-irc-sync/src/src/discordclient.py", line 178, in on_message
Apr 16 06:01:11 deb2 python[1681532]:     self.h_send_to_irc(username, self.h_format_text(c.strip()))
Apr 16 06:01:11 deb2 python[1681532]:   File "/home/discord-irc-sync/src/src/discordclient.py", line 313, in h_send_to_irc
Apr 16 06:01:11 deb2 python[1681532]:     self.h_send_notification('message', None, content, username)
Apr 16 06:01:11 deb2 python[1681532]:   File "/home/discord-irc-sync/src/src/discordclient.py", line 324, in h_send_notification
Apr 16 06:01:11 deb2 python[1681532]:     connector.get_notification(notif)
Apr 16 06:01:11 deb2 python[1681532]:   File "/home/discord-irc-sync/src/src/ircclient.py", line 201, in get_notification
Apr 16 06:01:11 deb2 python[1681532]:     self.callback[notif.n_type][notif.subtype](notif)
Apr 16 06:01:11 deb2 python[1681532]:   File "/home/discord-irc-sync/src/src/ircclient.py", line 207, in h_send_message
Apr 16 06:01:11 deb2 python[1681532]:     self.h_connection.privmsg(self.h_channel,notif.message)
Apr 16 06:01:11 deb2 python[1681532]:   File "/home/discord-irc-sync/venv/lib/python3.11/site-packages/irc/client.py", line 564, in privmsg
Apr 16 06:01:11 deb2 python[1681532]:     self.send_items('PRIVMSG', target, ':' + text)
Apr 16 06:01:11 deb2 python[1681532]:   File "/home/discord-irc-sync/venv/lib/python3.11/site-packages/irc/client.py", line 595, in send_items
Apr 16 06:01:11 deb2 python[1681532]:     self.send_raw(' '.join(filter(None, items)))
Apr 16 06:01:11 deb2 python[1681532]:   File "/home/discord-irc-sync/venv/lib/python3.11/site-packages/irc/client.py", line 606, in send_raw
Apr 16 06:01:11 deb2 python[1681532]:     sender(self._prep_message(string))
Apr 16 06:01:11 deb2 python[1681532]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^
Apr 16 06:01:11 deb2 python[1681532]:   File "/home/discord-irc-sync/venv/lib/python3.11/site-packages/irc/client.py", line 588, in _prep_messa>
Apr 16 06:01:11 deb2 python[1681532]:     raise MessageTooLong(msg)
Apr 16 06:01:11 deb2 python[1681532]: irc.client.MessageTooLong: Messages limited to 512 bytes including CR/LF
Apr 16 06:09:51 deb2 python[1681532]: [Discord] <aster30999> j'ai compris mon erreur : le scope de la variable (comme d'hab). Désolé pour le br>

No module named src.ircclient

Traceback (most recent call last):
File "discord-irc-sync.py", line 7, in
from src.ircclient import IRCClient
ImportError: No module named src.ircclient

discord.py 2 broke discord-irc-sync

Looks like the intents Client argument is now mandatory, I'm getting:

Traceback (most recent call last):
   File "/home/discord-irc-sync/src/discord-irc-sync.py", line 16, in <module>
     discord_client = DiscordClient(settings)
                      ^^^^^^^^^^^^^^^^^^^^^^^
   File "/home/discord-irc-sync/src/src/discordclient.py", line 48, in __init__
     super().__init__()
TypeError: Client.__init__() missing 1 required keyword-only argument: 'intents'

While it works with discord.py<2 (which gives discord.py==1.7.3)

I tried to change log_events to false, but it did not work.

    "discord": {
        "server": "",
        "channel": "",
        "token": ".",
        "owner": "sctnightcore",
        "cmd_prefix": "!",
        "output_msg": "<:username:> :message:",
        "output_cmd": "CMD by :username:",
        "log_events": true  > false, and false 
    },
  File "discord-irc-sync.py", line 19, in <module>
    settings = json.loads(f.read())
  File "/usr/lib/python3.5/json/__init__.py", line 319, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.5/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.5/json/decoder.py", line 355, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 23 column 5 (char 712)
(discordirc) root@instance-1:~/discord-irc-sync# 

Messages from Discord are empty with discord.py>2

I upgraded my gate a few minutes ago, on #afpy on libera.chat.

Messages from Discord are now empty see logs: https://logs.afpy.org/archives/2023/04/13

I'm having:

discord-irc-sync@deb2:~$ ./venv/bin/python -m pip list
Package            Version
------------------ -----------
aiohttp            3.7.4.post0
aiosignal          1.3.1
async-timeout      3.0.1
attrs              22.2.0
autocommand        2.2.2
chardet            4.0.0
charset-normalizer 3.1.0
discord            2.2.2
discord.py         2.2.2
frozenlist         1.3.3
idna               3.4
inflect            6.0.2
irc                20.1.0
jaraco.collections 4.0.0
jaraco.context     4.3.0
jaraco.functools   3.6.0
jaraco.logging     3.1.2
jaraco.stream      3.0.3
jaraco.text        3.11.1
more-itertools     9.1.0
multidict          6.0.4
pip                23.0.1
pydantic           1.10.7
pytz               2023.3
setuptools         67.6.1
tempora            5.2.1
typing_extensions  4.5.0
yarl               1.8.2

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.