Skip to content

Typescript conversion #633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
72108c6
Hastily update to Discord.JS v13 (logging broken)
aronson Aug 23, 2023
abc17ed
Fix webhooks
aronson Aug 24, 2023
d1fc94e
Hack logging to console.log
aronson Aug 24, 2023
dfbebae
Restore broken logging
aronson Aug 24, 2023
7fbfd3c
Add ping everyone perm
aronson Aug 24, 2023
f578cba
Upgrade winston to fix logging
aronson Aug 24, 2023
9a6f800
Upgrade to discord.js v14
aronson Aug 24, 2023
c6d3d7d
Disable broken partial match through config
aronson Aug 24, 2023
837bb2c
Display displayName instead of userName by default if no nickname
aronson Aug 24, 2023
5a4a960
Update logging event marked incorrectly
aronson Aug 24, 2023
cf1a505
Implement /names command from Discord side
aronson Aug 24, 2023
f8df85b
Remove console.log
aronson Aug 24, 2023
20a50b0
Add initial typescript implementation
aronson Aug 24, 2023
be1edae
Fix: use fetch() instead of cache for guild members, fixes many bugs
aronson Aug 25, 2023
0208281
Add tsconfig.json (oops!)
aronson Aug 25, 2023
4d468e6
Remove underscore lib, fix lodash, fixup configs
aronson Aug 25, 2023
13574c7
Remove unknown casts for correctness
aronson Aug 25, 2023
ed3a746
Refactor withMentions into cleaner, broken out methods. Add allowRole…
aronson Aug 25, 2023
f462e9d
Use async calls at handler level
aronson Aug 25, 2023
eb5c251
Further async methods
aronson Aug 25, 2023
d74eb7c
Await sendToIRC
aronson Aug 25, 2023
1dc0b08
Migrate to tsx and typescript-eslint
aronson Aug 25, 2023
50e9c45
Add prettier and run reformat
aronson Aug 25, 2023
48832c4
Add automatic linter and prettier support
aronson Aug 25, 2023
1a2271d
Add attribution to author field of package.json
aronson Aug 25, 2023
4f5b0b2
Remove unused dependencies
aronson Aug 25, 2023
eab0f69
Update minimum node version per discord.js v14
aronson Aug 25, 2023
3b603f8
Add aronson as contributor
aronson Aug 25, 2023
b74a1c4
Further clean up dependencies and add contributor metadata
aronson Aug 25, 2023
c2e593c
Fix dependency on discord.js to allow minor upgrades
aronson Aug 25, 2023
e3ad847
Commit lockfile
aronson Aug 25, 2023
ff3d46d
Remove deprecated encoding warning
aronson Aug 25, 2023
287ad68
Re-enable encoding
aronson Aug 25, 2023
ab280af
Update .gitignore against .eslintcache
aronson Aug 25, 2023
4f34231
Move name to top of package.json
aronson Aug 25, 2023
4eaaef6
Attribute Kage for /names feature
aronson Aug 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions .babelrc

This file was deleted.

19 changes: 0 additions & 19 deletions .eslintrc

This file was deleted.

15 changes: 15 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-env node */
module.exports = {
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
root: true,
rules: {
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};
22 changes: 11 additions & 11 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ name: Publish Docker image

on:
push:
branches: [ main ]
branches: [main]
release:
types: [ published ]
types: [published]

jobs:
push_to_registry:
name: Publish to Docker Hub
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Build and push to Docker Hub
uses: docker/build-push-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: discordirc/discord-irc
tag_with_ref: true
tag_with_sha: true
- uses: actions/checkout@v2
- name: Build and push to Docker Hub
uses: docker/build-push-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: discordirc/discord-irc
tag_with_ref: true
tag_with_sha: true
47 changes: 22 additions & 25 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,42 @@ name: Node.js CI

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]

jobs:
test:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x, 14.x, 15.x, 16.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build --if-present
- run: npm test
- run: npm run save-coverage
- name: Report to Coveralls (parallel)
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
flag-name: run-${{ matrix.node-version }}
parallel: true
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build --if-present
- run: npm test
- run: npm run save-coverage
- name: Report to Coveralls (parallel)
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
flag-name: run-${{ matrix.node-version }}
parallel: true

finish:

needs: test
runs-on: ubuntu-latest

