Skip to content

Add Presence System #368

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 3 commits into from
Closed
Changes from all commits
Commits
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
64 changes: 41 additions & 23 deletions lib/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Bot {
this.channels = _.values(options.channelMapping);
this.ircStatusNotices = options.ircStatusNotices;
this.announceSelfJoin = options.announceSelfJoin;
this.alterPresence = options.alterPresence

// Nicks to ignore
this.ignoreUsers = options.ignoreUsers || {};
Expand Down Expand Up @@ -82,32 +83,49 @@ class Bot {

connect() {
logger.debug('Connecting to IRC and Discord');
this.discord.login(this.discordToken);

const ircOptions = {
userName: this.nickname,
realName: this.nickname,
channels: this.channels,
floodProtection: true,
floodProtectionDelay: 500,
retryCount: 10,
autoRenick: true,
// options specified in the configuration file override the above defaults
...this.ircOptions
};
this.discord.login(this.discordToken).then(_ => {
if (this.alterPresence) {
let { secure, port } = this.ircOptions
port = port || 6667
let name = `irc://${this.server}/${secure ? '+' : ''}${port}`

this.discord.user.setPresence({
game: {
type: 'WATCHING',
name
}
})
}

const ircOptions = {
userName: this.nickname,
realName: this.nickname,
channels: this.channels,
floodProtection: true,
floodProtectionDelay: 500,
retryCount: 10,
autoRenick: true,
// options specified in the configuration file override the above defaults
...this.ircOptions
};

// default encoding to UTF-8 so messages to Discord aren't corrupted
if (!Object.prototype.hasOwnProperty.call(ircOptions, 'encoding')) {
if (irc.canConvertEncoding()) {
ircOptions.encoding = 'utf-8';
} else {
logger.warn('Cannot convert message encoding; you may encounter corrupted characters with non-English text.\n' +
'For information on how to fix this, please see: https://github.com/Throne3d/node-irc#character-set-detection');
// default encoding to UTF-8 so messages to Discord aren't corrupted
if (!Object.prototype.hasOwnProperty.call(ircOptions, 'encoding')) {
if (irc.canConvertEncoding()) {
ircOptions.encoding = 'utf-8';
} else {
logger.warn('Cannot convert message encoding; you may encounter corrupted characters with non-English text.\n' +
'For information on how to fix this, please see: https://github.com/Throne3d/node-irc#character-set-detection');
}
}
}

this.ircClient = new irc.Client(this.server, this.nickname, ircOptions);
this.attachListeners();
this.ircClient = new irc.Client(this.server, this.nickname, ircOptions);
this.attachListeners();


});


}

attachListeners() {
Expand Down