Giter VIP home page Giter VIP logo

urban's Introduction

urban

The Urban Dictionary program and library for node.js. The API is official, but undocumented.

installation

$ npm install -g urban # bin
$ npm install urban # lib

examples

bin

$ urban facepalm
$ urban -r // random mode

lib

var urban = require('urban'),
    trollface = urban('trollface');

trollface.first(function(json) {
    console.log(json);
});


// Random mode
var urban = require('urban');

urban.random().first(function(json) {
    console.log(json);
});

license

MIT

urban's People

Contributors

euank avatar jpinkney avatar linuxmercedes avatar markzalar avatar mvrilo avatar rgroli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

urban's Issues

multi-word entries?

Am I right in thinking this doesn't support multi-word entries, e.g. "presidential flashcards"?

Possible API change broke urban node module

This command has been working forever with no issues, today though I got an error, as I have not changed my code, and it's an error within the node module, I think the API must have changed.

My Code:

const { del } = require("../../functions.js");
const urban = require("urban");
const { MessageEmbed } = require("discord.js");
const { stripIndents } = require("common-tags");

module.exports = {
    name: "urban",
    aliases: ["urb", "urbandictionary", "ud"],
    category: "fun",
    description: "Gets an urban dictionary definition",
    usage: "[search <term> | random]",
    permissions: "member",
    run: (client, message, args) => {
        if (!args[0] || !["search", "random"].includes(args[0]))
            return message.reply("Please provide <search|random> (query).").then(m => del(m, 7500));
        let search = args[1] ? urban(args.slice(1).join(" ")) : urban.random();
        try {
            search.first(res => {
                if (!res) return message.reply("No results found for this topic, sorry!").then(m => del(m, 7500));
                let { word, definition, example, thumbs_up, thumbs_down, permalink, author } = res;

                let description = stripIndents`**Defintion:** ${definition || "No definition"}
                    **Example:** ${example || "No Example"}
                    **Upvote:** ${thumbs_up || 0}
                    **Downvote:** ${thumbs_down || 0}
                    **Link:** [link to ${word}](${permalink || "https://www.urbandictionary.com/"})`

                if (description.length >= 1024)
                    return message.reply("This definition is too long of a string for a message embed sorry!").then(m => del(m, 7500));
                else {
                    let embed = new MessageEmbed()
                        .setColor("#0efefe")
                        .setAuthor(`Urban Dictionary | ${word}`, image)
                        .setDescription(description)
                        .setTimestamp()
                        .setFooter(`Written by ${author || "unknown"}`);

                    message.channel.send(embed)
                }
            });
        } catch (err) {
            return message.channel.send(`Error while searching... ${err}`).then(m => del(m, 7500));
        }
    }
}

Error Caught by my process.on(uncaughtExcemption) event not the catch statement:

10-05-2021 12-18-44 A new uncaughtExcemption error: SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at IncomingMessage.<anonymous> (C:\Users\amp56\Documents\Projects\Comicallybot2.0\node_modules\urban\lib\urban.js:83:24)
    at IncomingMessage.emit (events.js:412:35)
    at endReadableNT (internal/streams/readable.js:1317:12)
    at processTicksAndRejections (internal/process/task_queues.js:82:21) at: uncaughtException

How to get an array of search results

The npm description does not explain too much about how to use this package so Im going to ask here.

If I wanted to get an array of search results for a search term, how would i go about doing that?

SyntaxError: Unexpected end of JSON input

Hello, I am using this package for my discord bot which uses Discord.js v13. Upon using it I get this error:

[ERROR] SyntaxError: Unexpected end of JSON input at JSON.parse (<anonymous>) at IncomingMessage.<anonymous> (C:\Users\User\Desktop\Durchie v13\node_modules\urban\lib\urban.js:83:24) at IncomingMessage.emit (node:events:406:35) at endReadableNT (node:internal/streams/readable:1331:12) at processTicksAndRejections (node:internal/process/task_queues:83:21)

Any idea why?

the API url that getData forms no longer seems to work

When I do this:

var urban = require('urban'),
    catfish = urban('catfish');

catfish.first(function(json) {
    console.log(json);
});

Dictionary.fn.getData @ https://github.com/mvrilo/urban/blob/master/lib/urban.js#L66

The above script will create a URL for the GET request and it doesn't work anymore
http://api.urbandictionary.com/v0/define?page=undefined&term=catfish

However

if you remove page=undefined though, it works
http://api.urbandictionary.com/v0/define?term=catfish

Is anyone else experiencing this? this lib just completely stopped working for me recently and it's just for this small reason.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.