Skip to content

Instantly share code, notes, and snippets.

@jiangzhuo
Created August 18, 2019 11:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jiangzhuo/793f6d120607bb71f30c45f4fa6ea00a to your computer and use it in GitHub Desktop.
Save jiangzhuo/793f6d120607bb71f30c45f4fa6ea00a to your computer and use it in GitHub Desktop.
discord stalker plugin
//META{"name":"Stalker"}*//
// !!! Hey there! If you didn't come here from the BetterDiscord Discord server ( https://discord.gg/2HScm8j ) !!! //
// !!! then please do not use whatever you were using that led you here, getting plugins from places other than !!! //
// !!! the #plugin repo channel in the BD server can be dangerous, as they can be malicious and do bad things. !!! //
class Stalker {
getName() {
return "Stalker";
}
getDescription() {
return "Get notifications when certain author posted.";
}
getVersion() {
return "0.0.1";
}
getAuthor() {
return "jiangzhuo";
}
load() {
this.getChannelById = BdApi.findModuleByProps('getChannel').getChannel;
this.getServerById = BdApi.findModuleByProps('getGuild').getGuild;
this.transitionTo = BdApi.findModuleByProps('transitionTo').transitionTo;
this.isMuted = BdApi.findModuleByProps('isGuildOrCategoryOrChannelMuted').isGuildOrCategoryOrChannelMuted.bind(BdApi.findModuleByProps('isGuildOrCategoryOrChannelMuted'));
this.isBlocked = BdApi.findModuleByProps('isBlocked').isBlocked;
this.getUnreadCount = BdApi.findModuleByProps('getUnreadCount').getUnreadCount;
this.currentChannel = BdApi.findModuleByProps("getChannelId").getChannelId;
this.userId = BdApi.findModuleByProps('getId').getId();
}
start() {
this.cancelPatch = BdApi.monkeyPatch(BdApi.findModuleByProps("dispatch"), 'dispatch', { after: this.dispatch.bind(this) });
this.author = BdApi.loadData('Stalker', 'author') || [];
this.blacklist = BdApi.loadData('Stalker', 'blacklist') || [];
}
stop() {
this.cancelPatch();
}
escapeRegex(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
dispatch(data) {
if (!this.author.length)
return;
// if(data.methodArguments[0].message.channel_id ==='611195682606416018')
// console.log(data.methodArguments[0].type)
if (data.methodArguments[0].type !== 'MESSAGE_CREATE')
return;
const message = data.methodArguments[0].message;
// if (this.blacklist.includes(message.guild_id))
// return;
if (this.currentChannel() === message.channel_id && require('electron').remote.getCurrentWindow().isFocused())
return;
// if (this.isMuted(message.guild_id, message.channel_id))
// return;
const author = message.author;
// if (message.author.id === this.userId)
// return;
// if (this.isBlocked(author.id))
// return;
let content = message.content;
let proceed = false;
if (!this.author.includes(message.author.id))
return
// this.author.forEach(word => {
// const regex = new RegExp(`\\b${this.escapeRegex(word)}\\b`, 'gi');
// const replaced = content.replace(regex, match => `→${match}←`);
// if (replaced !== content) {
// proceed = true;
// content = replaced;
// }
// });
// if (!proceed)
// return;
const channel = this.getChannelById(message.channel_id);
const server = this.getServerById(message.guild_id);
// const notification = new Notification(`${server.name ? `${server.name} #` : ''}${channel.name} (${this.getUnreadCount(channel.id)} unread)`, { body: `${author.username}: ${content}` });
// notification.addEventListener('click', _ => {
// this.goToMessage(server.id, channel.id, message.id);
// });
let avatar = BDFDB.getUserAvatar(message.author.id);
let string = `${BDFDB.encodeToHTML(message.author.username)} posted.`;
let toast = BDFDB.showToast(`<div class="toast-inner"><div class="toast-avatar" style="background-image:url(${avatar});"></div><div>${string}</div></div>`, {html:true, timeout:5000, type:"success", icon:false, selector:'stalkernotifications-post-toast'});
toast.addEventListener("click", _ => {
this.goToMessage(server.id, channel.id, message.id);
});
let audio = new Audio();
audio.src = 'https://fsb.zobj.net/download/b-lpPOH1S72ws42RgF4DgPlFrL7NmEap6ZwnFO209RUauHqYHWpFjCk63TIkDQRuesE8hTDF0HvN_uiA4WEeE39Lio6ejyLn5rwTJBTR21AWsNJulbE-uu4_b8gg/?a=web&c=72&f=no_no.mp3&special=1566124200-hlfM3QH2apYcFavmmQSRqVocmABOVVOQCW9GeV8EafQ%3D';
audio.play();
}
goToMessage(server, channel, message) {
require('electron').remote.getCurrentWindow().focus();
this.transitionTo(`/channels/${server ? server : '@me'}/${channel}/${message}`);
requestAnimationFrame(() => this.transitionTo(`/channels/${server ? server : '@me'}/${channel}/${message}`));
}
getSettingsPanel() {
const div = document.createElement('div');
const authorT = document.createElement('h6');
const author = document.createElement('textarea');
const br = document.createElement('br');
const button = document.createElement('button');
button.innerText = 'Apply';
button.style.cssFloat = 'right';
button.style.backgroundColor = '#3E82E5';
button.style.color = 'white';
button.style.fontSize = '100%';
authorT.innerText = 'Author';
author.placeholder = 'Insert list of userId to be notified about (Comma separated, e.g. "612598115240771594,458490722975350785,592727857374167072").';
author.value = this.author.join(',');
author.style.width = '100%';
author.style.minHeight = '6ch';
author.style.color = 'black';
author.style.backgroundColor = 'white';
button.addEventListener('click', _ => {
this.author = author.value.split(',').map(e => e.trim());
BdApi.saveData('Stalker', 'author', this.author);
document.getElementById('plugin-settings-Stalker').previousSibling.click();
});
div.appendChild(authorT);
div.appendChild(author);
div.appendChild(br);
div.appendChild(button);
return div;
}
}
@rodeka1
Copy link

rodeka1 commented Nov 8, 2021

Hello! What about keeping track of which voice channel the person is entering?

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