From 4783b75b84a2aec29108fb16b829b6c6af4bc994 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Mon, 26 Oct 2015 20:56:00 +0000 Subject: [PATCH] Added text formatting example and fixed newline --- examples/text-formatting.js | 59 +++++++++++++++++++++++++++++++++++++ lib/index.js | 7 ++++- 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 examples/text-formatting.js diff --git a/examples/text-formatting.js b/examples/text-formatting.js new file mode 100644 index 000000000..f08ab8186 --- /dev/null +++ b/examples/text-formatting.js @@ -0,0 +1,59 @@ +/* + this bot will demonstrate text formatting + that you can use +*/ + +var Discord = require("../"); + +// ### to enable text formatting we have to ### +// ### tell discord.js to patch Strings ### + +Discord.patchStrings(); + +// ...and now we can use the awesome formatting! + +// Get the email and password +var AuthDetails = require("./auth.json"); + +var bot = new Discord.Client(); + +bot.on("ready", function () { + console.log("Ready to begin! Serving in " + bot.channels.length + " channels"); +}); + +bot.on("disconnected", function () { + + console.log("Disconnected!"); + process.exit(1); //exit node.js with an error + +}); + +bot.on("message", function (msg) { + if (msg.content == "format") { + + // to format your text bold, do this: + bot.reply(msg, "this is bold".bold); + + // to format your text oblique/italics, do this: + bot.reply(msg, "this is italic".italic); + + // etc: + bot.reply(msg, "this is underlined".underline); + bot.reply(msg, "this is striked through".strike); + bot.reply(msg, "this is inline code".code); + bot.reply(msg, "this is a block of code".codeblock); + bot.reply(msg, "this ends with a newline".newline + "...see!"); + + // you can also chain them! + bot.reply(msg, "this is underlined, italic and bold".underline.italic.bold); + + // in any order + bot.reply(msg, "this is italic, bold, striked and underlined".italic.underline.strike.bold); + + // you can join newlines together easily: + bot.reply(msg, "this is line 1".newline + "this is line 2".newline); + + } +}); + +bot.login(AuthDetails.email, AuthDetails.password); \ No newline at end of file diff --git a/lib/index.js b/lib/index.js index a11654b8e..777aef3be 100644 --- a/lib/index.js +++ b/lib/index.js @@ -18,7 +18,12 @@ Discord.patchStrings = function () { defineProperty("strike", "~~"); defineProperty("code", "`"); defineProperty("codeblock", "```"); - defineProperty("newline", "\n"); + + Object.defineProperty(String.prototype, "newline", { + get: function get() { + return this + "\n"; + } + }); Object.defineProperty(String.prototype, "italic", { get: function get() {