src/commands_discord/social/remind-command.js
/**
   * Executes the command instance. The main function of a command, it's essence.
   * All arguments scanning, validation and permissions check is considered done before entering this function.
   * So if any exception happens inside the function, it's considered a Bot's internal problem.
   * @param  {BaseMessage}         message the Discord message as the source of the command
   * @return {Promise<string>}             the result text to be replied as the response of the execution
   */
Executes the command instance. The main function of a command, it's essence.
All arguments scanning, validation and permissions check is considered done before entering this function.
So if any exception happens inside the function, it's considered a Bot's internal problem.
@param  {BaseMessage}         message the Discord message as the source of the command
@return {Promise}             the result text to be replied as the response of the execution
Executes the command instance . The main function of a command it ' s essence . All arguments scanning validation and permissions check is considered done before entering this function . So if any exception happens inside the function it ' s considered a Bot ' s internal problem . @param { BaseMessage } message the Discord message as the source of the command @return { Promise } the result text to be replied as the response of the execution
async executeForDiscord(message) {
    let result = '';
    let taskAdded = false;
    const tasks = await this.context.dbManager.getDiscordRows(this.context.dbManager.tasksTable, this.orgId, {
      type: OrgTask.TASK_TYPES.reminder
    });
    if (tasks.length + this.channelIds.channels.length > this.context.prefsManager.max_reminders_per_discord_org) {
      return this.langManager.getString(
        'command_remind_too_many_reminders',
        this.context.prefsManager.max_reminders_per_discord_org
      );
    }
    const currentRows = await this.context.dbManager.getDiscordRows(this.context.dbManager.tasksTable, this.orgId);
    const maxIndex = OhUtils.findMaxId(currentRows);
    let newId = maxIndex + 1;
    const insertTaskResults = [];
    for (let i = 0; i < this.channelIds.channels.length; i++) {
      const content = { channel: this.channelIds.channels[i], message: this.message };
      const reminderRow = {
        id: newId++,
        source: this.source,
        orgId: this.orgId,
        type: OrgTask.TASK_TYPES.reminder,
        time: OrgTask.parseTimeArg(this.time),
        content
      };
      insertTaskResults.push(
        this.context.dbManager.insertOne(this.context.dbManager.tasksTable, reminderRow).then(rowResult => {
          if (rowResult) {
            result = result + this.langManager.getString('command_remind_success') + '\n';
            taskAdded = true;
          } else {
            result = result + this.langManager.getString('command_remind_duplicate') + '\n';
          }
        })
      );
    }
    await Promise.all(insertTaskResults);
    if (taskAdded) {
      await this.context.scheduler.syncTasks();
    }
    return result;
  }
async executeForDiscord ( message ) { let result = '' ; let taskAdded = false ; const tasks = await this . context . dbManager . getDiscordRows ( this . context . dbManager . tasksTable , this . orgId , { type : OrgTask . TASK_TYPES . reminder } ) ; if ( tasks . length + this . channelIds . channels . length > this . context . prefsManager . max_reminders_per_discord_org ) { return this . langManager . getString ( 'command_remind_too_many_reminders' , this . context . prefsManager . max_reminders_per_discord_org ) ; } const currentRows = await this . context . dbManager . getDiscordRows ( this . context . dbManager . tasksTable , this . orgId ) ; const maxIndex = OhUtils . findMaxId ( currentRows ) ; let newId = maxIndex + 1 ; const insertTaskResults = [ ] ; for ( let i = 0 ; i < this . channelIds . channels . length ; i ++ ) { const content = { channel : this . channelIds . channels [ i ] , message : this . message } ; const reminderRow = { id : newId ++ , source : this . source , orgId : this . orgId , type : OrgTask . TASK_TYPES . reminder , time : OrgTask . parseTimeArg ( this . time ) , content } ; insertTaskResults . push ( this . context . dbManager . insertOne ( this . context . dbManager . tasksTable , reminderRow ) . then ( rowResult => { if ( rowResult ) { result = result + this . langManager . getString ( 'command_remind_success' ) + '\n' ; taskAdded = true ; } else { result = result + this . langManager . getString ( 'command_remind_duplicate' ) + '\n' ; } } ) ) ; } await Promise . all ( insertTaskResults ) ; if ( taskAdded ) { await this . context . scheduler . syncTasks ( ) ; } return result ; }
Executes the command instance.
Executes the command instance .
// Inherited function with various possible implementations, some args may be unused. /* eslint no-unused-vars: ["error", { "args": "none" }] */