-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
49 lines (47 loc) · 1.94 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* eslint-disable no-empty-function */
const { Plugin } = require('powercord/entities');
module.exports = class SilentType extends Plugin {
startPlugin() {
powercord.api.commands.registerCommand({
command: 'silent-type',
description: 'Keep your typing to yourself!',
usage: '{c} [--toggle|--status]',
executor: (args) => ({
send: false,
result: this.handler(args)
})
})
// Magic
this.callRefresh()
}
handler(args) {
args = args.map(a => a.toLowerCase())
const current = this.settings.get('on')
if ((args.includes('--status') || args.includes('status')) && (args.includes('--toggle') || args.includes('toggle'))) {
return `${this.handler(['--toggle'])}\n${this.handler(['--status'])}`
} else if (args.includes('--toggle') || args.includes('toggle')) {
this.settings.set('on')
return `Changed from ${current ? "`On`": "`Off`"} to ${!current ? "`On`": "`Off`"}`
} else if (args.includes('--status') || args.includes('status')) {
return `Status: \`${current ? "On" : "Off"}\``
} else {
return `${args.length > 0 ? `Incorrect flags \`${args.join('| ')}\` given!\n` : `No Flags given!` }\nPlease run \`${powercord.api.commands.prefix}help silent-type\` for command usage`
}
}
callRefresh() {
try {
const { typing } = require('powercord/webpack');
typing.startTyping = (startTyping => (channel) => setImmediate(() => {
const on = this.settings.get('on')
if (!on) {
startTyping(channel)
}
}))(this.oldStartTyping = typing.startTyping)
} catch (e) {
}
}
pluginWillUnload() {
typing.startTyping = this.oldStartTyping;
powercord.api.commands.unregisterCommand('silent-type')
}
};