Skip to content

Commit

Permalink
Merge pull request #1 from p0358/master
Browse files Browse the repository at this point in the history
Fixes to issues which led the module to not work properly
  • Loading branch information
Matthew Knox authored Jun 10, 2016
2 parents 0944832 + efce143 commit 2f3a899
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
20 changes: 11 additions & 9 deletions assocfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ exports.match = function(event, commandPrefix) {
var s = event.body.toLowerCase();
for (var assoc in exports.config[event.thread_id]) {
if (s.indexOf(assoc.toLowerCase()) !== -1) {
if (!event.__assocateCmd) {
event.__associatedCmd = {
if (!event.__associateCmd) {
event.__associateCmd = {
thread: event.thread_id,
responses: []
};
Expand All @@ -22,10 +22,12 @@ exports.match = function(event, commandPrefix) {

var toggleAssociation = function(thread, hook, text) {
hook = hook.toLowerCase();
if (exports.config[thread] && exports.config[thread][hook] && !text) {
delete exports.config[thread][hook];
return false;
}
if (!text) {
if (exports.config[thread] && exports.config[thread][hook]) {
delete exports.config[thread][hook];
}
return false;
}

if (!exports.config[thread]) {
exports.config[thread] = {};
Expand Down Expand Up @@ -60,8 +62,8 @@ exports.run = function(api, event) {
}

if (!isCommand && event.__associateCmd) {
for (var i = 0; i < event.__assocateCmd.responses.length; i++) {
api.sendImage("file", event.__associatedCmd.responses[i], event.thread_id);
for (var i = 0; i < event.__associateCmd.responses.length; i++) {
api.sendImage("file", event.__associateCmd.responses[i], "", event.thread_id);
}
return;
}
Expand All @@ -70,6 +72,6 @@ exports.run = function(api, event) {
return api.sendMessage('Invalid arguments, use /help assocfile for help.', event.thread_id);
}

toggleAssociation(event.thread_id, event.arguments[1], event.arguments[3]);
toggleAssociation(event.thread_id, event.arguments[1], event.arguments[2]);
api.sendMessage('Association of file changed.', event.thread_id);
};
2 changes: 1 addition & 1 deletion kassy.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "assocfile",
"version": 1.1,
"version": 1.2,
"startup": "assocfile.js",
"help": [
["{{commandPrefix}}assocfile \"<hook>\" \"<file_name>\" or clear", "Associate and disassociate a file with a phrase.", "Associate and disassociate a file like image, video or audio (from ~\\files directory) with a phrase (so that a file is sent on a given phrase in chat)."]
Expand Down

0 comments on commit 2f3a899

Please sign in to comment.