steps:
- name: Report to Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true

- name: Report to Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@ config.json

# Build
dist/

# Husky
.husky

# Eslint
.eslintcache
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test/fixtures/invalid-json-config.json
1 change: 1 addition & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
319 changes: 215 additions & 104 deletions CHANGELOG.md

Large diffs are not rendered by default.

116 changes: 72 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
> Connects [Discord](https://discord.com/) and [IRC](https://www.ietf.org/rfc/rfc1459.txt) channels by sending messages back and forth.

## Example

![discord-irc](http://i.imgur.com/oI6iCrf.gif)

## Installation and usage

**Note**: discord-irc requires Node.js version 12 or newer, as it depends on [discord.js](https://github.com/hydrabolt/discord.js).
Future versions may require newer Node.js versions, though we should support active releases.

Expand All @@ -32,13 +34,15 @@ $ npm start -- --config /path/to/config.json # Note the extra double dash
```

It can also be used as a module:

```js
import discordIRC from 'discord-irc';
import config from './config.json';
discordIRC(config);
```

## Docker

As an alternative to running discord-irc directly on your machine, we provide a [Docker container image](https://hub.docker.com/r/discordirc/discord-irc).
After creating a configuration file, you can fetch the image from Docker Hub and run it with the following command:

Expand All @@ -57,80 +61,100 @@ Note that the path to the config file on the host (`/path/to/config`) _must_ be
Otherwise, you may get the error "illegal operation on a directory".

## Configuration

First you need to create a Discord bot user, which you can do by following the instructions [here](https://github.com/reactiflux/discord-irc/wiki/Creating-a-discord-bot-&-getting-a-token).

### Example configuration

```js
[
// Bot 1 (minimal configuration):
{
"nickname": "test2",
"server": "irc.testbot.org",
"discordToken": "botwantsin123",
"channelMapping": {
"#other-discord": "#new-irc-channel"
}
nickname: 'test2',
server: 'irc.testbot.org',
discordToken: 'botwantsin123',
channelMapping: {
'#other-discord': '#new-irc-channel',
},
},

// Bot 2 (advanced options):
{
"nickname": "test",
"server": "irc.bottest.org",
"discordToken": "botwantsin123",
"autoSendCommands": [ // Commands that will be sent on connect
["PRIVMSG", "NickServ", "IDENTIFY password"],
["MODE", "test", "+x"],
["AUTH", "test", "password"]
nickname: 'test',
server: 'irc.bottest.org',
discordToken: 'botwantsin123',
autoSendCommands: [
// Commands that will be sent on connect
['PRIVMSG', 'NickServ', 'IDENTIFY password'],
['MODE', 'test', '+x'],
['AUTH', 'test', 'password'],
],
"channelMapping": { // Maps each Discord-channel to an IRC-channel, used to direct messages to the correct place
"#discord": "#irc channel-password", // Add channel keys after the channel name
"1234567890": "#channel" // Use a discord channel ID instead of its name (so you can rename it or to disambiguate)
channelMapping: {
// Maps each Discord-channel to an IRC-channel, used to direct messages to the correct place
'#discord': '#irc channel-password', // Add channel keys after the channel name
1234567890: '#channel', // Use a discord channel ID instead of its name (so you can rename it or to disambiguate)
},
"ircOptions": { // Optional node-irc options
"floodProtection": false, // On by default
"floodProtectionDelay": 1000, // 500 by default
"port": "6697", // 6697 by default
"secure": true, // enable SSL, false by default
"sasl": true, // false by default
"username": "test", // nodeirc by default
"password": "p455w0rd" // empty by default
ircOptions: {
// Optional node-irc options
floodProtection: false, // On by default
floodProtectionDelay: 1000, // 500 by default
port: '6697', // 6697 by default
secure: true, // enable SSL, false by default
sasl: true, // false by default
username: 'test', // nodeirc by default
password: 'p455w0rd', // empty by default
},
"format": { // Optional custom formatting options
format: {
// Optional custom formatting options
// Patterns, represented by {$patternName}, are replaced when sending messages
"commandPrelude": "Command sent by {$nickname}", // Message sent before a command
"ircText": "<{$displayUsername}> {$text}", // When sending a message to IRC
"urlAttachment": "<{$displayUsername}> {$attachmentURL}", // When sending a Discord attachment to IRC
"discord": "**<{$author}>** {$withMentions}", // When sending a message to Discord
commandPrelude: 'Command sent by {$nickname}', // Message sent before a command
ircText: '<{$displayUsername}> {$text}', // When sending a message to IRC
urlAttachment: '<{$displayUsername}> {$attachmentURL}', // When sending a Discord attachment to IRC
discord: '**<{$author}>** {$withMentions}', // When sending a message to Discord
// Other patterns that can be used:
// {$discordChannel} (e.g. #general)
// {$ircChannel} (e.g. #irc)
"webhookAvatarURL": "https://robohash.org/{$nickname}" // Default avatar to use for webhook messages
webhookAvatarURL: 'https://robohash.org/{$nickname}', // Default avatar to use for webhook messages
},
"ircNickColor": false, // Gives usernames a color in IRC for better readability (on by default)
"ircNickColors": ['light_blue', 'dark_blue', 'light_red', 'dark_red', 'light_green', 'dark_green', 'magenta', 'light_magenta', 'orange', 'yellow', 'cyan', 'light_cyan'], // Which irc-upd colors to use
"parallelPingFix": true, // Prevents users of both IRC and Discord from being mentioned in IRC when they speak in Discord (off by default)
ircNickColor: false, // Gives usernames a color in IRC for better readability (on by default)
ircNickColors: [
'light_blue',
'dark_blue',
'light_red',
'dark_red',
'light_green',
'dark_green',
'magenta',
'light_magenta',
'orange',
'yellow',
'cyan',
'light_cyan',
], // Which irc-upd colors to use
parallelPingFix: true, // Prevents users of both IRC and Discord from being mentioned in IRC when they speak in Discord (off by default)
// Makes the bot hide the username prefix for messages that start
// with one of these characters (commands):
"commandCharacters": ["!", "."],
"ircStatusNotices": true, // Enables notifications in Discord when people join/part in the relevant IRC channel
"ignoreUsers": {
"irc": ["irc_nick1", "irc_nick2"], // Ignore specified IRC nicks and do not send their messages to Discord.
"discord": ["discord_nick1", "discord_nick2"], // Ignore specified Discord nicks and do not send their messages to IRC.
"discordIds": ["198528216523210752"] // Ignore specified Discord ids and do not send their messages to IRC.
commandCharacters: ['!', '.'],
ircStatusNotices: true, // Enables notifications in Discord when people join/part in the relevant IRC channel
ignoreUsers: {
irc: ['irc_nick1', 'irc_nick2'], // Ignore specified IRC nicks and do not send their messages to Discord.
discord: ['discord_nick1', 'discord_nick2'], // Ignore specified Discord nicks and do not send their messages to IRC.
discordIds: ['198528216523210752'], // Ignore specified Discord ids and do not send their messages to IRC.
},
// List of webhooks per channel
"webhooks": {
"#discord": "https://discord.com/api/webhooks/id/token"
}
}
]
webhooks: {
'#discord': 'https://discord.com/api/webhooks/id/token',
},
},
];
```

The `ircOptions` object is passed directly to irc-upd ([available options](https://node-irc-upd.readthedocs.io/en/latest/API.html#irc.Client)).

To retrieve a discord channel ID, write `\#channel` on the relevant server – it should produce something of the form `<#1234567890>`, which you can then use in the `channelMapping` config.

### Webhooks

Webhooks lets you override nicknames and avatars, so messages coming from IRC
can appear as regular Discord messages:

Expand All @@ -148,18 +172,22 @@ discord-irc's config as follows:
```

### Encodings

If you encounter trouble with some characters being corrupted from some clients (particularly umlauted characters, such as `ä` or `ö`), try installing the optional dependencies `iconv` and `node-icu-charset-detector`.
The bot will produce a warning when started if the IRC library is unable to convert between encodings.

Further information can be found in [the installation section of irc-upd](https://github.com/Throne3d/node-irc#character-set-detection).

## Tests

Run the tests with:

```bash
$ npm test
```

## Style Guide

discord-irc follows the [Airbnb Style Guide](https://github.com/airbnb/javascript).
[ESLint](http://eslint.org/) is used to make sure this is followed correctly, which can be run with:

Expand Down
Loading