Skip to content

Instantly share code, notes, and snippets.

@Rejdukien
Forked from notmike101/EmbedText.plugin.js
Last active September 9, 2017 17:42
Show Gist options
  • Save Rejdukien/d51bb1025fafda97dbeea6df3ece6ffb to your computer and use it in GitHub Desktop.
Save Rejdukien/d51bb1025fafda97dbeea6df3ece6ffb 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-text-area-default textarea').length == 0) return;
$('.channel-text-area-default 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 = "ff00ff";
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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment