Skip to content

Instantly share code, notes, and snippets.

@notmike101
Created March 9, 2017 01:10
Show Gist options
  • Save notmike101/857bee4000af620b4673825ab1d48b08 to your computer and use it in GitHub Desktop.
Save notmike101/857bee4000af620b4673825ab1d48b08 to your computer and use it in GitHub Desktop.
A self-bot embedded inside a BetterDiscord plugin that allows you to use the rich-text/embed feature.
//META{"name":"EmbedText"}*//
/* HOW TO USE:
COMMAND: /embed (color:#000000) (title:"Title") Text Content
Ex: /embed color:#ff0000 title:"This is the title" This is the text
This will create an embed with a red color and with a title saying "This is the title" with textsaying "This is the text".
Color can be any hex color.
Title MUST be wrapped in double quotes.
v2 will allow for both single and double quotes.
*/
var EmbedText = function(){};
EmbedText.prototype.load = function() {
EmbedText.prototype.getKey = function(){
if(bdStorage.get('token') == '') {
var DiscordLocalStorageProxy = document.createElement('iframe');
DiscordLocalStorageProxy.style.display = 'none';
DiscordLocalStorageProxy.id = 'DiscordLocalStorageProxy';
document.body.appendChild(DiscordLocalStorageProxy);
var token = DiscordLocalStorageProxy.contentWindow.localStorage.token.replace(/"/g, "");
console.log(token);
bdStorage.set('token',token);
delete DiscordLocalStorageProxy;
} else {
return bdStorage.get('token');
}
};
EmbedText.prototype.sendEmbed = function(title, text, color) {
var channelID = window.location.pathname.split('/').pop();
var embed = {
type : "rich",
description : text
};
if (color) {
embed.color = color;
}
if (title) {
embed.title = title;
}
var data = JSON.stringify({embed : embed});
$.ajax({
type : "POST",
url : "https://discordapp.com/api/channels/" + channelID + "/messages",
headers : {
"authorization": EmbedText.prototype.getKey()
},
dataType : "json",
contentType : "application/json",
data: data,
error: (req, error, exception) => {
console.log(req.responseText);
}
});
}
};
EmbedText.prototype.unload = function() {};
EmbedText.prototype.start = function() {
this.attachHandler();
};
EmbedText.prototype.onSwitch = function() {
this.attachHandler();
};
EmbedText.prototype.stop = function() {
var el = $('.channel-textarea textarea');
if (el.length == 0) return;
el.unbind("click focus", this.focusHandler);
el[0].removeEventListener("keydown", this.handleKeypress);
};
EmbedText.prototype.getName = function() {
return "EmbedText Plugin";
};
EmbedText.prototype.getDescription = function() {
return "A self-bot embedded inside a BetterDiscord plugin that allows you to use the rich-text/embed feature.";
};
EmbedText.prototype.getVersion = function() {
return "1.0";
};
EmbedText.prototype.getAuthor = function() {
return '<a href="https://github.com/IRDeNial" target="_BLANK">DeNial</a>';
};
EmbedText.prototype.attachHandler = function() {
if($('.channel-textarea textarea').length == 0) return;
$('.channel-textarea textarea')[0].addEventListener("keydown", function(e){
var code = e.keyCode || e.which;
if (code !== 13) {
return;
}
var text = $(this).val();
if(text.startsWith('/embed')) {
e.preventDefault();
e.stopPropagation();
var color;
var title;
var msg = text.replace('/embed','');
if(text.indexOf('color:#') != -1) {
color = text.match(/color\:#([a-zA-Z0-9]+)/)[1];
}
if(text.indexOf('title:"') != -1) {
title = text.match(/title\:\"(.*)\"/)[1];
}
msg = msg.replace('color:#' + color,'');
msg = msg.replace('title:"' + title + '"','');
msg = msg.replace(/\s+/g, ' ');
EmbedText.prototype.sendEmbed(title,msg,parseInt(color,16));
$(this).val("");
} else {
return;
}
}, false);
}
@believeinyuna
Copy link

hey, how do you insert a link break?

/embed color:#000000 title:"Test"
Test
Test
Test

^ like so? when i try it, it just lines them up next to each other. shift+enter & alt+enter don't work.
thanks.

@comicsads
Copy link

It's not working for me, tried copying your example, tried recreating it letter by letter. Not working. Yes the Plugin is enabled

@KrisNorrell
Copy link

same here

@KrisNorrell
Copy link

not working at all

@TheFireBlast
Copy link

i rewrote this plugin so that it works.
i'll update this comment when i post it on github

@VeH-c
Copy link

VeH-c commented Feb 22, 2018

i have found one that works(as of posting), also it grabs your Security Token for you 🥇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment