Skip to content

Commit e46bd37

Browse files
authored
Merge pull request #244 from euank/urban2
modules/ud: switch to more maintained ud impl
2 parents 882af78 + 832d6d3 commit e46bd37

10 files changed

Lines changed: 851 additions & 689 deletions

File tree

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- name: Use Node.js
1515
uses: actions/setup-node@v2
1616
with:
17-
node-version: '8'
17+
node-version: '14'
1818
cache: 'npm'
1919
- name: Install deps
2020
run: sudo apt-get install -y libicu-dev

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:8
1+
FROM node:14
22
COPY . /usr/src/app/
33
WORKDIR /usr/src/app
44

bot.js

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ const changeCase = require('change-case');
88
const SnailEscape = require('snailescape.js');
99
const bunyan = require('bunyan');
1010

11-
let heapdump = null;
12-
1311
const log = bunyan.createLogger({
1412
name: 'euircbot',
1513
serializers: { err: bunyan.stdSerializers.err },
@@ -24,15 +22,6 @@ const bot = {};
2422
bot.util = {}; // Util functions
2523

2624
bot.init = function botInit(cb) {
27-
if (bot.config.heapdump) {
28-
log.debug('enabling heap dumps');
29-
heapdump = require('heapdump');
30-
process.on('SIGINT', () => {
31-
log.warn('dumping heap, if configured, and exiting');
32-
bot.dump();
33-
process.exit();
34-
});
35-
}
3625
bot.configfolder = bot.config.configfolder;
3726
bot.tmpfolder = bot.config.tmpfolder;
3827
bot.datafolder = bot.config.datafolder;
@@ -503,17 +492,6 @@ bot.fsListData = function botFsListData(namespace, listPath, cb) {
503492
fs.readdir(finalPath, cb);
504493
};
505494

506-
bot.dump = function botDump() {
507-
if (heapdump) {
508-
heapdump.writeSnapshot((err, filename) => {
509-
log.warn('heapdump written to', filename);
510-
});
511-
} else {
512-
log.trace('dump called, but heapdump off');
513-
}
514-
};
515-
516-
517495
bot.run = function botRun() {
518496
async.series([
519497
function loadConf(cb) {

config.example.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"port": 6667,
1212
"timeout": 256,
1313
"debug": false,
14-
"heapdump": false,
1514
"mainChannel": "#seubot",
1615
"channels": "#seubot",
1716
"autoRejoin": true,

modules/urbandictionary/index.js

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const urban = require('urban');
1+
const ud = require('urban-dictionary');
22

33
const elems = {
44
ud: ['definition'],
@@ -18,21 +18,16 @@ function usage(command, reply) {
1818
}
1919

2020
function getFirst(command, term, reply) {
21-
let result;
22-
try {
23-
result = urban(term);
24-
} catch (ex) {
25-
reply(`Error getting entry for ${term}`);
26-
}
27-
28-
result.first((json) => {
29-
if (json) {
30-
elems[command].forEach((elem) => {
31-
reply.custom({ lines: 5, replaceNewlines: true, pmExtra: true }, `${elem}: ${json[elem]}`);
32-
});
33-
} else {
34-
reply(`No entry for ${term}`);
21+
ud.define(term).then((results) => {
22+
if (results.length === 0) {
23+
reply(`No results for ${term}`);
24+
return;
3525
}
26+
elems[command].forEach((elem) => {
27+
reply.custom({ lines: 5, replaceNewlines: true, pmExtra: true }, `${elem}: ${results[0][elem]}`);
28+
});
29+
}).catch((error) => {
30+
reply(`Error getting ${term}: ${error.message}`);
3631
});
3732
}
3833

modules/urbandictionary/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "UrbanDictionary module",
55
"main": "index.js",
66
"dependencies": {
7-
"urban": "git+https://github.com/euank/urban.git"
7+
"urban-dictionary": "^3.0.2"
88
},
99
"author": "LinuxMercedes",
1010
"license": "MIT"

0 commit comments

Comments
 (0)