Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General Improvments #11

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 webtax-gh
Copyright (c) 2021 Wolfhound905

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# userid-info
A powercord plugin to quickly get info about a userid.
A powercord plugin to quickly get info about a user.

## Join my server
Join this server for support & really anything [discord.gg/5nAw2C5Y2e](https://discord.gg/5nAw2C5Y2e)

Usage: `.userid <userid>`

Example:
![img](https://i.imgur.com/LcU37Ge.png)
Usage: `.userinfo <userid | mention>` or right click a user.

Example:\
![image](https://user-images.githubusercontent.com/58155937/141900956-0f8277de-9875-459d-b605-f870b02acafb.png)
236 changes: 156 additions & 80 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,83 +1,159 @@
const { Plugin } = require('powercord/entities');
const { React, getModule, channels } = require('powercord/webpack')
const { inject, uninject } = require('powercord/injector');
const { findInReactTree, getOwnerInstance } = require('powercord/util');

class UserIDInfo extends Plugin {
startPlugin() {
powercord.api.commands.registerCommand({
command: 'userid',
aliases: ['useridinfo', 'idinfo'],
label: 'UserID Info',
usage: '{c} <id>',
description: 'Lookup user info from a user id',
executor: (id) => {
if (id.toString().includes('@')) {
id = id.toString().split('!').pop().split('>')[0]
}
return this.getInfo(id)
}
})
}

async getInfo(id) {
try {
let userObject = await (await require('powercord/webpack').getModule(['acceptAgreements', 'getUser'])).getUser(String(id));
let userName = userObject['username'] + '#' + userObject['discriminator'];
let avatarURL = 'https://cdn.discordapp.com/avatars/' + id + '/' + userObject['avatar'];
let isBot = String(userObject['bot']);
let unixTime = (id / 4194304) + 1420070400000;
let jsTime = new Date(unixTime);
let humanTime = (jsTime.getMonth()+1) + '/' + jsTime.getDate() + '/' + jsTime.getFullYear();
function timeDifference(current,previous){var msPerMinute=60*1000;var msPerHour=msPerMinute*60;var msPerDay=msPerHour*24;var msPerMonth=msPerDay*30;var msPerYear=msPerDay*365;var elapsed=current-previous;if(elapsed<msPerMinute){return Math.round(elapsed/1000)+' seconds ago'}else if(elapsed<msPerHour){return Math.round(elapsed/msPerMinute)+' minutes ago'}else if(elapsed<msPerDay){return Math.round(elapsed/msPerHour)+' hours ago'}else if(elapsed<msPerMonth){return 'approximately '+Math.round(elapsed/msPerDay)+' days ago'}else if(elapsed<msPerYear){return 'approximately '+Math.round(elapsed/msPerMonth)+' months ago'}else{return 'approximately '+Math.round(elapsed/msPerYear)+' years ago'}}
let currentTime = Date.now();
let relativeTime = timeDifference(currentTime,unixTime)
const embed = {
type: 'rich',
title: `UserID Lookup for ${userName}`,
thumbnail: {
url: avatarURL,
proxy_url: avatarURL,
height: 128,
width: 128
},
fields: [{
name: 'ID',
value: `${id}`,
inline: false
}, {
name: 'Tag',
value: `<@${id}>`,
inline: false
}, {
name: 'Username',
value: userName,
inline: false
}, {
name: 'Bot',
value: `${isBot}`,
inline: false
}, {
name: 'Avatar',
value: avatarURL,
inline: false
}, {
name: 'Created',
value: humanTime+' (' +relativeTime+')',
inline: false
}]
}
return {
result: embed,
embed: true
}
} catch (err) {
return {
result: 'Incorrect UserID.'
}
}
}

pluginWillUnload() {
powercord.api.commands.unregisterCommand('userid');
}
}
const { createBotMessage } = getModule(["createBotMessage"], false);
const { receiveMessage } = getModule(["receiveMessage"], false);

const { OutputManager } = require('./utils');

class UserInfo extends Plugin {
constructor() {
super();
this.OutputManager = new OutputManager('User Info', {});
}

async startPlugin() {
powercord.api.commands.registerCommand({
command: 'userinfo',
aliases: ['useridinfo', 'idinfo', 'userinfo'],
label: 'User Info',
usage: '{c} <id | mention>',
description: 'Lookup user info from an ID or Mention',
executor: (id) => {
if (id.toString().includes('@')) {
id = id.toString().split('!').pop().split('>')[0]
}
return this.getInfo(id)
}
})

const Menu = await getModule(['MenuItem']);
inject('user-info', Menu, 'default', (args) => {
const [{ navId, children }] = args;
if (navId !== 'user-context') {
return args;
}

const hasUserInfo = findInReactTree(children, child => child.props && child.props.id === 'get-user-info');
if (!hasUserInfo) {
let user;

if (document.querySelector('#user-context')) {
const instance = getOwnerInstance(document.querySelector('#user-context'));
user = (instance?._reactInternals || instance?._reactInternalFiber)?.return?.memoizedProps?.user;
if (document.querySelector('#user-context').getBoundingClientRect().bottom > window.innerHeight) {
(instance?._reactInternals || instance?._reactInternalFiber)?.return.memoizedProps.onHeightUpdate();
}
}

if (!user) {
return args;
}
const getUserInfo = React.createElement(Menu.MenuItem, {
id: 'get-user-info',
label: 'User Info',
action: async () => {
try {
if (channels.getChannelId()) {

module.exports = UserIDInfo;
const userInfo = await this.getInfo(user.id);
const received = createBotMessage(channels.getChannelId(), "");
if (userInfo.embed) {
received.embeds = [userInfo.result];
} else {
received.content = userInfo.result;
}
return receiveMessage(received.channel_id, received);
} else {
this.OutputManager.error("Not looking at any channel")
}
} catch (err) {
console.log(err)
this.OutputManager.error(err)
}
}

});

const devmodeItem = findInReactTree(children, child => child.props && child.props.id === 'devmode-copy-id');
const developerGroup = children.find(child => child.props && child.props.children === devmodeItem);
if (developerGroup) {
if (!Array.isArray(developerGroup.props.children)) {
developerGroup.props.children = [developerGroup.props.children];
}

developerGroup.props.children.push(getUserInfo);
} else {
children.push([React.createElement(Menu.MenuSeparator), React.createElement(Menu.MenuGroup, {}, getUserInfo)]);
}
}
return args;
}, true);

Menu.default.displayName = 'Menu';

}

async getInfo(id) {
try {
let userObject = await (await require('powercord/webpack').getModule(['acceptAgreements', 'getUser'])).getUser(String(id));
let userName = userObject['username'] + '#' + userObject['discriminator'];
let avatarURL = 'https://cdn.discordapp.com/avatars/' + id + '/' + userObject['avatar'];
let isBot = String(userObject['bot']);
let unixTime = Math.round(((id / 4194304) + 1420070400000) / 1000); // Converts to Discord unix timestamp
const embed = {
type: 'rich',
color: userObject["accentColor"],
author: {
name: userName,
url: `discord://-/users/${id}`,
icon_url: avatarURL,
proxy_icon_url: avatarURL,
},
thumbnail: {
url: avatarURL,
proxy_url: avatarURL,
height: 128,
width: 128
},
fields: [{
name: 'ID',
value: `\`${id}\``,
inline: true
}, {
name: 'Username',
value: userName + ` (<@${id}>)`,
inline: false
}, {
name: 'Bot',
value: `${isBot}`,
inline: false
}, {
name: 'Avatar',
value: `[Link](${avatarURL})`,
inline: true
}, {
name: 'Account Created',
value: `<t:${unixTime}:f> (<t:${unixTime}:R>)`,
inline: false
}]
}
return {
result: embed,
embed: true
}
} catch (err) {
return {
result: 'Not a valid user or ID'
}
}
}

pluginWillUnload() {
powercord.api.commands.unregisterCommand('userinfo');
uninject('user-info')
}
}
module.exports = UserInfo;
12 changes: 6 additions & 6 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "UserID Info",
"description": "Grabs info about a UserID and then shows it to you.",
"author": "webtax#9393",
"version": "1.2.0",
"license": "MIT"
}
"name": "User Info",
"description": "Grabs info about a User and then shows it to you.",
"author": "Wolfhound905#1234",
"version": "1.3.1",
"license": "MIT"
}
50 changes: 50 additions & 0 deletions utils/OutputManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
module.exports = class OutputManager {
constructor(startID, settings) {
this.settings = settings;
this.startID = startID;
}

success(msg) {
const button = {
text: 'OK',
color: 'green',
size: 'medium',
look: 'outlined'
};

if (this.settings.hideSuccessToasts) {
return;
}
this._main(msg, 'success', [button]);
}

error(msg, actions = []) {
const buttons = [
{
text: 'okay',
color: 'red',
size: 'medium',
look: 'outlined'
},
...actions.map((action) => ({
size: 'medium',
look: 'outlined',
...action
}))
];

this._main(msg, 'danger', buttons);
}

_main(content, type, buttons) {
const id = Math.random().toString(10).substr(2);
powercord.api.notices.sendToast(`${this.startID}-${id}`, {
header: 'User Info',
content,
type,
buttons
});
}
};

// thanks to https://github.dev/powerfart-plugins/translation-option
7 changes: 7 additions & 0 deletions utils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require('fs')
.readdirSync(__dirname)
.filter((file) => file !== 'index.js')
.forEach((filename) => {
const moduleName = filename.split('.')[0];
exports[moduleName] = require(`${__dirname}/${filename}`);
});