Skip to content

Commit 9387bca

Browse files
authored
Merge branch 'master' into master
2 parents 05e7ccd + ef553d3 commit 9387bca

File tree

7 files changed

+2982
-3295
lines changed

7 files changed

+2982
-3295
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
# Changelog
22
This project adheres to [Semantic Versioning](http://semver.org/).
33

4+
## [2.7.1] - 2019-06-15
5+
### Changed
6+
* Upgraded dependencies.
7+
8+
## [2.7.0] - 2019-04-02
9+
### Changed
10+
* Convert channel mentions to codified mentions (thanks to [Throne3d](https://github.com/reactiflux/discord-irc/pull/476)).
11+
* Match IRC style mentions at the beginning of message (thanks to [rdb](https://github.com/reactiflux/discord-irc/pull/470)).
12+
* Upgraded dependencies.
13+
414
## [2.6.2] - 2018-09-19
515
### Changed
616
* Upgraded dependencies.

lib/bot.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import { ConfigurationError } from './errors';
66
import { validateChannelMapping } from './validators';
77
import { formatFromDiscordToIRC, formatFromIRCToDiscord } from './formatting';
88

9+
// Usernames need to be between 2 and 32 characters for webhooks:
10+
const USERNAME_MIN_LENGTH = 2;
11+
const USERNAME_MAX_LENGTH = 32;
12+
913
const REQUIRED_FIELDS = ['server', 'nickname', 'channelMapping', 'discordToken'];
1014
const NICK_COLORS = ['light_blue', 'dark_blue', 'light_red', 'dark_red', 'light_green',
1115
'dark_green', 'magenta', 'light_magenta', 'orange', 'yellow', 'cyan', 'light_cyan'];
@@ -471,12 +475,14 @@ class Bot {
471475
// skips usernames including spaces for ease (they cannot include hashes)
472476
// checks case insensitively as Discord does
473477
const user = guild.members.find(x =>
474-
Bot.caseComp(x.user.username, username.toUpperCase())
478+
Bot.caseComp(x.user.username, username)
475479
&& x.user.discriminator === discriminator);
476480
if (user) return user;
477481

478482
return match;
479-
}).replace(/@([^\s]+)/g, (match, reference) => {
483+
}).replace(/^([^@\s:,]+)[:,]|@([^\s]+)/g, (match, startRef, atRef) => {
484+
const reference = startRef || atRef;
485+
480486
// this preliminary stuff is ultimately unnecessary
481487
// but might save time over later more complicated calculations
482488
// @nickname => mention, case insensitively
@@ -535,15 +541,24 @@ class Bot {
535541
if (emoji) return emoji;
536542

537543
return match;
544+
}).replace(/#([^\s#@'!?,.]+)/g, (match, channelName) => {
545+
// channel names can't contain spaces, #, @, ', !, ?, , or .
546+
// (based on brief testing. they also can't contain some other symbols,
547+
// but these seem likely to be common around channel references)
548+
549+
// discord matches channel names case insensitively
550+
const chan = guild.channels.find(x => Bot.caseComp(x.name, channelName));
551+
return chan || match;
538552
});
539553

540554
// Webhooks first
541555
const webhook = this.findWebhook(channel);
542556
if (webhook) {
543557
logger.debug('Sending message to Discord via webhook', withMentions, channel, '->', `#${discordChannel.name}`);
544558
const avatarURL = this.getDiscordAvatar(author, channel);
559+
const username = _.padEnd(author.substring(0, USERNAME_MAX_LENGTH), USERNAME_MIN_LENGTH, '_');
545560
webhook.client.sendMessage(withMentions, {
546-
username: author,
561+
username,
547562
text,
548563
avatarURL
549564
}).catch(logger.error);

0 commit comments

Comments
 (0)