Skip to main content

A Discord wrapper for miniirc.

Project description

miniirc_discord

Available on PyPI.

A wrapper for miniirc (GitHub, GitLab) to allow bots or clients made in miniirc to connect to (proprietary) Discord servers via discord.py with minimal code changes.

How to use

To use miniirc_discord, you already need to know how to use miniirc (GitHub, GitLab). Instead of creating a miniirc.IRC object, however, you need to use miniirc_discord.Discord. This is very similar, however has some differences:

  • miniirc_discord.Discord objects are created with miniirc_discord.Discord('TOKEN').
  • There is a stateless_mode keyword argument.
  • The discord_client attribute returns an instance of discord.Client, or None if stateless_mode is enabled.
  • There is a get_server_count() method which returns the number of guilds the bot is in.

Channels will start in # if they are public and are currently just a channel ID.

Some formatting from IRC to Discord should be translated nicely, however more complex codes and formatting from Discord to IRC are currently not.

Your bot will need to be able to request the "message content" intent for miniirc_discord to work properly.

Stateless mode

The stateless_mode keyword argument will instruct discord.py to disable the user cache and any intents not required by miniirc_discord. This should be enabled if you are not using discord_client to cut back on memory and bandwidth usage.

Since miniirc_discord 0.6.0, the stateless_mode keyword argument is True by default.

Example

TOKEN = os.environ['DISCORD_TOKEN']

irc = miniirc_discord.Discord(TOKEN)
channel = irc.discord_client.get_channel(channel_id)  # Error!

# Disabling stateless mode will add a "discord_client" attribute
irc = miniirc_discord.Discord(TOKEN, stateless_mode=False)
channel = irc.discord_client.get_channel(channel_id)  # No error

Supported commands

PRIVMSG

PRIVMSG operates like you'd expect and IRC formatting codes are converted to markdown. You cannot, however, send messages to a channel before the bot has received a message from the channel.

CTCP ACTION (irc.me())

This works similarly to PRIVMSG, except the CTCP ACTION is also converted to a Discord /me.

NOTICE

NOTICEs are converted into embeds by miniirc_discord. To set an embed title, you can add a bold line to the start of the embed:

irc.notice(channel, '\x02Embed title\x02\nEmbed content')

You can add an IRC colour code to the start of the line to set the embed colour:

# Green embed
irc.notice(channel, '\x033\x02Embed title\x02\x03\nEmbed content')

# Light blue embed
irc.notice(channel, '\x0312\x02Embed title\x02\x03\nEmbed content')

Older versions of miniirc_discord had a non-standard IRCv3 tag to set the embed title. This is still supported, however you should switch to the above syntax when possible.

TAGMSG

You can add reactions to messages using the +draft/react message tag.

Example:

@irc.Handler('PRIVMSG', colon=False, ircv3=True)
def handle_privmsg(irc, hostmask, tags, args):
    if args[1] == '$react':
        irc.send('TAGMSG', args[0], tags={
            '+draft/reply': tags.get('msgid'),
            '+draft/react': '🆗️'
        })

AWAY

AWAY will set the bot's "Playing" text. If you want to change the prefix to something else, you can set the non-standard IRCv3 client tag +discordapp.com/type to (Playing, Streaming, Listening to or Watching). The +discordapp.com/status tag can be set to 'online', 'idle', 'dnd' or 'invisible'.

Installation and setting up

You can install miniirc_discord with pip. On Linux-based systems, you would do sudo pip3 install miniirc_discord. Version numbers should follow SemVer since 0.4.0 and are no longer in sync with miniirc.

Getting a bot token

To get a Discord bot token and invite link, see this guide. Make sure you enable the message content intent in the bot settings page.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

miniirc_discord-0.6.0.tar.gz (9.0 kB view hashes)

Uploaded Source

Built Distribution

miniirc_discord-0.6.0-py3-none-any.whl (9.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page