summaryrefslogtreecommitdiff
path: root/index.js
blob: 1d8caf82b6905e4c77dbdf7df46b610b3244a7bc (plain)
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
const { Plugin } = require('powercord/entities');
const Settings = require('./Settings.jsx');
const manifest = require('./manifest.json');
const { getModule } = require('powercord/webpack');
const {
  inject,
  uninject
} = require('powercord/injector');
const { lookup } = require('./tz');

const { transformMessageArray } = require('./transformation.jsx');

const PLUGIN_ID = 'timezone-powercord';
const INJECTION_ID_MESSAGE_RENDER = PLUGIN_ID + '-message-render';

const MessageContent = getModule((m) => m.type && m.type.displayName === 'MessageContent', false);


module.exports = class TimezonePowercord extends Plugin {
  async startPlugin () {
    inject(INJECTION_ID_MESSAGE_RENDER, MessageContent, 'type', (args) => {
      return transformMessageArray(
        () => lookup(this.settings.get('timezone', 'GMT')))(args);
    }, true);
    powercord.api.notices.sendAnnouncement('timezone-request-tz', {
      color: 'green',
      message: 'Timezone Powercord Plugin has been loaded.'
    });
    powercord.api.settings.registerSettings(PLUGIN_ID, {
      category: this.entityID,
      label: 'Timezone Powercord Plugin',
      render: Settings
    });
  }

  async pluginWillUnload () {
    uninject(INJECTION_ID_MESSAGE_RENDER);
    powercord.api.settings.unregisterSettings(this.entityID);
  }

};