Unverified Commit 429f6463 authored by Bradley Hilton's avatar Bradley Hilton
Browse files

Update the Apps to use the promises

parent 07d081d5
......@@ -7,5 +7,13 @@
"url": "./app-schema.json"
}
],
"tslint.exclude": ["**node_modules**"]
"tslint.exclude": [
"**node_modules**"
],
"files.exclude": {
".server/": true,
".server-data/": true,
".site/": true,
".tmp/": true
}
}
......@@ -21,24 +21,24 @@ export class AsciiArtCommandsApp extends App {
private flipId = 'flip_cmd';
private unflipId = 'unflip_cmd';
public onEnable(environmentRead: IEnvironmentRead, configModify: IConfigurationModify): boolean {
public async onEnable(environmentRead: IEnvironmentRead, configModify: IConfigurationModify): Promise<boolean> {
const sets = environmentRead.getSettings();
this.enableOrDisableCommand(this.gimmeId, sets.getValueById(this.gimmeId), configModify);
this.enableOrDisableCommand(this.lennyId, sets.getValueById(this.lennyId), configModify);
this.enableOrDisableCommand(this.shrugId, sets.getValueById(this.shrugId), configModify);
this.enableOrDisableCommand(this.flipId, sets.getValueById(this.flipId), configModify);
this.enableOrDisableCommand(this.unflipId, sets.getValueById(this.unflipId), configModify);
await this.enableOrDisableCommand(this.gimmeId, await sets.getValueById(this.gimmeId), configModify);
await this.enableOrDisableCommand(this.lennyId, await sets.getValueById(this.lennyId), configModify);
await this.enableOrDisableCommand(this.shrugId, await sets.getValueById(this.shrugId), configModify);
await this.enableOrDisableCommand(this.flipId, await sets.getValueById(this.flipId), configModify);
await this.enableOrDisableCommand(this.unflipId, await sets.getValueById(this.unflipId), configModify);
return true;
}
public onSettingUpdated(setting: ISetting, configModify: IConfigurationModify, read: IRead, http: IHttp): void {
this.enableOrDisableCommand(setting.id, setting.value as boolean, configModify);
public async onSettingUpdated(setting: ISetting, configModify: IConfigurationModify, read: IRead, http: IHttp): Promise<void> {
await this.enableOrDisableCommand(setting.id, setting.value as boolean, configModify);
}
protected extendConfiguration(configuration: IConfigurationExtend): void {
configuration.settings.provideSetting({
protected async extendConfiguration(configuration: IConfigurationExtend): Promise<void> {
await configuration.settings.provideSetting({
id: this.gimmeId,
type: SettingType.BOOLEAN,
packageValue: true,
......@@ -48,7 +48,7 @@ export class AsciiArtCommandsApp extends App {
i18nDescription: 'Enable_Gimme_Command_Description',
});
configuration.settings.provideSetting({
await configuration.settings.provideSetting({
id: this.lennyId,
type: SettingType.BOOLEAN,
packageValue: true,
......@@ -58,7 +58,7 @@ export class AsciiArtCommandsApp extends App {
i18nDescription: 'Enable_Lenny_Command_Description',
});
configuration.settings.provideSetting({
await configuration.settings.provideSetting({
id: this.shrugId,
type: SettingType.BOOLEAN,
packageValue: true,
......@@ -68,7 +68,7 @@ export class AsciiArtCommandsApp extends App {
i18nDescription: 'Enable_Shrug_Command_Description',
});
configuration.settings.provideSetting({
await configuration.settings.provideSetting({
id: this.flipId,
type: SettingType.BOOLEAN,
packageValue: true,
......@@ -78,7 +78,7 @@ export class AsciiArtCommandsApp extends App {
i18nDescription: 'Enable_Tableflip_Command_Description',
});
configuration.settings.provideSetting({
await configuration.settings.provideSetting({
id: this.unflipId,
type: SettingType.BOOLEAN,
packageValue: true,
......@@ -88,48 +88,48 @@ export class AsciiArtCommandsApp extends App {
i18nDescription: 'Enable_Unflip_Table_Command_Description',
});
configuration.slashCommands.provideSlashCommand(new GimmeCommand());
configuration.slashCommands.provideSlashCommand(new LennyCommand());
configuration.slashCommands.provideSlashCommand(new ShrugCommand());
configuration.slashCommands.provideSlashCommand(new TableflipCommand());
configuration.slashCommands.provideSlashCommand(new UnflipCommand());
await configuration.slashCommands.provideSlashCommand(new GimmeCommand());
await configuration.slashCommands.provideSlashCommand(new LennyCommand());
await configuration.slashCommands.provideSlashCommand(new ShrugCommand());
await configuration.slashCommands.provideSlashCommand(new TableflipCommand());
await configuration.slashCommands.provideSlashCommand(new UnflipCommand());
}
private enableOrDisableCommand(id: string, doEnable: boolean, configModify: IConfigurationModify): void {
private async enableOrDisableCommand(id: string, doEnable: boolean, configModify: IConfigurationModify): Promise<void> {
switch (id) {
case this.gimmeId:
if (doEnable) {
configModify.slashCommands.enableSlashCommand(GimmeCommand.CommandName);
await configModify.slashCommands.enableSlashCommand(GimmeCommand.CommandName);
} else {
configModify.slashCommands.disableSlashCommand(GimmeCommand.CommandName);
await configModify.slashCommands.disableSlashCommand(GimmeCommand.CommandName);
}
return;
case this.lennyId:
if (doEnable) {
configModify.slashCommands.enableSlashCommand(LennyCommand.CommandName);
await configModify.slashCommands.enableSlashCommand(LennyCommand.CommandName);
} else {
configModify.slashCommands.disableSlashCommand(LennyCommand.CommandName);
await configModify.slashCommands.disableSlashCommand(LennyCommand.CommandName);
}
return;
case this.shrugId:
if (doEnable) {
configModify.slashCommands.enableSlashCommand(ShrugCommand.CommandName);
await configModify.slashCommands.enableSlashCommand(ShrugCommand.CommandName);
} else {
configModify.slashCommands.disableSlashCommand(ShrugCommand.CommandName);
await configModify.slashCommands.disableSlashCommand(ShrugCommand.CommandName);
}
return;
case this.flipId:
if (doEnable) {
configModify.slashCommands.enableSlashCommand(TableflipCommand.CommandName);
await configModify.slashCommands.enableSlashCommand(TableflipCommand.CommandName);
} else {
configModify.slashCommands.disableSlashCommand(TableflipCommand.CommandName);
await configModify.slashCommands.disableSlashCommand(TableflipCommand.CommandName);
}
return;
case this.unflipId:
if (doEnable) {
configModify.slashCommands.enableSlashCommand(UnflipCommand.CommandName);
await configModify.slashCommands.enableSlashCommand(UnflipCommand.CommandName);
} else {
configModify.slashCommands.disableSlashCommand(UnflipCommand.CommandName);
await configModify.slashCommands.disableSlashCommand(UnflipCommand.CommandName);
}
return;
}
......
......@@ -3,8 +3,8 @@
"name": "ASCII Art Commands",
"nameSlug": "asciiart-commands",
"description": "Provides neat little asciiart commands for fun usage.",
"version": "1.0.1",
"requiredApiVersion": ">=0.6.1",
"version": "1.0.2",
"requiredApiVersion": ">=0.9.6",
"author": {
"name": "Bradley Hilton",
"homepage": "https://github.com/graywolf336/temporary-apps-dev-environment",
......
......@@ -8,11 +8,11 @@ export class GimmeCommand implements ISlashCommand {
public paramsExample: string = 'your_message_optional';
public i18nDescription: string = 'Slash_Gimme_Description';
public executor(context: SlashCommandContext, read: IRead, modify: IModify, http: IHttp): void {
public async executor(context: SlashCommandContext, read: IRead, modify: IModify, http: IHttp): Promise<void> {
const builder = modify.getCreator().startMessage()
.setSender(context.getSender()).setRoom(context.getRoom())
.setText('༼ つ ◕_◕ ༽つ ' + context.getArguments().join(' '));
modify.getCreator().finish(builder);
await modify.getCreator().finish(builder);
}
}
......@@ -8,8 +8,8 @@ export class LennyCommand implements ISlashCommand {
public paramsExample: string = 'your_message_optional';
public i18nDescription: string = 'Slash_LennyFace_Description';
public executor(context: SlashCommandContext, read: IRead, modify: IModify, http: IHttp): void {
modify.getCreator().finish(modify.getCreator().startMessage({
public async executor(context: SlashCommandContext, read: IRead, modify: IModify, http: IHttp): Promise<void> {
await modify.getCreator().finish(modify.getCreator().startMessage({
id: 'this-will-be-removed(whoops)',
room: context.getRoom(),
sender: context.getSender(),
......
......@@ -8,13 +8,13 @@ export class ShrugCommand implements ISlashCommand {
public paramsExample: string = 'your_message_optional';
public i18nDescription: string = 'Slash_Shrug_Description';
public executor(context: SlashCommandContext, read: IRead, modify: IModify, http: IHttp): void {
public async executor(context: SlashCommandContext, read: IRead, modify: IModify, http: IHttp): Promise<void> {
const msgBuilder = modify.getCreator().startMessage()
.setSender(context.getSender()).setRoom(context.getRoom())
.setText(context.getArguments().join(' ') +
(context.getArguments().length === 0 ? '' : ' ') +
'¯\\_(ツ)_/¯');
modify.getCreator().finish(msgBuilder);
await modify.getCreator().finish(msgBuilder);
}
}
......@@ -8,13 +8,13 @@ export class TableflipCommand implements ISlashCommand {
public paramsExample: string = 'your_message_optional';
public i18nDescription: string = 'Slash_Tableflip_Description';
public executor(context: SlashCommandContext, read: IRead, modify: IModify, http: IHttp): void {
public async executor(context: SlashCommandContext, read: IRead, modify: IModify, http: IHttp): Promise<void> {
const msgBuilder = modify.getCreator().startMessage()
.setSender(context.getSender()).setRoom(context.getRoom())
.setText(context.getArguments().join(' ') +
(context.getArguments().length === 0 ? '' : ' ') +
'(╯°□°)╯︵ ┻━┻');
modify.getCreator().finish(msgBuilder);
await modify.getCreator().finish(msgBuilder);
}
}
......@@ -8,13 +8,13 @@ export class UnflipCommand implements ISlashCommand {
public paramsExample: string = 'your_message_optional';
public i18nDescription: string = 'Slash_TableUnflip_Description';
public executor(context: SlashCommandContext, read: IRead, modify: IModify, http: IHttp): void {
public async executor(context: SlashCommandContext, read: IRead, modify: IModify, http: IHttp): Promise<void> {
const msgBuilder = modify.getCreator().startMessage()
.setSender(context.getSender()).setRoom(context.getRoom())
.setText(context.getArguments().join(' ') +
(context.getArguments().length === 0 ? '' : ' ') +
'┬─┬ ノ( ゜-゜ノ)');
modify.getCreator().finish(msgBuilder);
await modify.getCreator().finish(msgBuilder);
}
}
import { IHttp, ILogger, IPersistence, IPersistenceRead, IRead } from '@rocket.chat/apps-ts-definition/accessors';
import { IHttp, ILogger, IMessageBuilder, IPersistence, IRead } from '@rocket.chat/apps-ts-definition/accessors';
import { App } from '@rocket.chat/apps-ts-definition/App';
import { IMessage, IPreMessageSentModify } from '@rocket.chat/apps-ts-definition/messages';
import { IAppInfo } from '@rocket.chat/apps-ts-definition/metadata/IAppInfo';
......@@ -11,17 +11,32 @@ export class GithubApp extends App implements IPreMessageSentModify {
}
// tslint:disable-next-line:max-line-length
public checkPreMessageSentModify(message: IMessage, read: IRead, http: IHttp, persistence: IPersistenceRead): boolean {
return message.text.match(this.matcher).length !== 0;
public async checkPreMessageSentModify(message: IMessage, read: IRead, http: IHttp): Promise<boolean> {
if (typeof message.text !== 'string') {
return false;
}
const result = message.text.match(this.matcher);
return result ? result.length !== 0 : false;
}
// tslint:disable-next-line:max-line-length
public executePreMessageSentModify(message: IMessage, read: IRead, http: IHttp, persistence: IPersistence): IMessage {
public async executePreMessageSentModify(message: IMessage, builder: IMessageBuilder, read: IRead, http: IHttp, persistence: IPersistence): Promise<IMessage> {
if (typeof message.text !== 'string') {
return message;
}
const githubLinks = message.text.match(this.matcher);
if (githubLinks.length > 0) {
if (githubLinks && githubLinks.length > 0) {
for (const link of githubLinks) {
const parts = this.matcher.exec(link);
if (!parts || parts.length < 4) {
continue;
}
const newLink = `[${link}](https://github.com/${parts[1]}/${parts[2]}/issues/${parts[3]})`;
message.text = message.text.replace(link, newLink);
......
{
"id": "5cb9a328-0613-4d39-b20f-cc2cc9175df5",
"name": "GitHub App"
"name": "GitHub App",
"nameSlug": "github-linker-app",
"description": "Turns GitHub references into links.",
"version": "1.0.0",
"requiredApiVersion": ">=0.9.6",
"author": {
"name": "Bradley Hilton",
"homepage": "https://github.com/RocketChat/Rocket.Chat.Apps-dev-environment",
"support": "https://github.com/RocketChat/Rocket.Chat.Apps-dev-environment/issues"
},
"classFile": "Github.ts",
"iconFile": "GitHub-Mark.png"
}
......@@ -24,24 +24,25 @@ export class GuggyApp extends App {
this.guggyGetter = new GuggyGetter();
}
public onEnable(environmentRead: IEnvironmentRead, configModify: IConfigurationModify): boolean {
if (!environmentRead.getSettings().getValueById(this.apiKeySettingid)) {
configModify.slashCommands.disableSlashCommand('guggy');
public async onEnable(environmentRead: IEnvironmentRead, configModify: IConfigurationModify): Promise<boolean> {
const setting = await environmentRead.getSettings().getValueById(this.apiKeySettingid);
if (!setting) {
await configModify.slashCommands.disableSlashCommand('guggy');
}
return true;
}
// tslint:disable-next-line:max-line-length
public onSettingUpdated(setting: ISetting, configModify: IConfigurationModify, read: IRead, http: IHttp): void {
public async onSettingUpdated(setting: ISetting, configModify: IConfigurationModify, read: IRead, http: IHttp): Promise<void> {
switch (setting.id) {
case this.apiKeySettingid:
this.handleApiKeySettingHandle(setting, configModify, http);
await this.handleApiKeySettingHandle(setting, configModify, http);
break;
}
}
protected extendConfiguration(configuration: IConfigurationExtend, environmentRead: IEnvironmentRead): void {
protected async extendConfiguration(configuration: IConfigurationExtend, environmentRead: IEnvironmentRead): Promise<void> {
configuration.settings.provideSetting({
id: this.apiKeySettingid,
type: SettingType.STRING,
......@@ -58,21 +59,21 @@ export class GuggyApp extends App {
configuration.slashCommands.provideSlashCommand(new GuggyCommand(this.guggyGetter));
}
private handleApiKeySettingHandle(setting: ISetting, configModify: IConfigurationModify, http: IHttp): void {
private async handleApiKeySettingHandle(setting: ISetting, configModify: IConfigurationModify, http: IHttp): Promise<void> {
if (setting.value) {
try {
this.guggyGetter.getTheGif(http, 'testing');
this.getLogger().log('Enabling the slash command.');
configModify.slashCommands.enableSlashCommand('guggy');
await configModify.slashCommands.enableSlashCommand('guggy');
} catch (e) {
// Not valid api key
// The api key is not valid
this.getLogger().log('Disabling the slash command because the api key isnt valid.');
configModify.slashCommands.disableSlashCommand('guggy');
await configModify.slashCommands.disableSlashCommand('guggy');
}
} else {
// There is no value, so remove the command
this.getLogger().log('Disabling the slash command because there is no setting value defined.');
configModify.slashCommands.disableSlashCommand('guggy');
await configModify.slashCommands.disableSlashCommand('guggy');
}
}
}
......@@ -3,8 +3,8 @@
"name": "Guggy Command",
"nameSlug": "guggy-command",
"description": "Provides a command for generating gifs based upon text provided.",
"version": "1.0.8",
"requiredApiVersion": ">=0.6.29",
"version": "1.0.9",
"requiredApiVersion": ">=0.9.6",
"author": {
"name": "Bradley Hilton",
"homepage": "https://github.com/graywolf336/temporary-apps-dev-environment",
......
......@@ -9,16 +9,16 @@ export class GuggyCommand implements ISlashCommand {
constructor(private readonly getter: GuggyGetter) { }
public executor(context: SlashCommandContext, read: IRead, modify: IModify, http: IHttp): void {
public async executor(context: SlashCommandContext, read: IRead, modify: IModify, http: IHttp): Promise<void> {
const builder = modify.getCreator().startMessage().setSender(context.getSender()).setRoom(context.getRoom());
try {
const gifUrl = this.getter.getTheGif(http, context.getArguments().join(' '));
const gifUrl = await this.getter.getTheGif(http, context.getArguments().join(' '));
builder.addAttachment({ imageUrl: gifUrl });
} catch (e) {
builder.setText('Sorry I don\'t have a photo for you :disappointed_relieved:');
}
modify.getCreator().finish(builder);
await modify.getCreator().finish(builder);
}
}
......@@ -3,8 +3,8 @@ import { HttpStatusCode, IHttp } from '@rocket.chat/apps-ts-definition/accessors
export class GuggyGetter {
private readonly url: string = 'http://text2gif.guggy.com/guggify';
public getTheGif(http: IHttp, sentence: string): string {
const result = http.post(this.url, {
public async getTheGif(http: IHttp, sentence: string): Promise<string> {
const result = await http.post(this.url, {
data: {
format: 'gif',
sentence,
......
......@@ -13,8 +13,8 @@ export class SettingToHttpHeader implements IHttpPreRequestHandler {
}
// tslint:disable-next-line:max-line-length
public executePreHttpRequest(url: string, request: IHttpRequest, read: IRead, persistence: IPersistence): IHttpRequest {
const apiKey = read.getEnvironmentReader().getSettings().getValueById(this.apiKeyId);
public async executePreHttpRequest(url: string, request: IHttpRequest, read: IRead, persistence: IPersistence): Promise<IHttpRequest> {
const apiKey = await read.getEnvironmentReader().getSettings().getValueById(this.apiKeyId);
if (typeof apiKey !== 'string' || apiKey.length === 0) {
throw new Error('Invalid Guggy Api Key!');
......
......@@ -15,7 +15,7 @@ import { IOutOfOfficeStorage } from './IOutOfOfficeStorage';
import { OutOfOfficeCommand} from './OutOfOfficeCommand';
export class OutOfOfficeApp extends App implements IPostMessageSent {
public checkPostMessageSent(message: IMessage, read: IRead, http: IHttp): boolean {
public async checkPostMessageSent(message: IMessage, read: IRead, http: IHttp): Promise<boolean> {
// We don't auto-respond to rooms beside direct messages
// maybe in the future if the user is tagged by someone
// then they will be direct messaged but right now it is
......@@ -24,18 +24,18 @@ export class OutOfOfficeApp extends App implements IPostMessageSent {
return message.room.type === RoomType.DIRECT_MESSAGE;
}
public executePostMessageSent(message: IMessage, read: IRead,
http: IHttp, persistence: IPersistence): void {
public async executePostMessageSent(message: IMessage, read: IRead,
http: IHttp, persistence: IPersistence): Promise<void> {
const otherUsers = message.room.usernames.filter((u) => u !== message.sender.username);
if (otherUsers.length !== 1) {
// We don't care if there isn't one other person in the room
return;
}
const otherUser = read.getUserReader().getByUsername(otherUsers[0]);
const otherUser = await read.getUserReader().getByUsername(otherUsers[0]);
const assoc = new RocketChatAssociationRecord(RocketChatAssociationModel.USER, otherUser.id);
const awayDatas = read.getPersistenceReader().readByAssociation(assoc);
const awayDatas = await read.getPersistenceReader().readByAssociation(assoc);
if (awayDatas.length === 0) {
// The user is not marked as away
return;
......@@ -48,13 +48,13 @@ export class OutOfOfficeApp extends App implements IPostMessageSent {
.setUsernameAlias('Out of Office').setEmojiAvatar(':calendar:')
.setRoom(message.room).setSender(message.sender).getMessage();
read.getNotifier().notifyUser(message.sender, msg);
await read.getNotifier().notifyUser(message.sender, msg);
this.getLogger().log(otherUser.username +
' is currently *out of office*, however they left the following message:\n\n>"' + data.message + '"');
}
protected extendConfiguration(configuration: IConfigurationExtend, environmentRead: IEnvironmentRead): void {
configuration.slashCommands.provideSlashCommand(new OutOfOfficeCommand());
protected async extendConfiguration(configuration: IConfigurationExtend, environmentRead: IEnvironmentRead): Promise<void> {
await configuration.slashCommands.provideSlashCommand(new OutOfOfficeCommand());
}
}
......@@ -11,24 +11,24 @@ export class OutOfOfficeCommand implements ISlashCommand {
public i18nDescription = 'outOfOfficeDescription';
// tslint:disable-next-line:max-line-length
public executor(context: SlashCommandContext, read: IRead, modify: IModify, http: IHttp, persis: IPersistence): void {
public async executor(context: SlashCommandContext, read: IRead, modify: IModify, http: IHttp, persis: IPersistence): Promise<void> {
switch (context.getArguments().length) {
case 0:
return this.invalidUsageHandler(context, modify);
return await this.invalidUsageHandler(context, modify);
case 1:
return this.handleStatusArgOnly(context, read, modify, persis);
return await this.handleStatusArgOnly(context, read, modify, persis);
default:
return this.handleWithCustomMessage(context, read, modify, persis);
return await this.handleWithCustomMessage(context, read, modify, persis);
}
}
private invalidUsageHandler(context: SlashCommandContext, modify: IModify): void {
this.sendNotifyMessage(context, modify, 'Invalid usage of the Out of Office command. ' +
private async invalidUsageHandler(context: SlashCommandContext, modify: IModify): Promise<void> {
await this.sendNotifyMessage(context, modify, 'Invalid usage of the Out of Office command. ' +
'Please provide whether you are `out` or `in`, with the message optional if you are away.');
}
// tslint:disable-next-line:max-line-length
private handleStatusArgOnly(context: SlashCommandContext, read: IRead, modify: IModify, persis: IPersistence): void {
private async handleStatusArgOnly(context: SlashCommandContext, read: IRead, modify: IModify, persis: IPersistence): Promise<void> {
const assoc = new RocketChatAssociationRecord(RocketChatAssociationModel.USER, context.getSender().id);
const data: IOutOfOfficeStorage = {
out: true,
......@@ -38,34 +38,35 @@ export class OutOfOfficeCommand implements ISlashCommand {
switch (context.getArguments()[0].toLowerCase()) {
case 'in':
persis.removeByAssociation(assoc);
await persis.removeByAssociation(assoc);
// TODO: Maybe say something different if they weren't away to come back lol
return this.sendNotifyMessage(context, modify, `Welcome back, ${ context.getSender().username }!`);
return await this.sendNotifyMessage(context, modify, `Welcome back, ${ context.getSender().username }!`);
case 'out':
persis.createWithAssociation(data, assoc);
return this.sendNotifyMessage(context, modify,
await persis.createWithAssociation(data, assoc);
return await this.sendNotifyMessage(context, modify,
'You are marked as *Out of Office*, we will see you when you get back.');
case 'status':
if (read.getPersistenceReader().readByAssociation(assoc).length > 0) {
return this.sendNotifyMessage(context, modify, 'You are currently *out of office*.');
const existing = await read.getPersistenceReader().readByAssociation(assoc);
if (existing.length > 0) {
return await this.sendNotifyMessage(context, modify, 'You are currently *out of office*.');
} else {
return this.sendNotifyMessage(context, modify, 'You are currently *in office*.');
return await this.sendNotifyMessage(context, modify, 'You are currently *in office*.');
}
default:
return this.sendNotifyMessage(context, modify,
return await this.sendNotifyMessage(context, modify,
'No idea what you are talking about. ' +
'Only `out`, `in` and `status` are accepted options for the first argument.');
}
}
// tslint:disable-next-line:max-line-length
private handleWithCustomMessage(context: SlashCommandContext, read: IRead, modify: IModify, persis: IPersistence): void {
private async handleWithCustomMessage(context: SlashCommandContext, read: IRead, modify: IModify, persis: IPersistence): Promise<void> {
const action = context.getArguments()[0].toLowerCase();
if (action === 'in' || action === 'status') {
return this.handleStatusArgOnly(context, read, modify, persis);
return await this.handleStatusArgOnly(context, read, modify, persis);
} else if (action !== 'out') {
return this.sendNotifyMessage(context, modify,
return await this.sendNotifyMessage(context, modify,
'No idea what you are talking about. ' +
'Only `out`, `in` and `status` are accepted options for the first argument.');
}
......@@ -79,22 +80,24 @@ export class OutOfOfficeCommand implements ISlashCommand {
};
// Allow setting their status again if they're currently marked as away
if (read.getPersistenceReader().readByAssociation(assoc).length > 0) {
persis.removeByAssociation(assoc);
const existing = await read.getPersistenceReader().readByAssociation(assoc);
if (existing.length > 0) {
await persis.removeByAssociation(assoc);
}
persis.createWithAssociation(data, assoc);
return this.sendNotifyMessage(context, modify,
await persis.createWithAssociation(data, assoc);
return await this.sendNotifyMessage(context, modify,
'You are marked as *Out of Office*, we will see you when you get back. ' +
'The message being sent to others when they contact you is: "' +
data.message + '"');
}
private sendNotifyMessage(context: SlashCommandContext, modify: IModify, text: string): void {
private async sendNotifyMessage(context: SlashCommandContext, modify: IModify, text: string): Promise<void> {
const msg = modify.getCreator().startMessage().setText(text)
.setUsernameAlias('Out of Office').setEmojiAvatar(':calendar:')