Skip to content

Instantly share code, notes, and snippets.

@danny8376
Last active July 4, 2020 05:27
Show Gist options
  • Save danny8376/b0df6dcc78b8f9f6baee5f716d7971e6 to your computer and use it in GitHub Desktop.
Save danny8376/b0df6dcc78b8f9f6baee5f716d7971e6 to your computer and use it in GitHub Desktop.
!!!OUTDATED!!! Use https://github.com/danny8376/DannyAAMBetterDiscordAddons/tree/master/Plugins/VoiceChannelUserJoinNotification instead! A simple BetterDiscord plugin for you to monitor specific users joining voice channels in spcific guilds.
/**
* @name VoiceChannelUserJoinNotification
* @description !!!OUTDATED 舊版本!!! A simple BetterDiscord plugin for you to monitor specific users joining voice channels in spcific guilds. Press Alt + V to open the voice log.
* @displayName VoiceChannelUserJoinNotification
* @authorId 275978619354873856
* @authorLink https://saru.moe/
* @source https://gist.github.com/danny8376/b0df6dcc78b8f9f6baee5f716d7971e6
*/
/* ========================================
* ========================================
* !!! THIS IS AN OUTDATED VERSION !!!
* PLEASE GO TO
* https://github.com/danny8376/DannyAAMBetterDiscordAddons
* FOR NEWER VERSION !
* ----------------------------------------
* !!! 這個是舊版本,已經不會繼續更新 !!!
* 請改到 https://github.com/danny8376/DannyAAMBetterDiscordAddons
* 下載新版本使用
* ========================================
* ========================================
*/
/*@cc_on
@if (@_jscript)
// Offer to self-install for clueless users that try to run this directly.
var shell = WScript.CreateObject("WScript.Shell");
// Put the user at ease by addressing them in the first person
shell.Popup("It looks like you've mistakenly tried to run me directly. \n(Don't do that!)\n\nAlso, this is outdated version. Please go to https://github.com/danny8376/DannyAAMBetterDiscordAddons for downloading newer version!", 0, "I'm a plugin for BetterDiscord & !!!OUTDATED!!!", 0x30);
if (shell.Popup("Should I the new version site for you?", 0, "Do you need some help?", 0x34) === 6) {
shell.Run("https://github.com/danny8376/DannyAAMBetterDiscordAddons/tree/master/Plugins/VoiceChannelUserJoinNotification");
}
WScript.Quit();
@else@*/
class VoiceChannelUserJoinNotification {
constructor() {
this.defaultSettings = {
guilds: "000000000000000000#Example",
users: "000000000000000000#Example,000000000000000000",
allGuilds: false,
notifyLeave: false,
silentNotification: false,
suppressInDnd: true,
logHotkey: true
};
this.monitoringGuilds = [];
this.monitoringUsers = [];
this.afkChannels = [];
this.updatePath = "https://raw.githubusercontent.com/danny8376/DannyAAMBetterDiscordAddons/master/Plugins/VoiceChannelUserJoinNotification/VoiceChannelUserJoinNotification.plugin.js";
}
getName() { return "VoiceChannelUserJoinNotification"; }
getDescription() { return "!!! OUTDATED 舊版本 !!! A simple BetterDiscord plugin for you to monitor specific users joining voice channels in spcific guilds. Press Alt + V to open the voice log. Modified from VoiceChatNotifications by Metalloriff"; }
getVersion() { return "0.0.10"; }
getAuthor() { return "DannyAAM"; }
getChanges() {
return {
"0.0.10":
`
Notifiy outdated, and updated to newer version.
`,
"0.0.9":
`
Avoid notification for AFK channel.
`,
"0.0.8":
`
Always log leaves, optional notification.
`,
"0.0.7":
`
Trim ID for easier settings.
`,
"0.0.6":
`
Fix author name in settings.
`,
"0.0.4":
`
Add ability to monitor all joined guilds, and fix left monitoring.
`,
"0.0.3":
`
Click on notification will transit you to the guild now.
`,
"0.0.2":
`
Fix Auto-Update.
`,
"0.0.1":
`
First public version.
`,
};
}
getLocaleText(id, args) {
switch (NeatoLib.Modules.get(["getLocaleInfo"]).getLocaleInfo().code) {
case "zh-TW":
switch (id) {
case "settingsGuildsTitle":
return "檢查伺服器ID ( , 分隔,ID後可加#註解)";
case "settingsGuildsTooltip":
return "伺服器ID,多組時使用 , 來分隔,ID後可加#註解";
case "settingsUsersTitle":
return "檢查使用者 ( , 分隔,ID後可加#註解)";
case "settingsUsersTooltip":
return "使用<使用者ID>,多組時使用 , 來分隔,ID後可加#註解";
case "settingsAllGuilds":
return "檢查所有已加入伺服器";
case "settingsNotifyLeave":
return "通知退出語音頻道";
case "settingsSilentNofification":
return "使用無聲通知";
case "settingsSuppressInDnd":
return "勿擾模式時關閉通知";
case "settingsLogHotkey":
return "啟用 Alt+V 開啟記錄視窗";
case "notificationJoinMessage":
return `${args.user} 進入了 ${args.channel} @ ${args.guild}`;
case "notificationJoinLog":
return `進入了 ${args.channel} @ ${args.guild}`;
case "notificationMoveMessage":
return `${args.user} 移動到 ${args.channel} @ ${args.guild}`;
case "notificationMoveLog":
return `移動到 ${args.channel} @ ${args.guild}`;
case "notificationLeaveMessage":
return `${args.user} 離開 ${args.channel} @ ${args.guild}`;
case "notificationLeaveLog":
return `離開 ${args.channel} @ ${args.guild}`;
}
case "en-US":
default:
switch (id) {
case "settingsGuildsTitle":
return "Monitoring Guild IDs (seprated with \",\" and append \"#\" after id for commenting)";
case "settingsGuildsTooltip":
return "Guild IDs (seprated with \",\" and append \"#\" after id for commenting)";
case "settingsUsersTitle":
return "Monitoring User IDs (seprated with \",\" and append \"#\" after id for commenting)";
case "settingsUsersTooltip":
return "User IDs (seprated with \",\" and append \"#\" after id for commenting)";
case "settingsAllGuilds":
return "Monitor all guilds";
case "settingsNotifyLeave":
return "Notify user leaves";
case "settingsSilentNofification":
return "Silent notifications";
case "settingsSuppressInDnd":
return "Suppress notifications while in Do Not Disturb";
case "settingsLogHotkey":
return "Enable Alt+V Log Panel";
case "notificationJoinMessage":
return `${args.user} joined ${args.channel} @ ${args.guild}`;
case "notificationJoinLog":
return `Joined ${args.channel} @ ${args.guild}`;
case "notificationMoveMessage":
return `${args.user} moved to ${args.channel} @ ${args.guild}`;
case "notificationMoveLog":
return `Moved to ${args.channel} @ ${args.guild}`;
case "notificationLeaveMessage":
return `${args.user} left ${args.channel} @ ${args.guild}`;
case "notificationLeaveLog":
return `Left ${args.channel} @ ${args.guild}`;
}
}
}
load() {}
start() {
const libLoadedEvent = () => {
try{ this.onLibLoaded(); }
catch(err) { console.error(this.getName(), "fatal error, plugin could not be started!", err); }
};
let lib = document.getElementById("NeatoBurritoLibrary");
if(lib == undefined) {
lib = document.createElement("script");
lib.setAttribute("id", "NeatoBurritoLibrary");
lib.setAttribute("type", "text/javascript");
lib.setAttribute("src", "https://rawgit.com/Metalloriff/BetterDiscordPlugins/master/Lib/NeatoBurritoLibrary.js");
document.head.appendChild(lib);
}
if(typeof window.Metalloriff !== "undefined") libLoadedEvent();
else lib.addEventListener("load", libLoadedEvent);
}
parseMatchlist() {
this.monitoringGuilds = [];
this.monitoringUsers = [];
this.settings.guilds.split(",").forEach(l => {
this.monitoringGuilds.push(l.split("#")[0].trim());
});
this.settings.users.split(",").forEach(l => {
this.monitoringUsers.push(l.split("#")[0].trim());
});
}
getSettingsPanel() {
setTimeout(() => {
NeatoLib.Settings.pushElement(NeatoLib.Settings.Elements.createTextField(this.getLocaleText("settingsGuildsTitle"), "text", this.settings.guilds, evt => {
this.settings.guilds = evt.target.value;
this.parseMatchlist();
this.saveSettings();
}, {
tooltip: this.getLocaleText("settingsGuildsToolltip")
}), this.getName());
NeatoLib.Settings.pushElement(NeatoLib.Settings.Elements.createTextField(this.getLocaleText("settingsUsersTitle"), "text", this.settings.users, evt => {
this.settings.users = evt.target.value;
this.parseMatchlist();
this.saveSettings();
}, {
tooltip: this.getLocaleText("settingsUsersToolltip")
}), this.getName());
NeatoLib.Settings.pushElement(NeatoLib.Settings.Elements.createToggleGroup("vcujn-toggles", "", [
{ title : this.getLocaleText("settingsAllGuilds"), value : "allGuilds", setValue : this.settings.allGuilds },
{ title : this.getLocaleText("settingsNotifyLeave"), value : "notifyLeave", setValue : this.settings.notifyLeave },
{ title : this.getLocaleText("settingsSilentNofification"), value : "silentNotification", setValue : this.settings.silentNotification },
{ title : this.getLocaleText("settingsSuppressInDnd"), value : "suppressInDnd", setValue : this.settings.suppressInDnd },
{ title : this.getLocaleText("settingsLogHotkey"), value : "logHotkey", setValue : this.settings.logHotkey }
], choice => {
this.settings[choice.value] = !this.settings[choice.value];
this.saveSettings();
}), this.getName());
NeatoLib.Settings.pushChangelogElements(this);
}, 0);
return `${NeatoLib.Settings.Elements.pluginNameLabel(this.getName(), this.getAuthor())}`;
}
saveSettings() { NeatoLib.Settings.save(this); }
notificationAndLog({act, user, channel, guild}) {
this.log.push({avatar: user.getAvatarURL(), username: user.username , timestamp : new Date().toLocaleTimeString(), text : this.getLocaleText(`notification${act}Log`, {channel: channel.name, guild: guild.name})});
if(!(this.settings.suppressInDnd && NeatoLib.getLocalStatus() == "dnd") && !this.afkChannels.includes(channel.id) && (act !== "Leave" || this.settings.notifyLeave)) {
const notification = new Notification(this.getLocaleText(`notification${act}Message`, {user: user.username, channel: channel.name, guild: guild.name}), {silent: this.settings.silentNotification, icon: user.getAvatarURL()});
if (act === "Join" || act === "Move") {
notification.addEventListener("click", () => {
NeatoLib.Modules.get("transitionToGuild").transitionToGuild(guild.id);
});
}
}
}
onLibLoaded() {
this.settings = NeatoLib.Settings.load(this, this.defaultSettings);
this.parseMatchlist();
NeatoLib.Updates.check(this, this.updatePath);
if(this.settings.displayUpdateNotes) NeatoLib.Changelog.compareVersions(this.getName(), this.getChanges());
this.log = [];
const getVoiceStates = NeatoLib.Modules.get(["getVoiceState"]).getVoiceStates;
const getUser = NeatoLib.Modules.get(["getUser"]).getUser;
const getChannel = NeatoLib.Modules.get(["getChannel"]).getChannel;
const getGuild = NeatoLib.Modules.get(["getGuild"]).getGuild;
let lastStates = [];
const localUser = NeatoLib.getLocalUser();
this.update = setInterval(() => {
if (!this.settings.allGuilds && this.monitoringGuilds.length == 0) return;
if (this.monitoringUsers.length == 0) return;
const allGuilds = [];
this.afkChannels = [];
Object.values(NeatoLib.Modules.get(["getGuilds"]).getGuilds()).forEach(g => {
allGuilds.push(g.id);
if (g.afkChannelId) this.afkChannels.push(g.afkChannelId);
});
const targetGuilds = this.settings.allGuilds ? allGuilds : this.monitoringGuilds;
const newStates = targetGuilds.map(gid => getVoiceStates(gid)).reduce((a, v) => {return {...v, ...a}});
for(let id in newStates) {
if(localUser.id == id) continue;
if(!this.monitoringUsers.includes(id)) continue;
if(lastStates[id] == undefined) {
const user = getUser(id), channel = getChannel(newStates[id].channelId);
if(user && channel) {
const guild = getGuild(channel.guild_id);
this.notificationAndLog({act: "Join", user, channel, guild});
}
} else {
if(lastStates[id].channelId != newStates[id].channelId) {
const user = getUser(id), channel = getChannel(newStates[id].channelId);
if(user && channel) {
const guild = getGuild(channel.guild_id);
this.notificationAndLog({act: "Move", user, channel, guild});
}
continue;
}
}
}
for(let id in lastStates) {
if(localUser.id == id) continue;
if(!this.monitoringUsers.includes(id)) continue;
if(newStates[id] == undefined && id != localUser.id) {
const user = getUser(id), channel = getChannel(lastStates[id].channelId);
if(user && channel) {
const guild = getGuild(channel.guild_id);
this.notificationAndLog({act: "Leave", user, channel, guild});
}
}
}
lastStates = newStates;
}, 500);
this.focused = true;
this.focus = () => this.focused = true;
this.unfocus = () => this.focused = false;
window.addEventListener("focus", this.focus);
window.addEventListener("blur", this.unfocus);
this.onKeyDown = e => {
if(this.settings.logHotkey && e.altKey && e.key == "v") {
if(document.getElementById("vcn-log")) return;
const list = NeatoLib.UI.createBasicScrollList("vcn-log", "Voice Notification Log", { width : 400, height : 500 });
if(this.log.length > 50) this.log.splice(50, this.log.length);
for(let i = 0; i < this.log.length; i++) {
list.scroller.insertAdjacentHTML("afterbegin", `
<div class="message-group hide-overflow">
<div class="avatar-large stop-animation" style="background-image: url(${this.log[i].avatar});"></div>
<div class="comment">
<div class=NeatoLib.Modules.get("message").message.split(" ").join("")>
<div class="body">
<h2 class="old-h2"><span class="username-wrapper"><strong class="user-name" style="color: white">${this.log[i].username}</strong></span><span class="highlight-separator"> - </span><span class="timestamp">${this.log[i].timestamp}</span></h2>
<div class="message-text">
<div class=NeatoLib.Modules.get("markup").markup.split(" ").join("")>${this.log[i].text}.</div>
</div>
</div>
</div>
</div>
</div>
`);
}
}
};
document.addEventListener("keydown", this.onKeyDown);
NeatoLib.Events.onPluginLoaded(this);
}
stop() {
clearInterval(this.update);
if(this.focus && this.unfocus) {
window.removeEventListener("focus", this.focus);
window.removeEventListener("blur", this.unfocus);
}
if(this.onKeyDown) document.removeEventListener("keydown", this.onKeyDown);
this.ready = false;
}
}
/*@end@*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment