File size: 8,830 Bytes
5c2ed06
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var announcements_exports = {};
__export(announcements_exports, {
  Announcement: () => Announcement,
  commands: () => commands
});
module.exports = __toCommonJS(announcements_exports);
class Announcement extends Rooms.MinorActivity {
  constructor(room, options) {
    super(room);
    this.activityid = "announcement";
    this.name = "Announcement";
    this.activityNumber = options.activityNumber || room.nextGameNumber();
    this.source = options.source;
    this.setTimer(options);
  }
  generateAnnouncement() {
    return `<div class="broadcast-blue"><p style="margin: 2px 0 5px 0"><strong style="font-size:11pt">${this.source}</strong></p></div>`;
  }
  displayTo(user, connection = null) {
    const recipient = connection || user;
    recipient.sendTo(this.room, `|uhtml|announcement${this.activityNumber}|${this.generateAnnouncement()}`);
  }
  display() {
    const announcement = this.generateAnnouncement();
    for (const id in this.room.users) {
      const thisUser = this.room.users[id];
      thisUser.sendTo(this.room, `|uhtml|announcement${this.activityNumber}|${announcement}`);
    }
  }
  onConnect(user, connection = null) {
    this.displayTo(user, connection);
  }
  destroy() {
    this.room.send(`|uhtmlchange|announcement${this.activityNumber}|<div class="infobox">(${this.room.tr`The announcement has ended.`})</div>`);
    this.room.setMinorActivity(null);
  }
  toJSON() {
    return {
      source: this.source,
      activityNumber: this.activityNumber,
      timeoutMins: this.timeoutMins,
      timerEnd: this.timerEnd,
      activityid: "announcement"
    };
  }
  save() {
    this.room.settings.minorActivity = this.toJSON();
    this.room.saveSettings();
  }
}
const commands = {
  announcement: {
    htmlcreate: "new",
    create: "new",
    new(target, room, user, connection, cmd, message) {
      room = this.requireRoom();
      if (!target)
        return this.parse("/help announcement new");
      target = target.trim();
      if (room.battle)
        return this.errorReply(this.tr`Battles do not support announcements.`);
      const text = this.filter(target);
      if (target !== text)
        return this.errorReply(this.tr`You are not allowed to use filtered words in announcements.`);
      const supportHTML = cmd === "htmlcreate";
      this.checkCan("minigame", null, room);
      if (supportHTML)
        this.checkCan("declare", null, room);
      this.checkChat();
      if (room.minorActivity) {
        return this.errorReply(this.tr`There is already a poll or announcement in progress in this room.`);
      }
      const source = supportHTML ? this.checkHTML(Chat.collapseLineBreaksHTML(target)) : Chat.formatText(target, true);
      room.setMinorActivity(new Announcement(room, { source }));
      this.roomlog(`${user.name} used ${message}`);
      this.modlog("ANNOUNCEMENT");
      return this.privateModAction(room.tr`An announcement was started by ${user.name}.`);
    },
    newhelp: [`/announcement create [announcement] - Creates an announcement. Requires: % @ # ~`],
    htmledit: "edit",
    edit(target, room, user, connection, cmd, message) {
      room = this.requireRoom();
      const announcement = this.requireMinorActivity(Announcement);
      if (!target)
        return this.parse("/help announcement edit");
      target = target.trim();
      const text = this.filter(target);
      if (target !== text)
        return this.errorReply(this.tr`You are not allowed to use filtered words in announcements.`);
      const supportHTML = cmd === "htmledit";
      this.checkCan("minigame", null, room);
      if (supportHTML)
        this.checkCan("declare", null, room);
      this.checkChat();
      const source = supportHTML ? this.checkHTML(Chat.collapseLineBreaksHTML(target)) : Chat.formatText(target, true);
      announcement.source = source;
      announcement.save();
      this.roomlog(`${user.name} used ${message}`);
      this.modlog("ANNOUNCEMENT EDIT");
      this.privateModAction(room.tr`The announcement was edited by ${user.name}.`);
      this.parse("/announcement display");
    },
    edithelp: [`/announcement edit [announcement] - Edits the announcement. Requires: % @ # ~`],
    timer(target, room, user) {
      room = this.requireRoom();
      const announcement = this.requireMinorActivity(Announcement);
      if (target) {
        this.checkCan("minigame", null, room);
        if (target === "clear") {
          if (!announcement.endTimer())
            return this.errorReply(this.tr`There is no timer to clear.`);
          return this.add(this.tr`The announcement timer was turned off.`);
        }
        const timeoutMins = parseFloat(target);
        if (isNaN(timeoutMins) || timeoutMins <= 0 || timeoutMins > 7 * 24 * 60) {
          return this.errorReply(this.tr`Time should be a number of minutes less than one week.`);
        }
        announcement.setTimer({ timeoutMins });
        room.add(`The announcement timer was turned on: the announcement will end in ${timeoutMins} minute${Chat.plural(timeoutMins)}.`);
        this.modlog("ANNOUNCEMENT TIMER", null, `${timeoutMins} minutes`);
        return this.privateModAction(`The announcement timer was set to ${timeoutMins} minute${Chat.plural(timeoutMins)} by ${user.name}.`);
      } else {
        if (!this.runBroadcast())
          return;
        if (announcement.timeout) {
          return this.sendReply(`The announcement timer is on and will end in ${announcement.timeoutMins} minute${Chat.plural(announcement.timeoutMins)}.`);
        } else {
          return this.sendReply(this.tr`The announcement timer is off.`);
        }
      }
    },
    timerhelp: [
      `/announcement timer [minutes] - Sets the announcement to automatically end after [minutes] minutes. Requires: % @ # ~`,
      `/announcement timer clear - Clears the announcement's timer. Requires: % @ # ~`
    ],
    close: "end",
    stop: "end",
    end(target, room, user) {
      room = this.requireRoom();
      this.checkCan("minigame", null, room);
      this.checkChat();
      const announcement = this.requireMinorActivity(Announcement);
      announcement.end(room);
      this.modlog("ANNOUNCEMENT END");
      this.privateModAction(room.tr`The announcement was ended by ${user.name}.`);
    },
    endhelp: [`/announcement end - Ends a announcement and displays the results. Requires: % @ # ~`],
    show: "",
    display: "",
    ""(target, room, user, connection) {
      room = this.requireRoom();
      const announcement = this.requireMinorActivity(Announcement);
      if (!this.runBroadcast())
        return;
      room.update();
      if (this.broadcasting) {
        announcement.display();
      } else {
        announcement.displayTo(user, connection);
      }
    },
    displayhelp: [`/announcement display - Displays the announcement`]
  },
  announcementhelp: [
    `/announcement allows rooms to run their own announcements. These announcements are limited to one announcement at a time per room.`,
    `Accepts the following commands:`,
    `/announcement create [announcement] - Creates a announcement. Requires: % @ # ~`,
    `/announcement htmlcreate [announcement] - Creates a announcement, with HTML allowed. Requires: # ~`,
    `/announcement edit [announcement] - Edits the announcement. Requires: % @ # ~`,
    `/announcement htmledit [announcement] - Edits the announcement, with HTML allowed. Requires: # ~`,
    `/announcement timer [minutes] - Sets the announcement to automatically end after [minutes]. Requires: % @ # ~`,
    `/announcement display - Displays the announcement`,
    `/announcement end - Ends a announcement. Requires: % @ # ~`
  ]
};
process.nextTick(() => {
  Chat.multiLinePattern.register("/announcement (new|create|htmlcreate|edit|htmledit) ");
});
for (const room of Rooms.rooms.values()) {
  if (room.settings.minorActivity?.activityid === "announcement") {
    room.setMinorActivity(new Announcement(room, room.settings.minorActivity), true);
  }
}
//# sourceMappingURL=announcements.js.map