Skip to content

Commit

Permalink
Enable Imgur by default.
Browse files Browse the repository at this point in the history
Don't send Telegram documents to IRC to mask bot api key.
  • Loading branch information
Tjzabel authored and jwflory committed Feb 23, 2019
1 parent 228bbe2 commit ac76ede
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions config.js
Expand Up @@ -8,6 +8,7 @@ let settings = {
channel: process.env.IRC_CHANNEL || "",
botName: process.env.IRC_BOT_NAME || "teleirc",
sendStickerEmoji: process.env.IRC_SEND_STICKER_EMOJI === "true" || true,
sendDocument: process.env.IRC_SEND_DOCUMENT === "true" || false,
prefix: process.env.IRC_PREFIX || "<",
suffix: process.env.IRC_SUFFIX || ">",
showJoinMessage: process.env.IRC_SHOW_JOIN_MESSAGE === "true" || true,
Expand Down
3 changes: 2 additions & 1 deletion env.example
Expand Up @@ -10,6 +10,7 @@ IRC_BLACKLIST=""
IRC_BOT_NAME=teleirc
IRC_CHANNEL=#channel
IRC_SEND_STICKER_EMOJI=true
IRC_SEND_DOCUMENT=false
IRC_PREFIX="<"
IRC_SUFFIX=">"
IRC_SERVER=chat.freenode.net
Expand Down Expand Up @@ -40,7 +41,7 @@ TELEGRAM_CHAT_ID=-0000000000000
# #
###############################################################################

USE_IMGUR_FOR_IMAGES=false
USE_IMGUR_FOR_IMAGES=true
IMGUR_CLIENT_ID=0000000000


Expand Down
4 changes: 2 additions & 2 deletions lib/TeleIrc.js
Expand Up @@ -331,10 +331,10 @@ class TeleIrc {
this.tgbot.on('message', teleirc.tgEventListener.ParseMessage.bind(teleirc.tgEventListener));
this.tgbot.on('edited_message', teleirc.tgEventListener.ParseEditedMessage.bind(teleirc.tgEventListener));

// ---- Setup Telegram Handlers ----
// ---- Set up Telegram Handlers ----

this.tgDocumentHandler = new TgDocumentHandler(
true,
this.config.sendDocument,
this.tgbot,
this.sendMessageToIrc.bind(this)
);
Expand Down
18 changes: 12 additions & 6 deletions lib/TelegramHandlers/TgDocumentHandler.js
Expand Up @@ -30,14 +30,19 @@ class TgDocumentHandler {
*/
async RelayDocumentMessage(from, document) {
if (!this.Enabled) {
return;
}
let username = TgHelpers.ResolveUserName(from);
let message = username +
" shared a file on Telegram with caption: 'test'";
// TODO get caption of document

this._action(message);

let username = TgHelpers.ResolveUserName(from);
} else {
let username = TgHelpers.ResolveUserName(from);

let url = await this._tgbot.getFileLink(document.file_id);
let url = await this._tgbot.getFileLink(document.file_id);

let message = username +
let message = username +
" Posted File: " +
document.file_name +
" (" +
Expand All @@ -47,7 +52,8 @@ class TgDocumentHandler {
" bytes): " +
url;

this._action(message);
this._action(message);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/TelegramHandlers/TgMessageHandler.js
Expand Up @@ -40,6 +40,7 @@ class TgMessageHandler {
const messagePrefix = self._ircConfig.prefix + username + self._ircConfig.suffix + " ";
const messageSplitRegex = new RegExp(`.\{1,${self._ircConfig.maxMessageLength - messagePrefix.length}}`, 'g');

// split messages based on max message length, and prepend username on each new line
userMessage.toString().split(/\r?\n/).filter(function(line) {
return line.length > 0;
}).forEach(function(line) {
Expand Down
2 changes: 1 addition & 1 deletion lib/TelegramHandlers/TgPhotoHandler.js
Expand Up @@ -28,7 +28,7 @@ class TgPhotoHandler {
*
* @param {*} from - Object that contains the information about the user name.
* @param {*} photoList - The information about the photos we can get from Telegram.
* @param {string} - The caption of the photo, if any.
* @param {string} caption - The caption of the photo, if any.
*/
async RelayPhotoMessage(from, photoList, caption) {
if (!this.Enabled) {
Expand Down

0 comments on commit ac76ede

Please sign in to comment.