Skip to content

Commit

Permalink
Merge pull request #2 from 67P/feature/update_messages_module
Browse files Browse the repository at this point in the history
Update RS chat-messages module and adapt to new API
  • Loading branch information
raucao authored Sep 13, 2021
2 parents 9217616 + 1fc4eec commit 9d7a484
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 26 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ This Hubot script logs chat messages to remoteStorage-enabled accounts.

* `RS_LOGGER_USER`: RemoteStorage user address
* `RS_LOGGER_TOKEN`: RemoteStorage OAuth bearer token for "chat-messages:rw" scope
* `RS_LOGGER_SERVER_NAME`: Server ID/shortname to be used with remoteStorage (in URLs and metadata), e.g. "freenode"
* `RS_LOGGER_PUBLIC`: Store log files in public folder (doesn't log direct messages)

## Help

If you have a question about this program, please open an issue for this repo
or ask us in #67p or #kosmos on Freenode.
or [chat with us](https://wiki.kosmos.org/Main_Page#Chat).
23 changes: 11 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
/* Description:
* Logs channel messages to a remoteStorage-enabled account
* Logs chat channel messages to a remoteStorage-enabled account
*
* Configuration:
* RS_LOGGER_USER: RemoteStorage user address
* RS_LOGGER_TOKEN: RemoteStorage OAuth bearer token for "chat-messages:rw" scope
* RS_LOGGER_SERVER_NAME: Server ID/shortname to be used with remoteStorage (in URLs and metadata), e.g. "freenode"
* RS_LOGGER_PUBLIC: Store log files in public folder (doesn't log direct messages)
*
* Commands:
*
* Notes:
* Some code translated from hubot-logger
*
Expand All @@ -25,7 +22,7 @@ const RemoteStorage = require("remotestoragejs");
const ChatMessages = require("remotestorage-module-chat-messages");

const remoteStorage = new RemoteStorage({
modules: [ChatMessages.default]
modules: [ ChatMessages ]
});

module.exports = function (robot) {
Expand Down Expand Up @@ -120,7 +117,7 @@ module.exports = function (robot) {
let messages = messageCache[room];

if (messages && messages.length > 0) {
log(`Storing ${messages.length} messages for room ${room}`);
log(`Storing ${messages.length} new messages for room ${room}`);

messageCache[room] = [];
rsAddMessages(room, messages).then(function(){
Expand All @@ -136,23 +133,25 @@ module.exports = function (robot) {

var rsAddMessages = function(room, messages) {
let archive = {
server: {
type: hubotAdapter,
name: process.env.RS_LOGGER_SERVER_NAME
},
date: new Date(messages[0].timestamp),
isPublic: process.env.RS_LOGGER_PUBLIC != null
};

switch (hubotAdapter) {
case 'irc':
archive.channelName = room;
archive.server.ircURI = "irc://" + process.env.HUBOT_IRC_SERVER;
archive.service = {
protocol: 'IRC',
domain: process.env.HUBOT_IRC_SERVER
}
break;
case 'xmpp':
let [roomName, mucHost] = room.split("@");
archive.channelName = roomName;
archive.server.xmppMUC = mucHost;
archive.service = {
protocol: 'XMPP',
domain: mucHost
}
break;
}

Expand Down
34 changes: 24 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
"repository": "https://github.com/67P/hubot-remotestorage-logger",
"dependencies": {
"hubot": "3.x",
"remotestorage-module-chat-messages": "~1.0.1",
"remotestoragejs": "~1.2.2"
"remotestorage-module-chat-messages": "^2.0.0",
"remotestoragejs": "^2.0.0-beta.1"
},
"peerDependencies": {
"hubot": "3.x"
},
"optionalDependencies": {
"fsevents": "^2.3.2"
}
}

0 comments on commit 9d7a484

Please sign in to comment.