Skip to content
This repository was archived by the owner on Jul 17, 2020. It is now read-only.

Commit 3c45680

Browse files
author
Zirak
committed
merged #147
1 parent a0d447c commit 3c45680

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

master.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,7 @@ bot.Command = function ( cmd ) {
10171017
cmd.del = function () {
10181018
bot.info.forgotten += 1;
10191019
delete bot.commands[ cmd.name ];
1020+
bot.commandDictionary.trie.del(cmd.name);
10201021
};
10211022

10221023
return cmd;
@@ -1539,6 +1540,24 @@ TrieNode.prototype.add = function( word ) {
15391540
node.word = word;
15401541
};
15411542

1543+
TrieNode.prototype.del = function(word, i) {
1544+
i = i || 0;
1545+
var node = this;
1546+
var char = word[i++];
1547+
1548+
// recursively delete all trie nodes that are left empty after removing the command from the leaf
1549+
if (node.children[char]) {
1550+
node.children[char].del(word, i);
1551+
if (Object.keys(node.children[char].children).length === 0 && node.children[char].word === null) {
1552+
delete node.children[char];
1553+
}
1554+
}
1555+
1556+
if (node.word === word) {
1557+
node.word = null;
1558+
}
1559+
}
1560+
15421561
//Having a small maxCost will increase performance greatly, experiment with
15431562
//values of 1-3
15441563
function SuggestionDictionary ( maxCost ) {

0 commit comments

Comments
 (0)