mongodb#Long TypeScript Examples

The following examples show how to use mongodb#Long. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: util.ts    From discord with GNU General Public License v3.0 7 votes vote down vote up
public static belongsToShard(id: Long, shard?: number) {
    if (Core.options.shardCount === 1) return true
    const mod = id
      .shiftRight(22)
      .modulo(Long.fromNumber(Core.options.shardCount))

    if (shard === undefined) {
      for (const shard of Core.options.shards as number[]) {
        if (mod.equals(Long.fromNumber(shard)))
          return true
      }
      return false
    }

    return mod.equals(Long.fromNumber(shard))
  }
Example #2
Source File: delete_confirm.ts    From discord with GNU General Public License v3.0 6 votes vote down vote up
export default async function (i: ReplyableComponentInteraction) {
  if (i.member && !PermissionStrings.containsManageServer(i.member.permissions))
    return i.ack()

  if (onGuildDataDeleteCooldown.includes(i.guild_id))
    return i.ack()

  onGuildDataDeleteCooldown.push(i.guild_id)
  setTimeout(() => onGuildDataDeleteCooldown.splice(0, 1), 1000 * 60 * 60 * 12)

  await DatabaseManager.removeGuild(Long.fromString(i.guild_id))
  const guild = await Core.guilds.fetch(i.guild_id)
  await DatabaseManager.addGuild(guild.id)

  i.edit({
    title: '=settings_guilddata_delete_success_1',
    description: '=settings_guilddata_delete_success_2',
    components: []
  })
}
Example #3
Source File: message-distributor.ts    From discord with GNU General Public License v3.0 6 votes vote down vote up
/**
   * Run a test announcement on guild with content
   * @param guild guild to run the test on
   * @param content content of the test message
   */
  public static test(guildId: string, content: GameInfo): void {
    Database
      .collection('guilds')
      .findOne({ _id: Long.fromString(guildId) })
      .then((g: DatabaseGuildData) => {
        if (!g) return
        MessageDistributor.sendToGuild(g, [ content ], true, true)
      })
      .catch(Logger.error)
  }
Example #4
Source File: print.ts    From discord with GNU General Public License v3.0 6 votes vote down vote up
export default async function (i: GenericInteraction): Promise<InteractionApplicationCommandCallbackData> {
  try {
    const data = await Database
      .collection('guilds')
      .findOne({ _id: Long.fromString(i.guild_id) })

    data._ = {
      shard: ((typeof i.guildData.sharder === 'number') ? i.guildData.sharder : i.guildData.sharder.getLowBits()) % Core.options.shardCount,
      worker: Manager.getSelfUUID(),
      container: await hostname()
    }

    const description = '```json\n' + JSON.stringify(data, null, 2) + '```'

    return {
      title: 'Guild Data Print',
      description,
      components: [
        {
          type: ComponentType.BUTTON,
          style: ButtonStyle.SECONDARY,
          custom_id: 'admin_main',
          label: '=generic_back',
          emoji: { id: Emojis.caretLeft.id }
        }
      ]
    }
  } catch (ex) {
    return {
      title: 'Error',
      description: '```' + ex + '```'
    }
  }
}
Example #5
Source File: manager.ts    From discord with GNU General Public License v3.0 6 votes vote down vote up
private static async runCommand(cmd: WorkerCommand) {
    switch (cmd.id) {
      case 'shutdown':
        Logger.manager('Shutdown.')
        process.exit(0)

      case 'reload_lang':
        Logger.manager('Reload language cache.')
        reloadLanguages()
        break

      case 'resend_to_guild':
        Logger.manager('Resend received')
        for (const guildid of cmd.guilds) {
          if (!Util.belongsToShard(Long.fromString(guildid))) continue
          const guildData = await DatabaseManager.getGuildData(guildid)
          const freebies = AnnouncementManager.getCurrentFreebies()
          MessageDistributor.sendToGuild(guildData, freebies, false, false)
          Logger.manager(`Resent to ${guildid}`)
        }
        break

      default:
        Logger.manager(`Unhandled command received: ${JSON.stringify(cmd)}`)
        break
    }
  }